From a7d281ed0186aabcff719422ba5265ef21b5a34e Mon Sep 17 00:00:00 2001 From: Niklas Ekman Date: Fri, 23 Nov 2018 09:07:42 +0100 Subject: [PATCH] Update copyright notice (#17) * Remove unnesecary code * Ignore private constructor in code coverage * Fix tests * Fix tests * Update copyright notice --- LICENSE.md | 2 +- src/Contract/LuhnAlgorithmInterface.php | 2 +- src/Contract/NumberInterface.php | 2 +- src/LuhnAlgorithm.php | 20 ++++++++------------ src/LuhnAlgorithmFactory.php | 5 ++++- src/Number.php | 2 +- tests/LuhnAlgorithmFactoryTest.php | 2 +- tests/LuhnAlgorithmTest.php | 2 +- tests/NumberTest.php | 2 +- 9 files changed, 19 insertions(+), 20 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 8a0bf0d..7e3b91a 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 Niklas Ekman +Copyright (c) 2018 Niklas Ekman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/src/Contract/LuhnAlgorithmInterface.php b/src/Contract/LuhnAlgorithmInterface.php index 0b490d0..fba1ce2 100644 --- a/src/Contract/LuhnAlgorithmInterface.php +++ b/src/Contract/LuhnAlgorithmInterface.php @@ -3,7 +3,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2014 Niklas Ekman + * Copyright (c) 2018 Niklas Ekman * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/src/Contract/NumberInterface.php b/src/Contract/NumberInterface.php index c9e7a99..446d6a5 100644 --- a/src/Contract/NumberInterface.php +++ b/src/Contract/NumberInterface.php @@ -3,7 +3,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2014 Niklas Ekman + * Copyright (c) 2018 Niklas Ekman * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/src/LuhnAlgorithm.php b/src/LuhnAlgorithm.php index c0abdb3..c75a6b9 100644 --- a/src/LuhnAlgorithm.php +++ b/src/LuhnAlgorithm.php @@ -3,7 +3,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2014 Niklas Ekman + * Copyright (c) 2018 Niklas Ekman * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -44,11 +44,9 @@ public function isValid(NumberInterface $number): bool throw new \InvalidArgumentException("Check digit is null."); } - $checksum = $this->calcChecksum($number); - $sum = $checksum + $number->getCheckDigit(); + $checksum = $this->calcChecksum($number) + $number->getCheckDigit(); - // If the checksum is divisible by 10 it is valid. - return ($sum % 10) === 0; + return ($checksum % 10) === 0; } /** @@ -61,7 +59,6 @@ public function calcCheckDigit(NumberInterface $number): int // Get the last digit of the checksum. $checkDigit = $checksum % 10; - // If the check digit is not 0, then subtract the value from 10. return $checkDigit === 0 ? $checkDigit : 10 - $checkDigit; @@ -72,14 +69,13 @@ public function calcCheckDigit(NumberInterface $number): int */ public function calcChecksum(NumberInterface $number): int { - $number = (string) $number->getNumber(); - // Need to account for the check digit. - $nDigits = strlen($number) + 1; - $parity = $nDigits % 2; + $nDigits = strlen($number->getNumber()); + // Need to account for check digit + $parity = ($nDigits + 1) % 2; $checksum = 0; - for ($i = 0; $i < $nDigits - 1; $i++) { - $digit = (int) $number[$i]; + for ($i = 0; $i < $nDigits; $i++) { + $digit = (int) $number->getNumber()[$i]; // Every other digit, starting from the rightmost, // shall be doubled. diff --git a/src/LuhnAlgorithmFactory.php b/src/LuhnAlgorithmFactory.php index 1b791b9..c186d15 100644 --- a/src/LuhnAlgorithmFactory.php +++ b/src/LuhnAlgorithmFactory.php @@ -3,7 +3,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2014 Niklas Ekman + * Copyright (c) 2018 Niklas Ekman * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -34,6 +34,9 @@ */ class LuhnAlgorithmFactory { + /** + * @codeCoverageIgnore + */ private function __construct() { // Only static methods. diff --git a/src/Number.php b/src/Number.php index 979191b..a343e33 100644 --- a/src/Number.php +++ b/src/Number.php @@ -3,7 +3,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2014 Niklas Ekman + * Copyright (c) 2018 Niklas Ekman * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/tests/LuhnAlgorithmFactoryTest.php b/tests/LuhnAlgorithmFactoryTest.php index f887f3e..09dc8a3 100644 --- a/tests/LuhnAlgorithmFactoryTest.php +++ b/tests/LuhnAlgorithmFactoryTest.php @@ -3,7 +3,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2014 Niklas Ekman + * Copyright (c) 2018 Niklas Ekman * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/tests/LuhnAlgorithmTest.php b/tests/LuhnAlgorithmTest.php index dc5385a..8b0db14 100644 --- a/tests/LuhnAlgorithmTest.php +++ b/tests/LuhnAlgorithmTest.php @@ -3,7 +3,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2014 Niklas Ekman + * Copyright (c) 2018 Niklas Ekman * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/tests/NumberTest.php b/tests/NumberTest.php index 3dde9b5..ff215fe 100644 --- a/tests/NumberTest.php +++ b/tests/NumberTest.php @@ -3,7 +3,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2014 Niklas Ekman + * Copyright (c) 2018 Niklas Ekman * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in