Skip to content

Bugfix missing depdency from Coveralls package #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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],
];
}
}