X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=languages%2FLanguage.php;h=aaaf2a206cd54a8d9dbe2a6c7c9a5cae2506d098;hb=197a82eda02768a4c69f97efde258bd7f1f13227;hp=5d5f980030b7fb7e0d87f6f8c80fcc1de51bcc0c;hpb=a71210724cc300180e3d9f427608296d25977f92;p=lhc%2Fweb%2Fwiklou.git diff --git a/languages/Language.php b/languages/Language.php index 5d5f980030..aaaf2a206c 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -27,6 +27,7 @@ */ use CLDRPluralRuleParser\Evaluator; +use Wikimedia\Assert\Assert; /** * Internationalisation code @@ -385,6 +386,7 @@ class Language { */ public static function isValidCode( $code ) { static $cache = []; + Assert::parameterType( 'string', $code, '$code' ); if ( !isset( $cache[$code] ) ) { // People think language codes are html safe, so enforce it. // Ideally we should only allow a-zA-Z0-9- @@ -404,20 +406,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 +2840,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; }