*/
use CLDRPluralRuleParser\Evaluator;
+use Wikimedia\Assert\Assert;
/**
* Internationalisation code
*/
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-
*
* @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 );
}
}
/**
+ * TODO: $s is not always a string per T218883
* @param string $s
* @return string
- * @throws MWException
*/
function checkTitleEncoding( $s ) {
if ( is_array( $s ) ) {
$length -= $ellipsisLength;
$string = $getSubstring( $string, 0, $length ); // xyz...
$string = $this->removeBadCharLast( $string );
- $string = rtrim( $string );
- $string = $string . $ellipsis;
+ $string = rtrim( $string ) . $ellipsis;
} else {
$length += $ellipsisLength;
$string = $getSubstring( $string, $length ); // ...xyz
$string = $this->removeBadCharFirst( $string );
- $string = ltrim( $string );
- $string = $ellipsis . $string;
+ $string = $ellipsis . ltrim( $string );
}
}