Skip to content

Commit

Permalink
Update copyright notice (#17)
Browse files Browse the repository at this point in the history
* Remove unnesecary code

* Ignore private constructor in code coverage

* Fix tests

* Fix tests

* Update copyright notice
  • Loading branch information
Ekman authored Nov 23, 2018
1 parent 9ba100f commit a7d281e
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Contract/LuhnAlgorithmInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Contract/NumberInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 8 additions & 12 deletions src/LuhnAlgorithm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
Expand All @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion src/LuhnAlgorithmFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -34,6 +34,9 @@
*/
class LuhnAlgorithmFactory
{
/**
* @codeCoverageIgnore
*/
private function __construct()
{
// Only static methods.
Expand Down
2 changes: 1 addition & 1 deletion src/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/LuhnAlgorithmFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/LuhnAlgorithmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/NumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a7d281e

Please sign in to comment.