Skip to content

Commit

Permalink
Merge pull request #9 from webdevium/patch-1
Browse files Browse the repository at this point in the history
Two little improvements
  • Loading branch information
vpratfr authored Oct 26, 2020
2 parents e7e7050 + dca1846 commit c4b743d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Luhn/Algorithm/LuhnAlgorithm.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public function computeCheckDigit(string $input): int
public function computeCheckSum(string $input): int
{
// Need to account for the check digit.
$nDigits = \strlen($input) + 1;
$parity = $nDigits % 2;
$nDigits = \strlen($input);
$parity = ($nDigits + 1) % 2;
$checksum = 0;

for ($i = 0; $i < $nDigits - 1; ++$i)
for ($i = 0; $i < $nDigits; ++$i)
{
$digit = (int)$input[$i];

Expand Down Expand Up @@ -68,10 +68,12 @@ protected function cleanAndSplitInput(string $input): array
if ($inputLength === 0) {
throw new InvalidArgumentException;
}


$inputLength--;

return [
\substr($input, 0, $inputLength - 1),
(int)$input[$inputLength - 1],
\substr($input, 0, $inputLength),
(int)$input[$inputLength],
];
}
}

0 comments on commit c4b743d

Please sign in to comment.