From: Fomafix Date: Tue, 12 Mar 2019 08:53:49 +0000 (+0100) Subject: Language: Use Assert::parameterType for type checks X-Git-Tag: 1.34.0-rc.0~2532^2~1 X-Git-Url: http://git.cyclocoop.org/%7B%7B%20url_for%28%27admin_vote_add%27%29%20%7D%7D?a=commitdiff_plain;h=79f721948b6fffac4ec4af5f6fed567ecb6dfca0;p=lhc%2Fweb%2Fwiklou.git Language: Use Assert::parameterType for type checks Depends-On: Ib0cb388958cf720052ca6df73d5145b7ab3f9529 Change-Id: I8287118cf8ec01326ead9c90a38f7b4134c3eba9 --- 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; }