diff --git a/.travis.yml b/.travis.yml index 06ec3b20..3efa8f18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,21 @@ language: php php: - - 5.6 + - 7.2 - 7.4 +env: + global: + - DEFAULT=1 + matrix: fast_finish: true include: - php: 7.4 - env: PHPCS=1 + env: CHECKS=1 DEFAULT=0 - - php: 5.6 + - php: 7.2 env: PREFER_LOWEST=1 install: @@ -19,8 +23,9 @@ install: - if [[ $PREFER_LOWEST == 1 ]]; then composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable ; fi script: - - sh -c "if [ '$PHPCS' != '1' ]; then vendor/bin/phpunit; fi" - - sh -c "if [ '$PHPCS' = '1' ]; then ./vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/; fi" + - if [[ $DEFAULT == 1 ]]; then vendor/bin/phpunit; fi + - if [[ $CHECKS == 1 ]]; then composer stan-setup && composer stan ; fi + - if [[ $CHECKS == 1 ]]; then composer cs-check ; fi cache: directories: diff --git a/composer.json b/composer.json index 63d233b6..72495e3a 100644 --- a/composer.json +++ b/composer.json @@ -18,12 +18,12 @@ "source": "https://github.com/cakephp/localized" }, "require": { - "php": ">=5.6", - "cakephp/cakephp": "^3.5" + "php": ">=7.2", + "cakephp/cakephp": "^4.0.0" }, "require-dev": { - "cakephp/cakephp-codesniffer": "^3.0", - "phpunit/phpunit": "^4.8|^5.7|^6.0" + "cakephp/cakephp-codesniffer": "^4.0", + "phpunit/phpunit": "^8.0" }, "autoload": { "psr-4": { @@ -35,5 +35,27 @@ "Cake\\Test\\": "vendor/cakephp/cakephp/tests", "Cake\\Localized\\Test\\": "tests" } + }, + "scripts": { + "check": [ + "@cs-check", + "@test", + "@analyse" + ], + "analyse": [ + "@stan", + "@psalm" + ], + "cs-check": "phpcs -p -n --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/", + "cs-fix": "phpcbf --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/", + "test": "phpunit --stderr", + "stan": "phpstan analyse src/", + "psalm": "php vendor/psalm/phar/psalm.phar --show-info=false src/", + "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^0.12.0 psalm/phar:^3.7 && mv composer.backup composer.json", + "stan-rebuild-baseline": "phpstan analyse --configuration phpstan.neon --error-format baselineNeon src/ > phpstan-baseline.neon", + "psalm-rebuild-baseline": "php vendor/psalm/phar/psalm.phar --show-info=false --set-baseline=psalm-baseline.xml src/", + "rector": "rector process src/", + "rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:^0.7 && mv composer.backup composer.json", + "coverage-test": "phpunit --stderr --coverage-clover=clover.xml" } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..efda9224 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: 1 + treatPhpDocTypesAsCertain: false + autoload_files: + - tests/bootstrap.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 36ec5426..4b379895 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,7 +3,6 @@ colors="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="./tests/bootstrap.php" > @@ -18,15 +17,5 @@ - - - - ./vendor/ - ./vendor/ - - ./tests/ - ./tests/ - - diff --git a/src/Locale/ar/cake.po b/resources/locales/ar/cake.po old mode 100755 new mode 100644 similarity index 100% rename from src/Locale/ar/cake.po rename to resources/locales/ar/cake.po diff --git a/src/Locale/ar_TN/cake.po b/resources/locales/ar_TN/cake.po similarity index 100% rename from src/Locale/ar_TN/cake.po rename to resources/locales/ar_TN/cake.po diff --git a/src/Locale/ca_ES/cake.po b/resources/locales/ca_ES/cake.po old mode 100755 new mode 100644 similarity index 100% rename from src/Locale/ca_ES/cake.po rename to resources/locales/ca_ES/cake.po diff --git a/src/Locale/cake.pot b/resources/locales/cake.pot similarity index 100% rename from src/Locale/cake.pot rename to resources/locales/cake.pot diff --git a/src/Locale/cs/cake.po b/resources/locales/cs/cake.po similarity index 100% rename from src/Locale/cs/cake.po rename to resources/locales/cs/cake.po diff --git a/src/Locale/da/cake.po b/resources/locales/da/cake.po similarity index 100% rename from src/Locale/da/cake.po rename to resources/locales/da/cake.po diff --git a/src/Locale/de/cake.po b/resources/locales/de/cake.po similarity index 100% rename from src/Locale/de/cake.po rename to resources/locales/de/cake.po diff --git a/src/Locale/es/cake.mo b/resources/locales/es/cake.mo similarity index 100% rename from src/Locale/es/cake.mo rename to resources/locales/es/cake.mo diff --git a/src/Locale/es/cake.po b/resources/locales/es/cake.po similarity index 100% rename from src/Locale/es/cake.po rename to resources/locales/es/cake.po diff --git a/src/Locale/fa_IR/cake.po b/resources/locales/fa_IR/cake.po similarity index 100% rename from src/Locale/fa_IR/cake.po rename to resources/locales/fa_IR/cake.po diff --git a/src/Locale/fr_FR/cake.po b/resources/locales/fr_FR/cake.po similarity index 100% rename from src/Locale/fr_FR/cake.po rename to resources/locales/fr_FR/cake.po diff --git a/src/Locale/hu/cake.po b/resources/locales/hu/cake.po similarity index 100% rename from src/Locale/hu/cake.po rename to resources/locales/hu/cake.po diff --git a/src/Locale/it/cake.po b/resources/locales/it/cake.po similarity index 100% rename from src/Locale/it/cake.po rename to resources/locales/it/cake.po diff --git a/src/Locale/ja_JP/cake.po b/resources/locales/ja_JP/cake.po similarity index 100% rename from src/Locale/ja_JP/cake.po rename to resources/locales/ja_JP/cake.po diff --git a/src/Locale/nb/cake.po b/resources/locales/nb/cake.po similarity index 100% rename from src/Locale/nb/cake.po rename to resources/locales/nb/cake.po diff --git a/src/Locale/nl/cake.po b/resources/locales/nl/cake.po similarity index 100% rename from src/Locale/nl/cake.po rename to resources/locales/nl/cake.po diff --git a/src/Locale/no/cake.po b/resources/locales/no/cake.po similarity index 100% rename from src/Locale/no/cake.po rename to resources/locales/no/cake.po diff --git a/src/Locale/pl/cake.po b/resources/locales/pl/cake.po similarity index 100% rename from src/Locale/pl/cake.po rename to resources/locales/pl/cake.po diff --git a/src/Locale/pt/cake.po b/resources/locales/pt/cake.po similarity index 100% rename from src/Locale/pt/cake.po rename to resources/locales/pt/cake.po diff --git a/src/Locale/ro_RO/cake.po b/resources/locales/ro_RO/cake.po similarity index 100% rename from src/Locale/ro_RO/cake.po rename to resources/locales/ro_RO/cake.po diff --git a/src/Locale/ru/cake.po b/resources/locales/ru/cake.po similarity index 100% rename from src/Locale/ru/cake.po rename to resources/locales/ru/cake.po diff --git a/src/Locale/tr/cake.po b/resources/locales/tr/cake.po similarity index 100% rename from src/Locale/tr/cake.po rename to resources/locales/tr/cake.po diff --git a/src/Locale/ua/cake.po b/resources/locales/ua/cake.po similarity index 100% rename from src/Locale/ua/cake.po rename to resources/locales/ua/cake.po diff --git a/src/Locale/vi/cake.po b/resources/locales/vi/cake.po similarity index 100% rename from src/Locale/vi/cake.po rename to resources/locales/vi/cake.po diff --git a/src/Locale/zh_CN/cake.po b/resources/locales/zh_CN/cake.po similarity index 100% rename from src/Locale/zh_CN/cake.po rename to resources/locales/zh_CN/cake.po diff --git a/src/Plugin.php b/src/Plugin.php new file mode 100644 index 00000000..76ffd253 --- /dev/null +++ b/src/Plugin.php @@ -0,0 +1,49 @@ += 10) ? 0 : $x - $dsc; + $dv2 = $x >= 10 ? 0 : $x - $dsc; - return ($dv1 . $dv2) === substr($check, -2); + return $dv1 . $dv2 === substr($check, -2); } /** @@ -188,7 +186,7 @@ public static function cnh($cnh) * @param string|int $cns National Heath Card Number * @return bool */ - public static function cns($cns) + public static function cns($cns): bool { if (!is_numeric($cns) && !is_string($cns)) { return false; diff --git a/src/Validation/CaValidation.php b/src/Validation/CaValidation.php index 853877bc..0acdd4f7 100644 --- a/src/Validation/CaValidation.php +++ b/src/Validation/CaValidation.php @@ -1,4 +1,6 @@ = 10) { diff --git a/src/Validation/FrValidation.php b/src/Validation/FrValidation.php index 746a973f..0bc9a481 100644 --- a/src/Validation/FrValidation.php +++ b/src/Validation/FrValidation.php @@ -1,4 +1,6 @@ = 1000 && $value <= 99138; } @@ -58,7 +60,7 @@ public static function postal($check) * @param string $check The value to check. * @return bool Success. */ - public static function personId($check) + public static function personId(string $check): bool { $pattern = '/^[12]\d{2}(0\d|1[012])(\d{2}|2[AB])\d{8}$/'; if (!preg_match($pattern, $check)) { @@ -71,14 +73,14 @@ public static function personId($check) // Corse special cases // source : http://xml.insee.fr/schema/nir.html // check : http://www.parodie.com/monetique/nir.htm - if ($numberWithoutKey[6] == 'A') { + if ($numberWithoutKey[6] === 'A') { $numberWithoutKey = str_replace('A', '0', $numberWithoutKey); $numberWithoutKey -= 1000000; - } elseif ($numberWithoutKey[6] == 'B') { + } elseif ($numberWithoutKey[6] === 'B') { $numberWithoutKey = str_replace('B', '0', $numberWithoutKey); $numberWithoutKey -= 2000000; } - return $key == (97 - ($numberWithoutKey - (floor($numberWithoutKey / 97) * 97))); + return $key == 97 - ($numberWithoutKey - (floor($numberWithoutKey / 97) * 97)); } } diff --git a/src/Validation/GbValidation.php b/src/Validation/GbValidation.php index a806e577..2240f27c 100644 --- a/src/Validation/GbValidation.php +++ b/src/Validation/GbValidation.php @@ -1,4 +1,6 @@ 31, 'Z' => 33, ]; $n1 = $keyTable[$check[0]]; - $checksum = intval($n1 / 10) + ($n1 % 10) * 9; + $checksum = (int)($n1 / 10) + ($n1 % 10) * 9; for ($i = 1; $i < 9; $i++) { $checksum += $check[$i] * (9 - $i); } - return (substr(10 - ($checksum % 10), 0, 1) == $check[9]); + return substr(strval(10 - ($checksum % 10)), 0, 1) === $check[9]; } /** @@ -82,16 +84,16 @@ public static function personId($check) * @return bool Success. * @link http://herolin.mine.nu/entry/is-valid-TW-company-ID */ - public static function ubn($check) + public static function ubn(string $check): bool { - if (!preg_match('/^[0-9]{8}$/', $check)) { + if (!preg_match('/^\d{8}$/', $check)) { return false; } $tbNum = [1, 2, 1, 2, 1, 2, 4, 1]; $intSum = 0; for ($i = 0; $i < 8; $i++) { $intMultiply = $check[$i] * $tbNum[$i]; - $intAddition = (floor($intMultiply / 10) + ($intMultiply % 10)); + $intAddition = floor($intMultiply / 10) + ($intMultiply % 10); $intSum += $intAddition; } @@ -105,7 +107,7 @@ public static function ubn($check) * @return bool Success. * @deprecated Use personId() instead. */ - public static function nicn($check) + public static function nicn(string $check): bool { return static::personId($check); } diff --git a/src/Validation/UaValidation.php b/src/Validation/UaValidation.php index 062e2a31..a1e899ea 100644 --- a/src/Validation/UaValidation.php +++ b/src/Validation/UaValidation.php @@ -1,4 +1,6 @@ 'fr', ]); $this->assertCount(2, $validator); - $this->assertEmpty($validator->errors([ + $this->assertEmpty($validator->validate([ 'phoneField' => '05 24 22 72 27', 'postalField' => '93000', ])); - $errors = $validator->errors(['phoneField' => '924.227.227', 'postalField' => '0000']); + $errors = $validator->validate(['phoneField' => '924.227.227', 'postalField' => '0000']); $expected = [ 'phoneField' => ['myCustomRuleNameForPhone' => 'Numéro invalide'], 'postalField' => ['myCustomRuleNameForPostal' => 'The provided value is invalid'], diff --git a/tests/TestCase/Validation/AtValidationTest.php b/tests/TestCase/Validation/AtValidationTest.php index b92c24e8..8202b98a 100644 --- a/tests/TestCase/Validation/AtValidationTest.php +++ b/tests/TestCase/Validation/AtValidationTest.php @@ -1,4 +1,6 @@ assertFalse(BrValidation::cpf('abcdefghi')); //testing 15 digits - $this->assertFalse(BrValidation::cnpj(123456789123456)); - $this->assertFalse(BrValidation::cnpj(062476224000121)); + $this->assertFalse(BrValidation::cnpj('123456789123456')); + $this->assertFalse(BrValidation::cnpj('062476224000121')); $this->assertFalse(BrValidation::cnpj('062476224000121')); $this->assertFalse(BrValidation::cnpj('062.476.224/0001-21')); $this->assertTrue(BrValidation::cnpj('62.476.224/0001-21')); - $this->assertTrue(BrValidation::cnpj(62476224000121)); + $this->assertTrue(BrValidation::cnpj('62476224000121')); $this->assertTrue(BrValidation::cnpj('62476224000121')); } @@ -170,7 +172,6 @@ public function testCnh() $this->assertFalse(BrValidation::cnh('11111111111')); $this->assertFalse(BrValidation::cnh('018278545')); $this->assertFalse(BrValidation::cnh('abcdefghij')); - $this->assertFalse(BrValidation::cnh(['01827854569'])); } /** @@ -183,7 +184,7 @@ public function testCns() $this->assertTrue(BrValidation::cns('702 5053 3246 4238')); $this->assertTrue(BrValidation::cns('898 0058 0155 2261')); $this->assertTrue(BrValidation::cns('706000307269748')); - $this->assertTrue(BrValidation::cns(706902161943931)); + $this->assertTrue(BrValidation::cns('706902161943931')); $this->assertFalse(BrValidation::cns('702 5053 3246 4237')); $this->assertFalse(BrValidation::cns('111 1111 1111 1111')); diff --git a/tests/TestCase/Validation/CaValidationTest.php b/tests/TestCase/Validation/CaValidationTest.php index a26ab25a..32bdd1cc 100644 --- a/tests/TestCase/Validation/CaValidationTest.php +++ b/tests/TestCase/Validation/CaValidationTest.php @@ -1,4 +1,6 @@ assertFalse(TnValidation::phone('9899999')); $this->assertFalse(TnValidation::phone('989999999')); $this->assertFalse(TnValidation::phone('004012345678')); - $this->assertFalse(TnValidation::phone(false)); $this->assertFalse(TnValidation::phone('abcdef')); } @@ -81,7 +82,6 @@ public function testPostal() $this->assertFalse(TnValidation::postal('abcd')); $this->assertFalse(TnValidation::postal('1')); $this->assertFalse(TnValidation::postal('10')); - $this->assertFalse(TnValidation::postal(true)); } /** @@ -99,7 +99,6 @@ public function testPersonId() $this->assertFalse(TnValidation::personId('0123456789')); $this->assertFalse(TnValidation::personId('1234 56798')); $this->assertFalse(TnValidation::personId('01234 567989')); - $this->assertFalse(TnValidation::personId(true)); $this->assertFalse(TnValidation::personId('abcdefgh')); } } diff --git a/tests/TestCase/Validation/TrValidationTest.php b/tests/TestCase/Validation/TrValidationTest.php index 84cebde2..b263d955 100644 --- a/tests/TestCase/Validation/TrValidationTest.php +++ b/tests/TestCase/Validation/TrValidationTest.php @@ -1,4 +1,6 @@ dirname(dirname(__FILE__)) . DS]); +Plugin::getCollection()->add(new \Cake\Localized\Plugin([ + 'path' => dirname(dirname(__FILE__)) . DS, + 'routes' => false, +]));