aboutsummaryrefslogtreecommitdiffstats
path: root/includes/Html/FormOptions.php
diff options
context:
space:
mode:
authorDaimona Eaytoy <daimona.wiki@gmail.com>2023-06-10 15:05:22 +0200
committerDannyS712 <dannys712.wiki@gmail.com>2024-01-19 23:11:59 +0000
commit175c0c4abf5bd7d94fad2a810df0f308f0564be8 (patch)
tree3bafb9ea451524160c1fe4f60697d0678f799fbb /includes/Html/FormOptions.php
parent2520f3d1c4054f4e2e19fd8a0ccd3792cc9772c9 (diff)
downloadmediawikicore-175c0c4abf5bd7d94fad2a810df0f308f0564be8.tar.gz
mediawikicore-175c0c4abf5bd7d94fad2a810df0f308f0564be8.zip
Replace more instances of deprecated MWException
Bug: T328220 Change-Id: Iba90f7f9b5766bccc05380d040138d74d5e9558a
Diffstat (limited to 'includes/Html/FormOptions.php')
-rw-r--r--includes/Html/FormOptions.php19
1 files changed, 7 insertions, 12 deletions
diff --git a/includes/Html/FormOptions.php b/includes/Html/FormOptions.php
index d621a33b2f97..1a6486ad418d 100644
--- a/includes/Html/FormOptions.php
+++ b/includes/Html/FormOptions.php
@@ -31,7 +31,7 @@ namespace MediaWiki\Html;
use ArrayAccess;
use InvalidArgumentException;
use MediaWiki\Request\WebRequest;
-use MWException;
+use UnexpectedValueException;
/**
* Helper class to keep track of options when mixing links and form elements.
@@ -144,13 +144,12 @@ class FormOptions implements ArrayAccess {
*
* @param string $name Option name
* @param bool $strict Throw an exception when the option doesn't exist instead of returning false
- * @throws MWException When $strict is true, failure results in an exception.
* @return bool True if the option exists, false otherwise
*/
public function validateName( $name, $strict = false ) {
if ( !isset( $this->options[$name] ) ) {
if ( $strict ) {
- throw new MWException( "Invalid option $name" );
+ throw new InvalidArgumentException( "Invalid option $name" );
} else {
return false;
}
@@ -218,10 +217,9 @@ class FormOptions implements ArrayAccess {
/**
* Get the value of given option and mark it as 'consumed'. Consumed options are not returned
- * by getUnconsumedValues().
+ * by getUnconsumedValues(). Callers should verify that the given option exists.
*
* @see consumeValues()
- * @throws MWException If the option does not exist
* @param string $name Option name
* @return mixed Value, or the default value if it is null
*/
@@ -234,10 +232,9 @@ class FormOptions implements ArrayAccess {
/**
* Get the values of given options and mark them as 'consumed'. Consumed options are not returned
- * by getUnconsumedValues().
+ * by getUnconsumedValues(). Callers should verify that all the given options exist.
*
* @see consumeValue()
- * @throws MWException If any option does not exist
* @param string[] $names List of option names
* @return array Array of option values, or the default values if they are null
*/
@@ -269,17 +266,16 @@ class FormOptions implements ArrayAccess {
*
* @since 1.23
*
- * @param string $name Option name
+ * @param string $name Option name. Must be of numeric type.
* @param int|float $min Minimum value
* @param int|float $max Maximum value
- * @throws MWException If the option's type is not numeric
*/
public function validateBounds( $name, $min, $max ) {
$this->validateName( $name, true );
$type = $this->options[$name]['type'];
if ( $type !== self::INT && $type !== self::INTNULL && $type !== self::FLOAT ) {
- throw new MWException( "Type of option $name is not numeric" );
+ throw new InvalidArgumentException( "Type of option $name is not numeric" );
}
$value = $this->getValueReal( $this->options[$name] );
@@ -348,7 +344,6 @@ class FormOptions implements ArrayAccess {
* @param array|null $optionKeys Which options to fetch the values for (default:
* all of them). Note that passing an empty array will also result in
* values for all keys being fetched.
- * @throws MWException If the type of any option is invalid
*/
public function fetchValuesFromRequest( WebRequest $r, $optionKeys = null ) {
if ( !$optionKeys ) {
@@ -384,7 +379,7 @@ class FormOptions implements ArrayAccess {
}
break;
default:
- throw new MWException( 'Unsupported datatype' );
+ throw new UnexpectedValueException( "Unsupported datatype $type" );
}
if ( $value !== null ) {