Skip to content

Commit

Permalink
Set up "squizlabs/php_codesniffer"
Browse files Browse the repository at this point in the history
The tool we used to verify whether the code base has the correct coding
standard was removed [1].

This commit will set up one that works best for us and will also make
sure we have fully compliant to PS1 and PSR2.

[1]: ffec95a

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
  • Loading branch information
henriquemoody committed Feb 3, 2019
1 parent 2b86e54 commit b7043b2
Show file tree
Hide file tree
Showing 237 changed files with 390 additions and 280 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,7 +1,8 @@
.php_cs.cache
.couscous/
.phpcs.cache
composer.lock
Makefile
phpcs.xml
phpstan.neon
phpunit.xml
vendor/
4 changes: 4 additions & 0 deletions .travis.yml
Expand Up @@ -34,6 +34,10 @@ script:
if [[ "${TRAVIS_PHP_VERSION}" == "7.2" ]]; then
vendor/bin/docheader check library tests
fi
- |
if [[ "${TRAVIS_PHP_VERSION}" == "7.2" ]]; then
vendor/bin/phpcs
fi
- |
if [[ "${TRAVIS_PHP_VERSION}" == "7.2" ]]; then
vendor/bin/phpstan analyze
Expand Down
6 changes: 6 additions & 0 deletions composer.json
Expand Up @@ -11,6 +11,9 @@
"homepage": "https://github.com/Respect/Validation/graphs/contributors"
}
],
"config": {
"sort-packages": true
},
"require": {
"php": ">=7.1",
"respect/stringifier": "^0.2.0",
Expand All @@ -22,6 +25,7 @@
"mikey179/vfsStream": "^1.6",
"phpstan/phpstan": "^0.10.3",
"phpunit/phpunit": "^7.3",
"squizlabs/php_codesniffer": "^3.4",
"symfony/validator": "^3.0||^4.0",
"zendframework/zend-validator": "^2.0"
},
Expand Down Expand Up @@ -51,12 +55,14 @@
},
"scripts": {
"docheader": "vendor/bin/docheader check library/ tests/",
"phpcs": "vendor/bin/phpcs",
"phpstan": "vendor/bin/phpstan analyze",
"phpunit": "vendor/bin/phpunit",
"phpunit-integration": "vendor/bin/phpunit --testsuite=integration",
"phpunit-unit": "vendor/bin/phpunit --testsuite=unit",
"qa": [
"@docheader",
"@phpcs",
"@phpstan",
"@phpunit"
]
Expand Down
18 changes: 14 additions & 4 deletions library/Factory.php
Expand Up @@ -78,8 +78,14 @@ public function __construct(
array $exceptionsNamespaces,
callable $translator
) {
$this->rulesNamespaces = $this->filterNamespaces($rulesNamespaces, self::DEFAULT_RULES_NAMESPACES);
$this->exceptionsNamespaces = $this->filterNamespaces($exceptionsNamespaces, self::DEFAULT_EXCEPTIONS_NAMESPACES);
$this->rulesNamespaces = $this->filterNamespaces(
$rulesNamespaces,
self::DEFAULT_RULES_NAMESPACES
);
$this->exceptionsNamespaces = $this->filterNamespaces(
$exceptionsNamespaces,
self::DEFAULT_EXCEPTIONS_NAMESPACES
);
$this->translator = $translator;
}

Expand Down Expand Up @@ -233,8 +239,12 @@ private function filterNamespaces(array $namespaces, array $defaultNamespaces):
*
* @return ValidationException
*/
private function createValidationException(string $exceptionName, string $id, $input, array $params): ValidationException
{
private function createValidationException(
string $exceptionName,
string $id,
$input,
array $params
): ValidationException {
/* @var ValidationException $exception */
$exception = $this->createReflectionClass($exceptionName, ValidationException::class)
->newInstance($input, $id, $params, $this->translator);
Expand Down
4 changes: 3 additions & 1 deletion library/Rules/ArrayVal.php
Expand Up @@ -17,7 +17,9 @@
use SimpleXMLElement;

/**
* Validates if the input is an array or if the input can be used as an array (instance of `ArrayAccess` or `SimpleXMLElement`).
* Validates if the input is an array or if the input can be used as an array.
*
* Instance of `ArrayAccess` or `SimpleXMLElement` are also considered as valid.
*
* @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
* @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
Expand Down
10 changes: 8 additions & 2 deletions library/Rules/Cnpj.php
Expand Up @@ -50,13 +50,19 @@ public function validate($input): bool
return false;
}

for ($i = 0, $n = 0; $i < 12; $n += $cleanInput[$i] * $b[++$i]);
$n = 0;
for ($i = 0; $i < 12; ++$i) {
$n += $cleanInput[$i] * $b[$i+1];
}

if ($cleanInput[12] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
return false;
}

for ($i = 0, $n = 0; $i <= 12; $n += $cleanInput[$i] * $b[$i++]);
$n = 0;
for ($i = 0; $i <= 12; ++$i) {
$n += $cleanInput[$i] * $b[$i];
}

if ($cleanInput[13] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
return false;
Expand Down
10 changes: 8 additions & 2 deletions library/Rules/Cpf.php
Expand Up @@ -41,13 +41,19 @@ public function validate($input): bool
return false;
}

for ($s = 10, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--);
$n = 0;
for ($s = 10, $i = 0; $s >= 2; ++$i, --$s) {
$n += $c[$i] * $s;
}

if ($c[9] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
return false;
}

for ($s = 11, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--);
$n = 0;
for ($s = 11, $i = 0; $s >= 2; ++$i, --$s) {
$n += $c[$i] * $s;
}

if ($c[10] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Locale/AdSubdivisionCode.php
Expand Up @@ -39,6 +39,6 @@ protected function getDataSource(): array
'06', // Sant Julia de Lòria
'07', // Andorra la Vella
'08', // Escaldes-Engordany
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/AeSubdivisionCode.php
Expand Up @@ -39,6 +39,6 @@ protected function getDataSource(): array
'RK', // R'as al Khaymah
'SH', // Ash Shariqah
'UQ', // Umm al Qaywayn
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/AfSubdivisionCode.php
Expand Up @@ -66,6 +66,6 @@ protected function getDataSource(): array
'URU', // Uruzgān province
'WAR', // Wardak province
'ZAB', // Zabol province
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/AgSubdivisionCode.php
Expand Up @@ -40,6 +40,6 @@ protected function getDataSource(): array
'08', // Saint Philip
'10', // Barbuda
'11', // Redonda
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/AlSubdivisionCode.php
Expand Up @@ -80,6 +80,6 @@ protected function getDataSource(): array
'TP', // Tropoje
'TR', // Tirane
'VL', // Vlore
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/AmSubdivisionCode.php
Expand Up @@ -43,6 +43,6 @@ protected function getDataSource(): array
'SU', // Syunik'
'TV', // Tavush
'VD', // Vayots' Dzor
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/AoSubdivisionCode.php
Expand Up @@ -50,6 +50,6 @@ protected function getDataSource(): array
'NAM', // Namibe
'UIG', // Uige
'ZAI', // Zaire
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/ArSubdivisionCode.php
Expand Up @@ -56,6 +56,6 @@ protected function getDataSource(): array
'X', // Cordoba
'Y', // Jujuy
'Z', // Santa Cruz
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/AsSubdivisionCode.php
Expand Up @@ -37,6 +37,6 @@ protected function getDataSource(): array
'R', // Rose Island
'S', // Swains Island
'W', // Western
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/AtSubdivisionCode.php
Expand Up @@ -41,6 +41,6 @@ protected function getDataSource(): array
'7', // Tirol
'8', // Vorarlberg
'9', // Wien
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/AuSubdivisionCode.php
Expand Up @@ -40,6 +40,6 @@ protected function getDataSource(): array
'TAS', // Tasmania
'VIC', // Victoria
'WA', // Western Australia
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/AzSubdivisionCode.php
Expand Up @@ -110,6 +110,6 @@ protected function getDataSource(): array
'ZAN', // Zangilan
'ZAQ', // Zaqatala
'ZAR', // Zardab
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BaSubdivisionCode.php
Expand Up @@ -45,6 +45,6 @@ protected function getDataSource(): array
'BIH', // Federacija Bosna i Hercegovina
'BRC', // Brcko District
'SRP', // Republika Srpska
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BbSubdivisionCode.php
Expand Up @@ -43,6 +43,6 @@ protected function getDataSource(): array
'09', // Saint Peter
'10', // Saint Philip
'11', // Saint Thomas
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BdSubdivisionCode.php
Expand Up @@ -104,6 +104,6 @@ protected function getDataSource(): array
'F', // Rangpur
'G', // Sylhet
'H', // Mymensingh Division
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BeSubdivisionCode.php
Expand Up @@ -45,6 +45,6 @@ protected function getDataSource(): array
'WLG', // Liege
'WLX', // Luxembourg
'WNA', // Namur
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BfSubdivisionCode.php
Expand Up @@ -90,6 +90,6 @@ protected function getDataSource(): array
'ZIR', // Ziro
'ZON', // Zondoma
'ZOU', // Zoundweogo
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BgSubdivisionCode.php
Expand Up @@ -60,6 +60,6 @@ protected function getDataSource(): array
'26', // Khaskovo
'27', // Shumen
'28', // Yambol
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BhSubdivisionCode.php
Expand Up @@ -36,6 +36,6 @@ protected function getDataSource(): array
'14', // Southern
'15', // Muharraq
'17', // Northern
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BiSubdivisionCode.php
Expand Up @@ -50,6 +50,6 @@ protected function getDataSource(): array
'RM', // Rumonge
'RT', // Rutana
'RY', // Ruyigi
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BjSubdivisionCode.php
Expand Up @@ -44,6 +44,6 @@ protected function getDataSource(): array
'OU', // Oueme
'PL', // Plateau
'ZO', // Zou
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BmSubdivisionCode.php
Expand Up @@ -43,6 +43,6 @@ protected function getDataSource(): array
'SH', // Southampton
'SM', // Smith's
'WA', // Warwick
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BnSubdivisionCode.php
Expand Up @@ -36,6 +36,6 @@ protected function getDataSource(): array
'BM', // Brunei and Muara
'TE', // Temburong
'TU', // Tutong
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BoSubdivisionCode.php
Expand Up @@ -41,6 +41,6 @@ protected function getDataSource(): array
'P', // Departmento Potosi
'S', // Departmento Santa Cruz
'T', // Departmento Tarija
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BqSubdivisionCode.php
Expand Up @@ -35,6 +35,6 @@ protected function getDataSource(): array
'BO', // Bonaire
'SA', // Saba
'SE', // Sint Eustatius
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BrSubdivisionCode.php
Expand Up @@ -59,6 +59,6 @@ protected function getDataSource(): array
'SE', // Sergipe
'SP', // Sao Paulo
'TO', // Tocantins
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BsSubdivisionCode.php
Expand Up @@ -64,6 +64,6 @@ protected function getDataSource(): array
'SS', // San Salvador
'SW', // Spanish Wells
'WG', // West Grand Bahama
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BtSubdivisionCode.php
Expand Up @@ -52,6 +52,6 @@ protected function getDataSource(): array
'45', // Samdrup Jongkhar
'GA', // Gasa
'TY', // Trashi Yangste
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BwSubdivisionCode.php
Expand Up @@ -48,6 +48,6 @@ protected function getDataSource(): array
'SO', // Southern
'SP', // Selibe Phikwe
'ST', // Sowa Town
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BySubdivisionCode.php
Expand Up @@ -39,6 +39,6 @@ protected function getDataSource(): array
'MA', // Mahilyow voblast
'MI', // Minsk voblast
'VI', // Vitsebsk voblast
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/BzSubdivisionCode.php
Expand Up @@ -38,6 +38,6 @@ protected function getDataSource(): array
'OW', // Orange Walk District
'SC', // Stann Creek District
'TOL', // Toledo District
];
];
}
}
2 changes: 1 addition & 1 deletion library/Rules/Locale/CaSubdivisionCode.php
Expand Up @@ -45,6 +45,6 @@ protected function getDataSource(): array
'QC', // Quebec
'SK', // Saskatchewan
'YT', // Yukon Territory
];
];
}
}

0 comments on commit b7043b2

Please sign in to comment.