Skip to content

Commit

Permalink
melhorias para cobrir PSR-12
Browse files Browse the repository at this point in the history
  • Loading branch information
geekcom committed Jan 16, 2020
1 parent f934363 commit 9477030
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"phpcbf" : "phpcbf --standard=PSR12 -n src",
"unit": "phpunit --coverage-clover ./tests/log/clover.xml --colors=always",
"unit-html": "php -d phar.readonly=0 vendor/bin/phpunit --coverage-html ./tests/log/ --colors=always",
"phpstan": "phpstan analyse src --level 8",
"phpstan": "phpstan analyse src --level 0",
"test": [
"@phpcs",
"@unit",
Expand Down
7 changes: 3 additions & 4 deletions src/validator-docs/Rules/Certidao.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public function validateCertidao($attribute, $value): bool

$dv1 = $this->somaPonderadaCertidao($num) % 11;
$dv1 = $dv1 > 9 ? 1 : $dv1;
$dv2 = $this->somaPonderadaCertidao($num.$dv1) % 11;
$dv2 = $this->somaPonderadaCertidao($num . $dv1) % 11;
$dv2 = $dv2 > 9 ? 1 : $dv2;

// Compara o dv recebido com os dois numeros calculados
if ($dv === $dv1.$dv2) {
if ($dv === $dv1 . $dv2) {
return true;
}

Expand All @@ -47,7 +47,6 @@ private function somaPonderadaCertidao($value): int
$multiplicador = 32 - mb_strlen($value);

for ($i = 0; $i < mb_strlen($value); $i++) {

$soma += $value[$i] * $multiplicador;

$multiplicador += 1;
Expand All @@ -56,4 +55,4 @@ private function somaPonderadaCertidao($value): int

return $soma;
}
}
}
6 changes: 3 additions & 3 deletions src/validator-docs/Rules/Cnh.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function validateCnh($attribute, $value): bool
$dv1 = 11 - $resto;
}

$parcial = $dv1.$parcial;
$parcial = $dv1 . $parcial;

for ($i = 0, $j = 2, $s = 0; $i < mb_strlen($parcial); $i++, $j++) {
$s += (int) $parcial[$i] * $j;
Expand All @@ -51,6 +51,6 @@ public function validateCnh($attribute, $value): bool
$dv2 = 11 - $resto;
}

return $dv1.$dv2 == substr($value, -2);
return $dv1 . $dv2 == substr($value, -2);
}
}
}
12 changes: 9 additions & 3 deletions src/validator-docs/Rules/Cnpj.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,24 @@ public function validateCnpj($attribute, $value): bool

$b = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];

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

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

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

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

return true;
}
}
}
2 changes: 1 addition & 1 deletion src/validator-docs/Rules/Cns.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ private function somaPonderadaCns($value): int

return $soma;
}
}
}
12 changes: 9 additions & 3 deletions src/validator-docs/Rules/Cpf.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@ public function validateCpf($attribute, $value): bool
return false;
}

for ($s = 10, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--);
for (
$s = 10, $n = 0, $i = 0; $s >= 2; $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--);
for (
$s = 11, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--
) {
}

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

return true;
}
}
}
2 changes: 1 addition & 1 deletion src/validator-docs/Rules/Nis.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ public function validateNis($attribute, $value): bool

return ($nis[10] == (((10 * $d) % 11) % 10));
}
}
}
2 changes: 1 addition & 1 deletion src/validator-docs/Rules/Sanitization.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public function sanitize($value): string
{
return preg_replace('/[^\d]/', '', $value);
}
}
}
8 changes: 5 additions & 3 deletions src/validator-docs/Rules/TituloEleitoral.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ public function validateTituloEleitor($attribute, $value): bool

$uf = substr($input, -4, 2);

if (((mb_strlen($input) < 5) || (mb_strlen($input) > 13)) ||
if (
((mb_strlen($input) < 5) || (mb_strlen($input) > 13)) ||
(str_repeat($input[1], mb_strlen($input)) == $input) ||
($uf < 1 || $uf > 28)) {
($uf < 1 || $uf > 28)
) {
return false;
}

Expand Down Expand Up @@ -62,4 +64,4 @@ public function validateTituloEleitor($attribute, $value): bool

return true;
}
}
}
2 changes: 1 addition & 1 deletion src/validator-docs/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ protected function validateCertidao($attribute, $value): bool

return $certidao->validateCertidao($attribute, $value);
}
}
}
2 changes: 1 addition & 1 deletion src/validator-docs/ValidatorProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ public function provides()
{
return [];
}
}
}

0 comments on commit 9477030

Please sign in to comment.