diff options
author | Bartosz Dziewoński <dziewonski@fastmail.fm> | 2024-08-21 06:37:57 +0200 |
---|---|---|
committer | Bartosz Dziewoński <dziewonski@fastmail.fm> | 2024-08-21 06:53:04 +0200 |
commit | 4948fbe4f947651470c03af37bf29850e289669c (patch) | |
tree | 842ff12ecb3ee063a44394f8e005ec05528859f7 /includes/Message | |
parent | 01f56187576b159204378f685b4a28fa86b3e618 (diff) | |
download | mediawikicore-4948fbe4f947651470c03af37bf29850e289669c.tar.gz mediawikicore-4948fbe4f947651470c03af37bf29850e289669c.zip |
Message: Validate ScalarParam and ListParam types
* Add getters for the lists of valid types
(named cases() like in PHP 8.1 enums)
* Validate that the provided type is in the list
* Replace funky use of reflection in Converter
Change-Id: I8da89edbb943fae8920c15b1bc6856ce97a4de7a
Diffstat (limited to 'includes/Message')
-rw-r--r-- | includes/Message/Converter.php | 19 |
1 files changed, 1 insertions, 18 deletions
diff --git a/includes/Message/Converter.php b/includes/Message/Converter.php index 87f17b9ab340..7b9e07e05f05 100644 --- a/includes/Message/Converter.php +++ b/includes/Message/Converter.php @@ -3,7 +3,6 @@ namespace MediaWiki\Message; use InvalidArgumentException; -use ReflectionClass; use Wikimedia\Message\ListParam; use Wikimedia\Message\MessageParam; use Wikimedia\Message\MessageSpecifier; @@ -17,22 +16,6 @@ use Wikimedia\Message\ScalarParam; */ class Converter { - /** @var string[]|null ParamType constants */ - private static $constants = null; - - /** - * Return the ParamType constants - * @return string[] - */ - private static function getTypes() { - if ( self::$constants === null ) { - $rc = new ReflectionClass( ParamType::class ); - self::$constants = array_values( $rc->getConstants() ); - } - - return self::$constants; - } - /** * Allow the Message class to be mocked in tests by constructing objects in * a protected method. @@ -79,7 +62,7 @@ class Converter { return new ListParam( $param['type'], $convertedElements ); } - foreach ( self::getTypes() as $type ) { + foreach ( ParamType::cases() as $type ) { if ( $type !== ParamType::LIST && isset( $param[$type] ) ) { return new ScalarParam( $type, $param[$type] ); } |