*/
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 );
}
}
* Checks that convertPlural was given an array and pads it to requested
* amount of forms by copying the last one.
*
- * @param array $forms Array of forms given to convertPlural
+ * @param array $forms
* @param int $count How many forms should there be at least
- * @return array Padded array of forms or an exception if not an array
+ * @return array Padded array of forms
*/
protected function preConvertPlural( /* Array */ $forms, $count ) {
- while ( count( $forms ) < $count ) {
- $forms[] = $forms[count( $forms ) - 1];
- }
- return $forms;
+ return array_pad( $forms, $count, end( $forms ) );
}
/**