Skip to content

Update copyright notice #17

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 5 commits into from
Nov 23, 2018
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
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