Always use mbstring functions

This commit is contained in:
Henrique Moody 2016-10-30 10:44:52 +01:00
parent 4d72af312f
commit f34a34c0b2
No known key found for this signature in database
GPG key ID: 221E9281655813A6
31 changed files with 45 additions and 44 deletions

View file

@ -11,6 +11,7 @@ return Symfony\CS\Config\Config::create()
->level(\Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->fixers(array(
'empty_return',
'mb_str_functions',
'multiline_spaces_before_semicolon',
'newline_after_open_tag',
'no_useless_else',

View file

@ -31,7 +31,7 @@ abstract class AbstractInterval extends AbstractRule
return $value;
}
if (strlen($value) == 1) {
if (mb_strlen($value) == 1) {
return $value;
}

View file

@ -24,7 +24,7 @@ class Base extends AbstractRule
$this->chars = $chars;
}
$max = strlen($this->chars);
$max = mb_strlen($this->chars);
if (!is_numeric($base) || $base > $max) {
throw new BaseException(sprintf('a base between 1 and %s is required', $max));
}
@ -33,7 +33,7 @@ class Base extends AbstractRule
public function validate($input)
{
$valid = substr($this->chars, 0, $this->base);
$valid = mb_substr($this->chars, 0, $this->base);
return (bool) preg_match("@^[$valid]+$@", (string) $input);
}

View file

@ -29,7 +29,7 @@ class Bsn extends AbstractRule
return false;
}
if (strlen($input) !== 9) {
if (mb_strlen($input) !== 9) {
return false;
}

View file

@ -23,7 +23,7 @@ class Cnh extends AbstractRule
$input = preg_replace('{\D}', '', (string) $input);
// Validate length and invalid numbers
if ((strlen($input) != 11) || (intval($input) == 0)) {
if ((mb_strlen($input) != 11) || (intval($input) == 0)) {
return false;
}

View file

@ -19,7 +19,7 @@ class Cnpj extends AbstractRule
$c = preg_replace('/\D/', '', $input);
$b = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
if (strlen($c) != 14) {
if (mb_strlen($c) != 14) {
return false;
}

View file

@ -319,7 +319,7 @@ class CountryCode extends AbstractRule
public function validate($input)
{
return in_array(
strtoupper($input),
mb_strtoupper($input),
$this->getCountryCodeList($this->index),
true
);

View file

@ -18,7 +18,7 @@ class Cpf extends AbstractRule
// Code ported from jsfromhell.com
$c = preg_replace('/\D/', '', $input);
if (strlen($c) != 11 || preg_match("/^{$c[0]}{11}$/", $c)) {
if (mb_strlen($c) != 11 || preg_match("/^{$c[0]}{11}$/", $c)) {
return false;
}

View file

@ -82,8 +82,8 @@ class CreditCard extends AbstractRule
{
$sum = 0;
$input = strrev($input);
for ($i = 0; $i < strlen($input); ++$i) {
$current = substr($input, $i, 1);
for ($i = 0; $i < mb_strlen($input); ++$i) {
$current = mb_substr($input, $i, 1);
if ($i % 2 == 1) {
$current *= 2;
if ($current > 9) {

View file

@ -204,6 +204,6 @@ class CurrencyCode extends AbstractRule
public function validate($input)
{
return in_array(strtoupper($input), $this->currencyCodes, true);
return in_array(mb_strtoupper($input), $this->currencyCodes, true);
}
}

View file

@ -35,7 +35,7 @@ class Domain extends AbstractComposite
new AllOf(
new StartsWith('xn--'),
new Callback(function ($str) {
return substr_count($str, '--') == 1;
return mb_substr_count($str, '--') == 1;
})
)
)

View file

@ -19,11 +19,11 @@ class HexRgbColor extends Xdigit
return false;
}
if (0 === strpos($input, '#')) {
$input = substr($input, 1);
if (0 === mb_strpos($input, '#')) {
$input = mb_substr($input, 1);
}
$length = strlen($input);
$length = mb_strlen($input);
if ($length != 3 && $length != 6) {
return false;
}

View file

@ -19,7 +19,7 @@ class IdentityCard extends AbstractWrapper
public function __construct($countryCode)
{
$shortName = ucfirst(strtolower($countryCode)).'IdentityCard';
$shortName = ucfirst(mb_strtolower($countryCode)).'IdentityCard';
$className = __NAMESPACE__.'\\Locale\\'.$shortName;
if (!class_exists($className)) {
throw new ComponentException(sprintf('There is no support for identity cards from "%s"', $countryCode));

View file

@ -37,6 +37,6 @@ class Image extends AbstractRule
return false;
}
return 0 === strpos($this->fileInfo->file($input), 'image/');
return 0 === mb_strpos($this->fileInfo->file($input), 'image/');
}
}

View file

@ -29,7 +29,7 @@ class Imei extends AbstractRule
}
$numbers = preg_replace('/\D/', '', $input);
if (strlen($numbers) != self::IMEI_SIZE) {
if (mb_strlen($numbers) != self::IMEI_SIZE) {
return false;
}

View file

@ -39,11 +39,11 @@ class Ip extends AbstractRule
$range = ['min' => null, 'max' => null, 'mask' => null];
if (strpos($input, '-') !== false) {
if (mb_strpos($input, '-') !== false) {
list($range['min'], $range['max']) = explode('-', $input);
} elseif (strpos($input, '*') !== false) {
} elseif (mb_strpos($input, '*') !== false) {
$this->parseRangeUsingWildcards($input, $range);
} elseif (strpos($input, '/') !== false) {
} elseif (mb_strpos($input, '/') !== false) {
$this->parseRangeUsingCidr($input, $range);
} else {
throw new ComponentException('Invalid network range');
@ -62,7 +62,7 @@ class Ip extends AbstractRule
protected function fillAddress(&$input, $char = '*')
{
while (substr_count($input, '.') < 3) {
while (mb_substr_count($input, '.') < 3) {
$input .= '.'.$char;
}
}
@ -81,7 +81,7 @@ class Ip extends AbstractRule
$this->fillAddress($input[0], '0');
$range['min'] = $input[0];
$isAddressMask = strpos($input[1], '.') !== false;
$isAddressMask = mb_strpos($input[1], '.') !== false;
if ($isAddressMask && $this->verifyAddress($input[1])) {
$range['mask'] = sprintf('%032b', ip2long($input[1]));

View file

@ -556,7 +556,7 @@ class LanguageCode extends AbstractRule
}
return in_array(
strtoupper($input),
mb_strtoupper($input),
$this->getLanguageCodeList($this->index),
true
);

View file

@ -66,7 +66,7 @@ class Length extends AbstractRule
}
if (is_int($input)) {
return strlen((string) $input);
return mb_strlen((string) $input);
}
return false;

View file

@ -21,7 +21,7 @@ class Factory
*/
public function bic($countryCode)
{
$filteredCountryCode = strtoupper($countryCode);
$filteredCountryCode = mb_strtoupper($countryCode);
switch ($filteredCountryCode) {
case 'DE':
return new GermanBic();
@ -41,7 +41,7 @@ class Factory
*/
public function bank($countryCode)
{
$filteredCountryCode = strtoupper($countryCode);
$filteredCountryCode = mb_strtoupper($countryCode);
switch ($filteredCountryCode) {
case 'DE':
return new GermanBank();
@ -61,7 +61,7 @@ class Factory
*/
public function bankAccount($countryCode, $bank)
{
$filteredCountryCode = strtoupper($countryCode);
$filteredCountryCode = mb_strtoupper($countryCode);
switch ($filteredCountryCode) {
case 'DE':
return new GermanBankAccount($bank);

View file

@ -28,7 +28,7 @@ class NfeAccessKey extends AbstractRule
*/
public function validate($aK)
{
if (strlen($aK) !== 44) {
if (mb_strlen($aK) !== 44) {
return false;
}

View file

@ -50,7 +50,7 @@ final class Nif extends AbstractRule
*/
private function validateDni($number, $control)
{
return substr('TRWAGMYFPDXBNJZSQVHLCKE', ($number % 23), 1) === $control;
return mb_substr('TRWAGMYFPDXBNJZSQVHLCKE', ($number % 23), 1) === $control;
}
/**
@ -97,6 +97,6 @@ final class Nif extends AbstractRule
return (int) $key === (int) $control;
}
return substr('JABCDEFGHI', ($key % 10), 1) === $control;
return mb_substr('JABCDEFGHI', ($key % 10), 1) === $control;
}
}

View file

@ -184,7 +184,7 @@ class PostalCode extends Regex
}
$regex = self::DEFAULT_PATTERN;
$upperCountryCode = strtoupper($countryCode);
$upperCountryCode = mb_strtoupper($countryCode);
if (isset($this->postalCodes[$upperCountryCode])) {
$regex = $this->postalCodes[$upperCountryCode];
}

View file

@ -15,7 +15,7 @@ class Slug extends AbstractRule
{
public function validate($input)
{
if (strstr($input, '--')) {
if (mb_strstr($input, '--')) {
return false;
}

View file

@ -25,7 +25,7 @@ class SubdivisionCode extends AbstractWrapper
public function __construct($countryCode)
{
$shortName = ucfirst(strtolower($countryCode)).'SubdivisionCode';
$shortName = ucfirst(mb_strtolower($countryCode)).'SubdivisionCode';
$className = __NAMESPACE__.'\\SubdivisionCode\\'.$shortName;
if (!class_exists($className)) {
throw new ComponentException(sprintf('"%s" is not a valid country code in ISO 3166-2', $countryCode));

View file

@ -120,6 +120,6 @@ class Tld extends AbstractRule
public function validate($input)
{
return in_array(strtolower($input), $this->tldList);
return in_array(mb_strtolower($input), $this->tldList);
}
}

View file

@ -33,7 +33,7 @@ class Type extends AbstractRule
public function __construct($type)
{
$lowerType = strtolower($type);
$lowerType = mb_strtolower($type);
if (!isset($this->availableTypes[$lowerType])) {
throw new ComponentException(sprintf('"%s" is not a valid type', print_r($type, true)));
}
@ -43,7 +43,7 @@ class Type extends AbstractRule
public function validate($input)
{
$lowerType = strtolower($this->type);
$lowerType = mb_strtolower($this->type);
if ('callable' === $lowerType) {
return is_callable($input);
}

View file

@ -19,7 +19,7 @@ final class Vatin extends AbstractWrapper
public function __construct($countryCode)
{
$shortName = ucfirst(strtolower($countryCode)).'Vatin';
$shortName = ucfirst(mb_strtolower($countryCode)).'Vatin';
$className = __NAMESPACE__.'\\Locale\\'.$shortName;
if (!class_exists($className)) {
$message = sprintf('There is no support for VAT identification number from "%s"', $countryCode);

View file

@ -40,13 +40,13 @@ class VideoUrl extends AbstractRule
*/
public function __construct($service = null)
{
$serviceKey = strtolower($service);
$serviceKey = mb_strtolower($service);
if (null !== $service && !isset($this->services[$serviceKey])) {
throw new ComponentException(sprintf('"%s" is not a recognized video service.', $service));
}
$this->service = $service;
$this->serviceKey = strtolower($service);
$this->serviceKey = mb_strtolower($service);
}
/**

View file

@ -29,7 +29,7 @@ class Zend extends AbstractRule
throw new ComponentException('Invalid Validator Construct');
}
if (false === stripos($validator, 'Zend')) {
if (false === mb_stripos($validator, 'Zend')) {
$validator = "Zend\\Validator\\{$validator}";
} else {
$validator = "\\{$validator}";

View file

@ -28,7 +28,7 @@ class CheckExceptionsTest extends \PHPUnit_Framework_TestCase
continue;
}
$ruleName = substr($fileInfo->getBasename(), 0, -4);
$ruleName = mb_substr($fileInfo->getBasename(), 0, -4);
$ruleIsDeprecated = in_array($ruleName, $this->deprecateds);
$isRuleClassFile = (bool) ($fileInfo->getExtension() !== 'php');
if ($ruleIsDeprecated || $isRuleClassFile) {

View file

@ -28,8 +28,8 @@ class PhpLabelTest extends RuleTestCase
[$rule, 'f00'],
[$rule, uniqid('_')],
[$rule, uniqid('a')],
[$rule, strtoupper(uniqid('_'))],
[$rule, strtoupper(uniqid('a'))],
[$rule, mb_strtoupper(uniqid('_'))],
[$rule, mb_strtoupper(uniqid('a'))],
];
}