diff options
Diffstat (limited to 'includes/title/TitleValue.php')
-rw-r--r-- | includes/title/TitleValue.php | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/includes/title/TitleValue.php b/includes/title/TitleValue.php index 5cac3470..a0f3b6f9 100644 --- a/includes/title/TitleValue.php +++ b/includes/title/TitleValue.php @@ -21,6 +21,7 @@ * @license GPL 2+ * @author Daniel Kinzler */ +use Wikimedia\Assert\Assert; /** * Represents a page (or page fragment) title within %MediaWiki. @@ -67,26 +68,13 @@ class TitleValue { * @throws InvalidArgumentException */ public function __construct( $namespace, $dbkey, $fragment = '' ) { - if ( !is_int( $namespace ) ) { - throw new InvalidArgumentException( '$namespace must be an integer' ); - } - - if ( !is_string( $dbkey ) ) { - throw new InvalidArgumentException( '$dbkey must be a string' ); - } + Assert::parameterType( 'integer', $namespace, '$namespace' ); + Assert::parameterType( 'string', $dbkey, '$dbkey' ); + Assert::parameterType( 'string', $fragment, '$fragment' ); // Sanity check, no full validation or normalization applied here! - if ( preg_match( '/^_|[ \r\n\t]|_$/', $dbkey ) ) { - throw new InvalidArgumentException( '$dbkey must be a valid DB key: ' . $dbkey ); - } - - if ( !is_string( $fragment ) ) { - throw new InvalidArgumentException( '$fragment must be a string' ); - } - - if ( $dbkey === '' ) { - throw new InvalidArgumentException( '$dbkey must not be empty' ); - } + Assert::parameter( !preg_match( '/^_|[ \r\n\t]|_$/', $dbkey ), '$dbkey', 'invalid DB key' ); + Assert::parameter( $dbkey !== '', '$dbkey', 'should not be empty' ); $this->namespace = $namespace; $this->dbkey = $dbkey; |