Skip to content

Commit

Permalink
Merge pull request #1 from melhorenvio/hotfix/php7.4-compatibility
Browse files Browse the repository at this point in the history
Hotfix/php7.4 compatibility
  • Loading branch information
ldseinhardt authored Mar 15, 2021
2 parents b3a5c3d + ebd9ec7 commit 34ec1fa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
],
"require": {
"php": "^7.1",
"illuminate/support": "5.6.*|5.7.*"
"illuminate/support": "5.6.*|5.7.*",
"ext-mbstring": "*"
},
"require-dev": {
"orchestra/testbench": "3.8.*",
Expand Down
8 changes: 4 additions & 4 deletions src/Rules/Cnpj.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ public function passes($attribute, $value): bool
}

for ($i = 0, $j = 5, $sum = 0; $i < 12; $i++) {
$sum += $value{$i} * $j;
$sum += $value[$i] * $j;
$j = ($j == 2) ? 9 : $j - 1;
}

$mod = $sum % 11;

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

for ($i = 0, $j = 6, $sum = 0; $i < 13; $i++) {
$sum += $value{$i} * $j;
$sum += $value[$i] * $j;
$j = ($j == 2) ? 9 : $j - 1;
}

$mod = $sum % 11;

return $value{13} == ($mod < 2 ? 0 : 11 - $mod);
return $value[13] == ($mod < 2 ? 0 : 11 - $mod);
}

public function message(): string
Expand Down
8 changes: 4 additions & 4 deletions src/Rules/Cpf.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ public function passes($attribute, $value): bool
}

for ($i = 0, $j = 10, $sum = 0; $i < 9; $i++, $j--) {
$sum += $value{$i} * $j;
$sum += $value[$i] * $j;
}

$mod = $sum % 11;

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

for ($i = 0, $j = 11, $sum = 0; $i < 10; $i++, $j--) {
$sum += $value{$i} * $j;
$sum += $value[$i] * $j;
}

$mod = $sum % 11;

return $value{10} == ($mod < 2 ? 0 : 11 - $mod);
return $value[10] == ($mod < 2 ? 0 : 11 - $mod);
}

public function message(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Nfe.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function passes($attribute, $value): bool
$weight = 2;

for ($i = mb_strlen($value) - 2; $i >= 0; $i--) {
$sum += $value{$i} * $weight;
$sum += $value[$i] * $weight;
$weight = $weight < 9 ? $weight + 1 : 2;
}

Expand Down

0 comments on commit 34ec1fa

Please sign in to comment.