From ae1ce2c47de16916db8473c21b3620f4afebe6df Mon Sep 17 00:00:00 2001 From: Yevgeny Tomenko Date: Sun, 16 Feb 2020 00:24:55 +0300 Subject: [PATCH 1/9] upgrade to cakephp 4.0 --- .semver | 5 ++ composer.json | 30 ++++++++-- phpunit.xml.dist | 11 ---- {src/Locale => resources/locales}/ar/cake.po | 0 .../locales}/ar_TN/cake.po | 0 .../locales}/ca_ES/cake.po | 0 {src/Locale => resources/locales}/cake.pot | 0 {src/Locale => resources/locales}/cs/cake.po | 0 {src/Locale => resources/locales}/da/cake.po | 0 {src/Locale => resources/locales}/de/cake.po | 0 {src/Locale => resources/locales}/es/cake.mo | Bin {src/Locale => resources/locales}/es/cake.po | 0 .../locales}/fa_IR/cake.po | 0 .../locales}/fr_FR/cake.po | 0 {src/Locale => resources/locales}/hu/cake.po | 0 {src/Locale => resources/locales}/it/cake.po | 0 .../locales}/ja_JP/cake.po | 0 {src/Locale => resources/locales}/nb/cake.po | 0 {src/Locale => resources/locales}/nl/cake.po | 0 {src/Locale => resources/locales}/no/cake.po | 0 {src/Locale => resources/locales}/pl/cake.po | 0 {src/Locale => resources/locales}/pt/cake.po | 0 .../locales}/ro_RO/cake.po | 0 {src/Locale => resources/locales}/ru/cake.po | 0 {src/Locale => resources/locales}/tr/cake.po | 0 {src/Locale => resources/locales}/ua/cake.po | 0 {src/Locale => resources/locales}/vi/cake.po | 0 .../locales}/zh_CN/cake.po | 0 src/Plugin.php | 30 ++++++++++ src/Validation/AtValidation.php | 22 +++---- src/Validation/AuValidation.php | 20 ++++--- src/Validation/BdValidation.php | 20 ++++--- src/Validation/BeValidation.php | 20 ++++--- src/Validation/BrValidation.php | 54 +++++++++--------- src/Validation/CaValidation.php | 20 ++++--- src/Validation/ChValidation.php | 22 +++---- src/Validation/CnValidation.php | 20 ++++--- src/Validation/CzValidation.php | 20 ++++--- src/Validation/DeValidation.php | 24 ++++---- src/Validation/DkValidation.php | 28 ++++----- src/Validation/EsValidation.php | 42 +++++++------- src/Validation/FiValidation.php | 51 ++++++++--------- src/Validation/FrValidation.php | 26 +++++---- src/Validation/GbValidation.php | 22 +++---- src/Validation/HrValidation.php | 18 +++--- src/Validation/IdValidation.php | 26 +++++---- src/Validation/InValidation.php | 18 +++--- src/Validation/IrValidation.php | 34 +++++------ src/Validation/ItValidation.php | 34 +++++------ src/Validation/JpValidation.php | 28 ++++----- src/Validation/LocalizedValidation.php | 8 ++- src/Validation/LtValidation.php | 18 +++--- src/Validation/LvValidation.php | 23 ++++---- src/Validation/MxValidation.php | 18 +++--- src/Validation/NlValidation.php | 20 ++++--- src/Validation/NoValidation.php | 18 +++--- src/Validation/PlValidation.php | 54 +++++++----------- src/Validation/PtValidation.php | 22 +++---- src/Validation/RoValidation.php | 22 +++---- src/Validation/RsValidation.php | 36 ++++++------ src/Validation/RuValidation.php | 32 ++++++----- src/Validation/SkValidation.php | 20 ++++--- src/Validation/TnValidation.php | 22 +++---- src/Validation/TrValidation.php | 22 +++---- src/Validation/TwValidation.php | 36 ++++++------ src/Validation/UaValidation.php | 24 ++++---- src/Validation/UkValidation.php | 10 ++-- src/Validation/UsValidation.php | 22 +++---- src/Validation/ValidationInterface.php | 16 +++--- tests/TestCase/IntegrationTest.php | 10 ++-- .../TestCase/Validation/AtValidationTest.php | 2 + .../TestCase/Validation/AuValidationTest.php | 2 + .../TestCase/Validation/BdValidationTest.php | 2 + .../TestCase/Validation/BeValidationTest.php | 2 + .../TestCase/Validation/BrValidationTest.php | 11 ++-- .../TestCase/Validation/CaValidationTest.php | 2 + .../TestCase/Validation/ChValidationTest.php | 2 + .../TestCase/Validation/CnValidationTest.php | 2 + .../TestCase/Validation/CzValidationTest.php | 2 + .../TestCase/Validation/DeValidationTest.php | 2 +- .../TestCase/Validation/DkValidationTest.php | 2 + .../TestCase/Validation/EsValidationTest.php | 2 + .../TestCase/Validation/FiValidationTest.php | 3 +- .../TestCase/Validation/FrValidationTest.php | 2 + .../TestCase/Validation/GbValidationTest.php | 2 + .../TestCase/Validation/HrValidationTest.php | 2 + ...idatationTest.php => IdValidationTest.php} | 2 + ...idatationTest.php => InValidationTest.php} | 2 + .../TestCase/Validation/IrValidationTest.php | 2 + .../TestCase/Validation/ItValidationTest.php | 2 + .../TestCase/Validation/JpValidationTest.php | 2 + .../TestCase/Validation/LtValidationTest.php | 2 + .../TestCase/Validation/LvValidationTest.php | 3 +- .../TestCase/Validation/MxValidationTest.php | 2 + .../TestCase/Validation/NlValidationTest.php | 2 + .../TestCase/Validation/NoValidationTest.php | 2 + .../TestCase/Validation/PlValidationTest.php | 2 + .../TestCase/Validation/PtValidationTest.php | 2 + .../TestCase/Validation/RoValidationTest.php | 2 + .../TestCase/Validation/RsValidationTest.php | 2 + .../TestCase/Validation/RuValidationTest.php | 3 + .../TestCase/Validation/SkValidationTest.php | 2 + .../TestCase/Validation/TnValidationTest.php | 5 +- .../TestCase/Validation/TrValidationTest.php | 2 + .../TestCase/Validation/TwValidationTest.php | 2 + .../TestCase/Validation/UaValidationTest.php | 2 + .../TestCase/Validation/UsValidationTest.php | 2 + tests/bootstrap.php | 13 ++++- 108 files changed, 688 insertions(+), 512 deletions(-) create mode 100644 .semver rename {src/Locale => resources/locales}/ar/cake.po (100%) mode change 100755 => 100644 rename {src/Locale => resources/locales}/ar_TN/cake.po (100%) rename {src/Locale => resources/locales}/ca_ES/cake.po (100%) mode change 100755 => 100644 rename {src/Locale => resources/locales}/cake.pot (100%) rename {src/Locale => resources/locales}/cs/cake.po (100%) rename {src/Locale => resources/locales}/da/cake.po (100%) rename {src/Locale => resources/locales}/de/cake.po (100%) rename {src/Locale => resources/locales}/es/cake.mo (100%) rename {src/Locale => resources/locales}/es/cake.po (100%) rename {src/Locale => resources/locales}/fa_IR/cake.po (100%) rename {src/Locale => resources/locales}/fr_FR/cake.po (100%) rename {src/Locale => resources/locales}/hu/cake.po (100%) rename {src/Locale => resources/locales}/it/cake.po (100%) rename {src/Locale => resources/locales}/ja_JP/cake.po (100%) rename {src/Locale => resources/locales}/nb/cake.po (100%) rename {src/Locale => resources/locales}/nl/cake.po (100%) rename {src/Locale => resources/locales}/no/cake.po (100%) rename {src/Locale => resources/locales}/pl/cake.po (100%) rename {src/Locale => resources/locales}/pt/cake.po (100%) rename {src/Locale => resources/locales}/ro_RO/cake.po (100%) rename {src/Locale => resources/locales}/ru/cake.po (100%) rename {src/Locale => resources/locales}/tr/cake.po (100%) rename {src/Locale => resources/locales}/ua/cake.po (100%) rename {src/Locale => resources/locales}/vi/cake.po (100%) rename {src/Locale => resources/locales}/zh_CN/cake.po (100%) create mode 100644 src/Plugin.php rename tests/TestCase/Validation/{IdValidatationTest.php => IdValidationTest.php} (97%) rename tests/TestCase/Validation/{InValidatationTest.php => InValidationTest.php} (99%) diff --git a/.semver b/.semver new file mode 100644 index 00000000..f5ef8df3 --- /dev/null +++ b/.semver @@ -0,0 +1,5 @@ +--- +:major: 3 +:minor: 0 +:patch: 0 +:special: '' diff --git a/composer.json b/composer.json index 63d233b6..c7f65c09 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 --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/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..96ec00f2 --- /dev/null +++ b/src/Plugin.php @@ -0,0 +1,30 @@ += 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..c4662375 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..46d44ba7 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($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..5de751a4 100644 --- a/src/Validation/GbValidation.php +++ b/src/Validation/GbValidation.php @@ -1,4 +1,6 @@ 15, 'H' => 17, 'I' => 19, 'J' => 21, 'K' => 2, 'L' => 4, 'M' => 18, 'N' => 20, 'O' => 11, 'P' => 3, 'Q' => 6, 'R' => 8, 'S' => 12, 'T' => 14, 'U' => 16, 'V' => 10, 'W' => 22, 'X' => 25, - 'Y' => 24, 'Z' => 23 + 'Y' => 24, 'Z' => 23, ]; $sum = 0; for ($i = 1; $i <= 13; $i += 2) { - $sum += (is_numeric($check[$i])) ? (int)$check[$i] : ord($check[$i]) - ord('A'); + $sum += is_numeric($check[$i]) ? (int)$check[$i] : ord($check[$i]) - ord('A'); } for ($i = 0; $i <= 14; $i += 2) { $sum += $checkOdd[$check[$i]]; } - return (chr($sum % 26 + ord('A')) == $check[15]); + return chr($sum % 26 + ord('A')) === $check[15]; } /** * Checks a country specific identification number. * * @param string $check The value to check. - * @throws NotImplementedException Exception + * @throws \Cake\Network\Exception\NotImplementedException Exception * @return bool Success. */ - public static function personId($check) + public static function personId($check): bool { throw new NotImplementedException(__d('localized', '%s Not implemented yet.')); } diff --git a/src/Validation/JpValidation.php b/src/Validation/JpValidation.php index 38edac89..822a0bd8 100644 --- a/src/Validation/JpValidation.php +++ b/src/Validation/JpValidation.php @@ -1,4 +1,6 @@ 10, 'B' => 11, 'C' => 12, 'D' => 13, 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 34, 'J' => 18, 'K' => 19, 'L' => 20, 'M' => 21, 'N' => 22, 'O' => 35, 'P' => 23, 'Q' => 24, 'R' => 25, 'S' => 26, 'T' => 27, 'U' => 28, 'V' => 29, 'W' => 32, 'X' => 30, - 'Y' => 31, 'Z' => 33 + 'Y' => 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 6f004d24..b1051e80 100644 --- a/src/Validation/UaValidation.php +++ b/src/Validation/UaValidation.php @@ -1,4 +1,6 @@ setProvider('fr', FrValidation::class); $validator->add('phoneField', 'myCustomRuleNameForPhone', [ 'rule' => 'phone', @@ -44,12 +46,12 @@ public function testLocalizedProviderIntegration() 'provider' => 'fr', ]); $this->assertCount(2, $validator); - $this->assertEmpty($validator->errors([ + $this->assertEmpty($validator->validate([ 'phoneField' => '05 24 22 72 27', - 'postalField' => '93000' + '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(RuValidation::passport('1234123456')); $this->assertFalse(RuValidation::passport('1234 1x3456')); } + /** * test vatin method of RuValidation * diff --git a/tests/TestCase/Validation/SkValidationTest.php b/tests/TestCase/Validation/SkValidationTest.php index 5ff4cb8a..8ce35b1f 100644 --- a/tests/TestCase/Validation/SkValidationTest.php +++ b/tests/TestCase/Validation/SkValidationTest.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, +])); From 68d8532809496fa0b65687bbd1507a7ddaf64e6c Mon Sep 17 00:00:00 2001 From: Yevgeny Tomenko Date: Sun, 16 Feb 2020 00:32:55 +0300 Subject: [PATCH 2/9] update travis config --- .travis.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8b178b7c..a66c5dfa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,9 @@ language: php php: - - 5.6 - - 7.0 - - 7.1 - 7.2 + - 7.3 + - 7.4 sudo: false @@ -12,10 +11,10 @@ matrix: fast_finish: true include: - - php: 7.1 + - php: 7.4 env: PHPCS=1 - - php: 5.6 + - php: 7.2 env: PREFER_LOWEST=1 install: From b3b7d4fd1d5b986f67d05e25fb378c58c158a14b Mon Sep 17 00:00:00 2001 From: Yevgeny Tomenko Date: Sun, 16 Feb 2020 00:39:22 +0300 Subject: [PATCH 3/9] refactor obsolete syntax --- src/Validation/IrValidation.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Validation/IrValidation.php b/src/Validation/IrValidation.php index b715d3a7..9a7ffe61 100644 --- a/src/Validation/IrValidation.php +++ b/src/Validation/IrValidation.php @@ -115,8 +115,8 @@ public static function personId(string $check): bool $sum = 0; $equivalent = 0; for ($i = 0; $i < 9; $i++) { - $sum += $check{$i} * (10 - $i); - if ($check{1} === $check{$i}) { + $sum += substr($check, $i, 1) * (10 - $i); + if (substr($check, 1, 1) === substr($check, $i, 1)) { $equivalent++; } } @@ -125,9 +125,9 @@ public static function personId(string $check): bool } $remaining = $sum % 11; if ($remaining <= 1) { - return (bool)($remaining == $check{9}); + return (bool)($remaining == substr($check, 9, 1)); } - return (bool)((11 - $remaining) == $check{9}); + return (bool)((11 - $remaining) == substr($check, 9, 1)); } } From 0fd89a4e05c484e836a9d2013572ae8259426a10 Mon Sep 17 00:00:00 2001 From: Yevgeny Tomenko Date: Sun, 16 Feb 2020 00:43:19 +0300 Subject: [PATCH 4/9] (chore) code cleanup --- src/Validation/IrValidation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Validation/IrValidation.php b/src/Validation/IrValidation.php index 9a7ffe61..2061b66d 100644 --- a/src/Validation/IrValidation.php +++ b/src/Validation/IrValidation.php @@ -128,6 +128,6 @@ public static function personId(string $check): bool return (bool)($remaining == substr($check, 9, 1)); } - return (bool)((11 - $remaining) == substr($check, 9, 1)); + return (bool)(substr($check, 9, 1) == 11 - $remaining); } } From 00e2f98c0331450770baf74a81bc5b5df6dec6b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=AF=D1=80=D0=BE=D1=81=D0=BB=D0=B0=D0=B2?= Date: Fri, 3 Apr 2020 00:37:15 +0300 Subject: [PATCH 5/9] Phone numbers like 80xxyyyyyyy are considered invalid from 14 October 2009 --- src/Validation/UaValidation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Validation/UaValidation.php b/src/Validation/UaValidation.php index b1051e80..4b66aa6a 100644 --- a/src/Validation/UaValidation.php +++ b/src/Validation/UaValidation.php @@ -41,14 +41,14 @@ public static function postal(string $check): bool /** * Checks phone number for Ukraine * - * @example +38-044-283-93-57; (068)2839357; +380442839357; +38 (063)537-28-07; 8044223-95-26; +380612839357; + * @example +38-044-283-93-57; (068)2839357; +380442839357; +38 (063)537-28-07; +380612839357; * @param string $check The value to check. * @return bool Success. * @link https://en.wikipedia.org/wiki/Telephone_numbers_in_Ukraine */ public static function phone(string $check): bool { - $pattern = '/^((8|\+38)-?)?(\(?+...\)?)?-?\d{3}-?\d{2}-?\d{2}$/'; + $pattern = '/^(\+38-?)?(\(?+...\)?)?-?\d{3}-?\d{2}-?\d{2}$/'; return (bool)preg_match($pattern, $check); } From 6c1f1e4d1f320f4c180aa54e589ef469819a2b95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=AF=D1=80=D0=BE=D1=81=D0=BB=D0=B0=D0=B2?= Date: Fri, 3 Apr 2020 00:43:36 +0300 Subject: [PATCH 6/9] Phone numbers like 80xxyyyyyyy are considered invalid from 14 October 2009 --- tests/TestCase/Validation/UaValidationTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/TestCase/Validation/UaValidationTest.php b/tests/TestCase/Validation/UaValidationTest.php index abd1775b..cbd9850b 100644 --- a/tests/TestCase/Validation/UaValidationTest.php +++ b/tests/TestCase/Validation/UaValidationTest.php @@ -52,9 +52,10 @@ public function testPhone() $this->assertTrue(UaValidation::phone('+38-044-283-93-57')); $this->assertTrue(UaValidation::phone('(068)2839357')); $this->assertTrue(UaValidation::phone('+380442839357')); - $this->assertFalse(UaValidation::phone('+38 (063)537-28-07')); - $this->assertTrue(UaValidation::phone('8044223-95-26')); $this->assertTrue(UaValidation::phone('+380612839357')); + + $this->assertFalse(UaValidation::phone('+38 (063)537-28-07')); + $this->assertFalse(UaValidation::phone('8044223-95-26')); } /** From d2cc9fb56c7d45fe3c4d225cfd66d56f3ed750e9 Mon Sep 17 00:00:00 2001 From: mscherer Date: Fri, 3 Apr 2020 00:10:09 +0200 Subject: [PATCH 7/9] Merge CakeDC-3.x as Cake4 prep. --- .editorconfig | 4 +--- .gitattributes | 18 ++---------------- .gitignore | 2 +- .semver | 5 ----- .travis.yml | 9 +++++---- README.md | 10 +++++----- 6 files changed, 14 insertions(+), 34 deletions(-) delete mode 100644 .semver diff --git a/.editorconfig b/.editorconfig index 70619017..6e4a9119 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,6 +1,5 @@ ; This file is for unifying the coding style for different editors and IDEs. -; More information at http://editorconfig.org - +; More information at https://editorconfig.org root = true [*] @@ -14,5 +13,4 @@ trim_trailing_whitespace = true end_of_line = crlf [*.yml] -indent_style = space indent_size = 2 diff --git a/.gitattributes b/.gitattributes index 7ff9965d..5fe90dad 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,20 +1,6 @@ # Define the line ending behavior of the different file extensions -# Set default behaviour, in case users don't have core.autocrlf set. -* text=auto -* text eol=lf - -# Explicitly declare text files we want to always be normalized and converted -# to native line endings on checkout. -*.php text -*.default text -*.ctp text -*.md text -*.po text -*.js text -*.css text -*.ini text -*.txt text -*.xml text +# Set default behavior, in case users don't have core.autocrlf set. +* text text=auto eol=lf # Declare files that will always have CRLF line endings on checkout. *.bat eol=crlf diff --git a/.gitignore b/.gitignore index fab8667a..6c0987d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /composer.lock /phpunit.phar /vendor/ -.idea \ No newline at end of file +/.idea/ diff --git a/.semver b/.semver deleted file mode 100644 index f5ef8df3..00000000 --- a/.semver +++ /dev/null @@ -1,5 +0,0 @@ ---- -:major: 3 -:minor: 0 -:patch: 0 -:special: '' diff --git a/.travis.yml b/.travis.yml index a66c5dfa..6ad997ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,11 +2,8 @@ language: php php: - 7.2 - - 7.3 - 7.4 -sudo: false - matrix: fast_finish: true @@ -23,7 +20,11 @@ install: 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" + - sh -c "if [ '$PHPCS' = '1' ]; then ./vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/; fi" + +cache: + directories: + - $HOME/.composer/cache notifications: email: false diff --git a/README.md b/README.md index d7796170..c56159fd 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # CakePHP Localized plugin -[![Build Status](https://secure.travis-ci.org/cakephp/localized.svg?branch=master)](http://travis-ci.org/cakephp/localized) +[![Build Status](https://travis-ci.org/cakephp/localized.svg?branch=master)](http://travis-ci.org/cakephp/localized) [![License](https://poser.pugx.org/cakephp/localized/license.svg)](https://packagist.org/packages/cakephp/localized) [![Total Downloads](https://poser.pugx.org/cakephp/localized/d/total.svg)](https://packagist.org/packages/cakephp/localized) @@ -9,12 +9,12 @@ This plugin contains various localized validation classes for specific countries The master branch has the following requirements: -* CakePHP 3.1.0 or greater. -* PHP 5.4.16 or greater. +* CakePHP 3.5+. +* PHP 5.6+. ## Installation -You can install this plugin into your CakePHP application using [composer](http://getcomposer.org). +You can install this plugin into your CakePHP application using [composer](https://getcomposer.org). The recommended way to install composer packages is: @@ -43,7 +43,7 @@ class PostsTable extends Table { public function validationDefault(Validator $validator) { - $validator->provider('fr', FrValidation::class); + $validator->setProvider('fr', FrValidation::class); $validator->add('phoneField', 'myCustomRuleNameForPhone', [ 'rule' => 'phone', 'provider' => 'fr' From d2216b507be3dad85feadd661158032d30cac38f Mon Sep 17 00:00:00 2001 From: mscherer Date: Fri, 3 Apr 2020 00:25:56 +0200 Subject: [PATCH 8/9] PHPStan Level 1. --- .travis.yml | 11 ++++++++--- composer.json | 2 +- phpstan.neon | 5 +++++ src/Plugin.php | 19 +++++++++++++++++++ src/Validation/AtValidation.php | 6 +++--- src/Validation/AuValidation.php | 4 ++-- src/Validation/BdValidation.php | 6 +++--- src/Validation/BeValidation.php | 4 ++-- src/Validation/BrValidation.php | 4 ++-- src/Validation/CaValidation.php | 4 ++-- src/Validation/ChValidation.php | 6 +++--- src/Validation/CzValidation.php | 6 +++--- src/Validation/DeValidation.php | 4 ++-- src/Validation/DkValidation.php | 4 ++-- src/Validation/EsValidation.php | 2 +- src/Validation/FiValidation.php | 6 +++--- src/Validation/FrValidation.php | 2 +- src/Validation/GbValidation.php | 8 ++++---- src/Validation/HrValidation.php | 8 ++++---- src/Validation/IdValidation.php | 8 ++++---- src/Validation/InValidation.php | 6 +++--- src/Validation/ItValidation.php | 6 +++--- src/Validation/JpValidation.php | 6 +++--- src/Validation/LtValidation.php | 2 +- src/Validation/LvValidation.php | 8 ++++---- src/Validation/MxValidation.php | 6 +++--- src/Validation/NlValidation.php | 2 +- src/Validation/NoValidation.php | 2 +- src/Validation/PtValidation.php | 8 ++++---- src/Validation/RoValidation.php | 6 +++--- src/Validation/RsValidation.php | 6 +++--- src/Validation/RuValidation.php | 2 +- src/Validation/SkValidation.php | 8 ++++---- src/Validation/TrValidation.php | 6 +++--- src/Validation/TwValidation.php | 2 +- src/Validation/UaValidation.php | 2 +- src/Validation/UsValidation.php | 2 +- .../TestCase/Validation/FiValidationTest.php | 1 - 38 files changed, 114 insertions(+), 86 deletions(-) create mode 100644 phpstan.neon diff --git a/.travis.yml b/.travis.yml index 6ad997ef..3efa8f18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,12 +4,16 @@ php: - 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: 7.2 env: PREFER_LOWEST=1 @@ -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 c7f65c09..c135e1f1 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ "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/ ", + "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/", 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/src/Plugin.php b/src/Plugin.php index 96ec00f2..76ffd253 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -27,4 +27,23 @@ class Plugin extends BasePlugin * @var string */ protected $name = 'Localized'; + + /** + * @var bool + */ + protected $routesEnabled = false; + + /** + * @var bool + */ + protected $bootstrapEnabled = false; + /** + * @var bool + */ + protected $consoleEnabled = false; + + /** + * @var bool + */ + protected $middlewareEnabled = false; } diff --git a/src/Validation/AtValidation.php b/src/Validation/AtValidation.php index 8913166f..83150696 100644 --- a/src/Validation/AtValidation.php +++ b/src/Validation/AtValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * AtValidation @@ -42,7 +42,7 @@ public static function postal(string $check): bool * Checks a phone number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function phone(string $check): bool @@ -54,7 +54,7 @@ public static function phone(string $check): bool * Checks a country specific identification number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function personId(string $check): bool diff --git a/src/Validation/AuValidation.php b/src/Validation/AuValidation.php index 6f80d2d7..5299a7ab 100644 --- a/src/Validation/AuValidation.php +++ b/src/Validation/AuValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * AuValidation @@ -56,7 +56,7 @@ public static function phone(string $check): bool * Checks an identification number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function personId(string $check): bool diff --git a/src/Validation/BdValidation.php b/src/Validation/BdValidation.php index f44b5f67..035d116a 100644 --- a/src/Validation/BdValidation.php +++ b/src/Validation/BdValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * BdValidation @@ -42,7 +42,7 @@ public static function postal(string $check): bool * Checks a phone number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function phone(string $check): bool @@ -54,7 +54,7 @@ public static function phone(string $check): bool * Checks a country specific identification number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function personId(string $check): bool diff --git a/src/Validation/BeValidation.php b/src/Validation/BeValidation.php index ca47dbbb..83dde499 100644 --- a/src/Validation/BeValidation.php +++ b/src/Validation/BeValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * BeValidation @@ -42,7 +42,7 @@ public static function postal(string $check): bool * Checks a phone number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function phone(string $check): bool diff --git a/src/Validation/BrValidation.php b/src/Validation/BrValidation.php index d8022275..0834a6d8 100644 --- a/src/Validation/BrValidation.php +++ b/src/Validation/BrValidation.php @@ -89,12 +89,12 @@ public static function cpf(string $check): bool $sum = 0; $position = $pos + 1; for ($i = 0; $i <= $pos - 1; $i++, $position--) { - $sum += $check[$i] * $position; + $sum += (int)$check[$i] * $position; } $div = $sum % 11; $check[$pos] = $div < 2 ? 0 : 11 - $div; } - $dvRight = $check[9] * 10 + $check[10]; + $dvRight = (int)$check[9] * 10 + (int)$check[10]; return $dvRight == $dv; } diff --git a/src/Validation/CaValidation.php b/src/Validation/CaValidation.php index c4662375..0acdd4f7 100644 --- a/src/Validation/CaValidation.php +++ b/src/Validation/CaValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * CaValidation @@ -42,7 +42,7 @@ public static function postal(string $check): bool * Checks a phone number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function phone(string $check): bool diff --git a/src/Validation/ChValidation.php b/src/Validation/ChValidation.php index 9fc480a5..65a4328e 100644 --- a/src/Validation/ChValidation.php +++ b/src/Validation/ChValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * ChValidation @@ -44,7 +44,7 @@ public static function postal(string $check): bool * Checks a phone number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function phone(string $check): bool @@ -56,7 +56,7 @@ public static function phone(string $check): bool * Checks a country specific identification number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function personId(string $check): bool diff --git a/src/Validation/CzValidation.php b/src/Validation/CzValidation.php index 5bae1fce..67ea3889 100644 --- a/src/Validation/CzValidation.php +++ b/src/Validation/CzValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * CzValidation @@ -42,7 +42,7 @@ public static function postal(string $check): bool * Checks a phone number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function phone(string $check): bool @@ -54,7 +54,7 @@ public static function phone(string $check): bool * Checks a country specific identification number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function personId(string $check): bool diff --git a/src/Validation/DeValidation.php b/src/Validation/DeValidation.php index 935b8275..f251fca5 100644 --- a/src/Validation/DeValidation.php +++ b/src/Validation/DeValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * DeValidation @@ -90,7 +90,7 @@ public static function dob(string $check): bool * Checks a country specific identification number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function personId(string $check): bool diff --git a/src/Validation/DkValidation.php b/src/Validation/DkValidation.php index 2693a9eb..fcc90de0 100644 --- a/src/Validation/DkValidation.php +++ b/src/Validation/DkValidation.php @@ -40,7 +40,7 @@ public static function personId(string $check): bool * Checks a postal code for Denmark. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success */ public static function postal(string $check): bool @@ -54,7 +54,7 @@ public static function postal(string $check): bool * Checks a phone number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function phone(string $check): bool diff --git a/src/Validation/EsValidation.php b/src/Validation/EsValidation.php index 49d70931..04350516 100644 --- a/src/Validation/EsValidation.php +++ b/src/Validation/EsValidation.php @@ -62,7 +62,7 @@ public static function phone(string $check): bool * @param string $check The value to check. * @return bool Success. */ - public static function personId($check): bool + public static function personId(string $check): bool { $checks = ['dni', 'nie', 'nif']; diff --git a/src/Validation/FiValidation.php b/src/Validation/FiValidation.php index 16c2f066..68a7d0cc 100644 --- a/src/Validation/FiValidation.php +++ b/src/Validation/FiValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * FiValidation @@ -44,7 +44,7 @@ public static function postal(string $check): bool * * @param string $check The value to check. * - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function phone(string $check): bool @@ -59,7 +59,7 @@ public static function phone(string $check): bool * * @return bool Success. */ - public static function personId($check): bool + public static function personId(string $check): bool { $pattern = '/^\d{6}[-+A][0-9A-Z]{4}$/'; if (!(bool)preg_match($pattern, strval($check))) { diff --git a/src/Validation/FrValidation.php b/src/Validation/FrValidation.php index 46d44ba7..0bc9a481 100644 --- a/src/Validation/FrValidation.php +++ b/src/Validation/FrValidation.php @@ -60,7 +60,7 @@ public static function postal(string $check): bool * @param string $check The value to check. * @return bool Success. */ - public static function personId($check): bool + 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)) { diff --git a/src/Validation/GbValidation.php b/src/Validation/GbValidation.php index 5de751a4..2240f27c 100644 --- a/src/Validation/GbValidation.php +++ b/src/Validation/GbValidation.php @@ -15,7 +15,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * GB Localized Validation class. Handles localized validation for The United Kingdom @@ -40,7 +40,7 @@ public static function postal(string $check): bool * Checks a phone number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function phone(string $check): bool @@ -52,10 +52,10 @@ public static function phone(string $check): bool * Checks a country specific identification number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ - public static function personId($check): bool + public static function personId(string $check): bool { throw new NotImplementedException(__d('localized', '%s Not implemented yet.')); } diff --git a/src/Validation/HrValidation.php b/src/Validation/HrValidation.php index 98d7f4af..88ee9486 100644 --- a/src/Validation/HrValidation.php +++ b/src/Validation/HrValidation.php @@ -16,7 +16,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * HrValidation @@ -41,7 +41,7 @@ public static function postal(string $check): bool * Checks a phone number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function phone(string $check): bool @@ -53,10 +53,10 @@ public static function phone(string $check): bool * Checks a country specific identification number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ - public static function personId($check): bool + public static function personId(string $check): bool { throw new NotImplementedException(__d('localized', '%s Not implemented yet.')); } diff --git a/src/Validation/IdValidation.php b/src/Validation/IdValidation.php index 93404743..d0aafd46 100644 --- a/src/Validation/IdValidation.php +++ b/src/Validation/IdValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * IdValidation @@ -55,7 +55,7 @@ public static function mobile(string $check): bool * Checks a phone number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function phone(string $check): bool @@ -67,10 +67,10 @@ public static function phone(string $check): bool * Checks a country specific identification number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ - public static function personId($check): bool + public static function personId(string $check): bool { throw new NotImplementedException(__d('localized', '%s Not implemented yet.')); } diff --git a/src/Validation/InValidation.php b/src/Validation/InValidation.php index 236dd13e..09262074 100644 --- a/src/Validation/InValidation.php +++ b/src/Validation/InValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * InValidation @@ -54,10 +54,10 @@ public static function phone(string $check): bool * Checks an identification number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ - public static function personId($check): bool + public static function personId(string $check): bool { throw new NotImplementedException(__d('localized', '%s Not implemented yet.')); } diff --git a/src/Validation/ItValidation.php b/src/Validation/ItValidation.php index 93725b3b..acb53253 100644 --- a/src/Validation/ItValidation.php +++ b/src/Validation/ItValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * ItValidation @@ -94,10 +94,10 @@ public static function cf(string $check): bool * Checks a country specific identification number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ - public static function personId($check): bool + public static function personId(string $check): bool { throw new NotImplementedException(__d('localized', '%s Not implemented yet.')); } diff --git a/src/Validation/JpValidation.php b/src/Validation/JpValidation.php index 822a0bd8..eec26c2f 100644 --- a/src/Validation/JpValidation.php +++ b/src/Validation/JpValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * JpValidation @@ -146,10 +146,10 @@ public static function zenkaku(string $check): bool * Checks a country specific identification number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ - public static function personId($check): bool + public static function personId(string $check): bool { throw new NotImplementedException(__d('localized', '%s Not implemented yet.')); } diff --git a/src/Validation/LtValidation.php b/src/Validation/LtValidation.php index 5482cc63..36337a3e 100644 --- a/src/Validation/LtValidation.php +++ b/src/Validation/LtValidation.php @@ -53,7 +53,7 @@ public static function postal(string $check): bool * @param string $check The value to check. * @return bool Success. */ - public static function personId($check): bool + public static function personId(string $check): bool { $pattern = '/^([a-z]{2})[\s-]?[\d]{7}$/i'; diff --git a/src/Validation/LvValidation.php b/src/Validation/LvValidation.php index 1ff49138..d6e5d545 100644 --- a/src/Validation/LvValidation.php +++ b/src/Validation/LvValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * LvValidation @@ -30,7 +30,7 @@ class LvValidation extends LocalizedValidation * * @param string $check The value to check. * - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function postal(string $check): bool @@ -43,7 +43,7 @@ public static function postal(string $check): bool * * @param string $check The value to check. * - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function phone(string $check): bool @@ -58,7 +58,7 @@ public static function phone(string $check): bool * * @return bool Success. */ - public static function personId($check): bool + public static function personId(string $check): bool { $check = trim(str_replace('-', '', $check)); diff --git a/src/Validation/MxValidation.php b/src/Validation/MxValidation.php index af6500b9..7230bb2c 100644 --- a/src/Validation/MxValidation.php +++ b/src/Validation/MxValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * MxValidation @@ -55,10 +55,10 @@ public static function postal(string $check): bool * Checks a country specific identification number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ - public static function personId($check): bool + public static function personId(string $check): bool { throw new NotImplementedException(__d('localized', '%s Not implemented yet.')); } diff --git a/src/Validation/NlValidation.php b/src/Validation/NlValidation.php index f384b424..b8c9501d 100644 --- a/src/Validation/NlValidation.php +++ b/src/Validation/NlValidation.php @@ -53,7 +53,7 @@ public static function postal(string $check): bool * @param string $check The value to check. * @return bool Success. */ - public static function personId($check): bool + public static function personId(string $check): bool { $pattern = '/\A\b\d{9}\b\z/i'; diff --git a/src/Validation/NoValidation.php b/src/Validation/NoValidation.php index aaa873e3..05069c6f 100644 --- a/src/Validation/NoValidation.php +++ b/src/Validation/NoValidation.php @@ -73,7 +73,7 @@ public static function postal(string $check): bool * @param string $check The value to check. * @return bool Success. */ - public static function personId($check): bool + public static function personId(string $check): bool { $pattern = '/^(\d{11})|(\d{6} \d{5})$/'; diff --git a/src/Validation/PtValidation.php b/src/Validation/PtValidation.php index 946db29b..6432bb20 100644 --- a/src/Validation/PtValidation.php +++ b/src/Validation/PtValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * PtValidation @@ -42,7 +42,7 @@ public static function postal(string $check): bool * Checks a phone number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function phone(string $check): bool @@ -54,10 +54,10 @@ public static function phone(string $check): bool * Checks a country specific identification number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ - public static function personId($check): bool + public static function personId(string $check): bool { throw new NotImplementedException(__d('localized', '%s Not implemented yet.')); } diff --git a/src/Validation/RoValidation.php b/src/Validation/RoValidation.php index 63992e81..7592137a 100644 --- a/src/Validation/RoValidation.php +++ b/src/Validation/RoValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * RoValidation @@ -42,7 +42,7 @@ public static function postal(string $check): bool * Checks a phone number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function phone(string $check) @@ -54,7 +54,7 @@ public static function phone(string $check) * Checks a country specific identification number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function personId(string $check) diff --git a/src/Validation/RsValidation.php b/src/Validation/RsValidation.php index 201d1de4..48f65a4d 100644 --- a/src/Validation/RsValidation.php +++ b/src/Validation/RsValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * RsValidation @@ -45,7 +45,7 @@ public static function postal(string $check): bool * @return bool Success. * @link http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number */ - public static function personId($check): bool + public static function personId(string $check): bool { if (!preg_match('/^\d{13}$/', $check)) { return false; @@ -115,7 +115,7 @@ public static function jmbg(string $check): bool * Checks a phone number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function phone(string $check): bool diff --git a/src/Validation/RuValidation.php b/src/Validation/RuValidation.php index a37a060a..fe346ff8 100644 --- a/src/Validation/RuValidation.php +++ b/src/Validation/RuValidation.php @@ -130,7 +130,7 @@ public static function vatin(string $check): bool * @param string $check The value to check. * @return bool Success. */ - public static function personId($check): bool + public static function personId(string $check): bool { return static::snils($check); } diff --git a/src/Validation/SkValidation.php b/src/Validation/SkValidation.php index 38ff442b..e2279349 100644 --- a/src/Validation/SkValidation.php +++ b/src/Validation/SkValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * SkValidation @@ -42,7 +42,7 @@ public static function postal(string $check): bool * Checks a phone number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function phone(string $check): bool @@ -54,10 +54,10 @@ public static function phone(string $check): bool * Checks a country specific identification number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ - public static function personId($check): bool + public static function personId(string $check): bool { throw new NotImplementedException(__d('localized', '%s Not implemented yet.')); } diff --git a/src/Validation/TrValidation.php b/src/Validation/TrValidation.php index 50f855f9..ca1405e6 100644 --- a/src/Validation/TrValidation.php +++ b/src/Validation/TrValidation.php @@ -17,7 +17,7 @@ */ namespace Cake\Localized\Validation; -use Cake\Network\Exception\NotImplementedException; +use Cake\Http\Exception\NotImplementedException; /** * TrValidation @@ -44,7 +44,7 @@ public static function postal(string $check): bool * @param string $tckn The value to check. * @return bool Success. */ - public static function personId($tckn): bool + public static function personId(string $tckn): bool { if (strlen($tckn) !== 11) { return false; @@ -73,7 +73,7 @@ public static function personId($tckn): bool * Checks a phone number. * * @param string $check The value to check. - * @throws \Cake\Network\Exception\NotImplementedException Exception + * @throws \Cake\Http\Exception\NotImplementedException Exception * @return bool Success. */ public static function phone(string $check): bool diff --git a/src/Validation/TwValidation.php b/src/Validation/TwValidation.php index bbd39c3e..0af9e87b 100644 --- a/src/Validation/TwValidation.php +++ b/src/Validation/TwValidation.php @@ -55,7 +55,7 @@ public static function postal(string $check): bool * @param string $check The value to check. * @return bool Success. */ - public static function personId($check): bool + public static function personId(string $check): bool { $check = strtoupper($check); if (!preg_match('/^[A-Z][1-2]\d{8}$/', $check)) { diff --git a/src/Validation/UaValidation.php b/src/Validation/UaValidation.php index 4b66aa6a..a1e899ea 100644 --- a/src/Validation/UaValidation.php +++ b/src/Validation/UaValidation.php @@ -89,7 +89,7 @@ public static function idCard(string $check): bool * @return bool Success. * @link https://en.wikipedia.org/wiki/VAT_identification_number#VAT_numbers_of_non-EU_countries */ - public static function personId($check): bool + public static function personId(string $check): bool { $pattern = '/^\d{10}$/'; diff --git a/src/Validation/UsValidation.php b/src/Validation/UsValidation.php index e269e304..a54a73a3 100644 --- a/src/Validation/UsValidation.php +++ b/src/Validation/UsValidation.php @@ -59,7 +59,7 @@ public static function postal(string $check): bool * @param string $check The value to check. * @return bool Success */ - public static function personId($check): bool + public static function personId(string $check): bool { $pattern = '/\A\b\d{3}-\d{2}-\d{4}\b\z/i'; diff --git a/tests/TestCase/Validation/FiValidationTest.php b/tests/TestCase/Validation/FiValidationTest.php index f7966361..3be21fd3 100644 --- a/tests/TestCase/Validation/FiValidationTest.php +++ b/tests/TestCase/Validation/FiValidationTest.php @@ -42,7 +42,6 @@ public function personIdProvider() ['010100+991B', false], ['010100-9856', false], ['010100A929B', false], - [null, false], ['', false], ]; } From 045bb044cfb15b2a355f76126c292a58885751b3 Mon Sep 17 00:00:00 2001 From: mscherer Date: Fri, 3 Apr 2020 00:32:53 +0200 Subject: [PATCH 9/9] No warnings for now. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c135e1f1..72495e3a 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ "@stan", "@psalm" ], - "cs-check": "phpcs -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/", + "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/",