From 79f721948b6fffac4ec4af5f6fed567ecb6dfca0 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Tue, 12 Mar 2019 09:53:49 +0100 Subject: [PATCH] Language: Use Assert::parameterType for type checks Depends-On: Ib0cb388958cf720052ca6df73d5145b7ab3f9529 Change-Id: I8287118cf8ec01326ead9c90a38f7b4134c3eba9 --- languages/Language.php | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/languages/Language.php b/languages/Language.php index 5d5f980030..5ac2882716 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -27,6 +27,7 @@ */ use CLDRPluralRuleParser\Evaluator; +use Wikimedia\Assert\Assert; /** * Internationalisation code @@ -404,20 +405,11 @@ class Language { * * @param string $code * - * @throws MWException * @since 1.18 * @return bool */ public static function isValidBuiltInCode( $code ) { - if ( !is_string( $code ) ) { - if ( is_object( $code ) ) { - $addmsg = " of class " . get_class( $code ); - } else { - $addmsg = ''; - } - $type = gettype( $code ); - throw new MWException( __METHOD__ . " must be passed a string, $type given$addmsg" ); - } + Assert::parameterType( 'string', $code, '$code' ); return (bool)preg_match( '/^[a-z0-9-]{2,}$/', $code ); } @@ -2847,12 +2839,9 @@ class Language { /** * @param string $s * @return string - * @throws MWException */ function checkTitleEncoding( $s ) { - if ( is_array( $s ) ) { - throw new MWException( 'Given array to checkTitleEncoding.' ); - } + Assert::parameterType( 'string', $s, '$s' ); if ( StringUtils::isUtf8( $s ) ) { return $s; } -- 2.20.1