Skip to content

Commit

Permalink
Bugfix missing depdency from Coveralls package (#29)
Browse files Browse the repository at this point in the history
* Bugfix missing depdency from Coveralls package

* elaborate test
  • Loading branch information
Ekman authored Apr 23, 2020
1 parent df028af commit 6d66a5c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"require-dev": {
"phpunit/phpunit": "^6.0||^7.0",
"friendsofphp/php-cs-fixer": "^2.15",
"php-coveralls/php-coveralls": "^2.1"
"php-coveralls/php-coveralls": "^2.1",
"symfony/yaml": "^5.0"
},
"scripts": {
"lint": "php-cs-fixer fix",
Expand Down
5 changes: 3 additions & 2 deletions src/LuhnAlgorithm.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@ public function calcCheckDigit(NumberInterface $number): int
*/
public function calcChecksum(NumberInterface $number): int
{
$nDigits = strlen($number->getNumber());
$num = $number->getNumber();
$nDigits = strlen($num);
// Need to account for check digit
$parity = ($nDigits + 1) % 2;
$checksum = 0;

for ($i = 0; $i < $nDigits; $i++) {
$digit = (int) $number->getNumber()[$i];
$digit = (int) $num[$i];

// Every other digit, starting from the rightmost,
// shall be doubled.
Expand Down
2 changes: 2 additions & 0 deletions tests/LuhnAlgorithmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function provideCalcChecksum_success()
{
return [
"Valid checksum" => [new Number(3199723370002), 50],
"Checksum mod 10 is 0" => [new Number(31997), 30],
];
}

Expand All @@ -112,6 +113,7 @@ public function provideCalcCheckDigit_success()
"Valid number" => [new Number(12345), 5],
"Swedish company organization ID" => [new Number(559114884), 5],
"Swedish organization number" => [new Number(640319261), 7],
"Checksum mod 10 is 0" => [new Number(31997), 0],
];
}
}

0 comments on commit 6d66a5c

Please sign in to comment.