Skip to content

Commit a7d281e

Browse files
authored
Update copyright notice (#17)
* Remove unnesecary code * Ignore private constructor in code coverage * Fix tests * Fix tests * Update copyright notice
1 parent 9ba100f commit a7d281e

9 files changed

+19
-20
lines changed

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 Niklas Ekman
3+
Copyright (c) 2018 Niklas Ekman
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

src/Contract/LuhnAlgorithmInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2014 Niklas Ekman
6+
* Copyright (c) 2018 Niklas Ekman
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy of
99
* this software and associated documentation files (the "Software"), to deal in

src/Contract/NumberInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2014 Niklas Ekman
6+
* Copyright (c) 2018 Niklas Ekman
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy of
99
* this software and associated documentation files (the "Software"), to deal in

src/LuhnAlgorithm.php

+8-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2014 Niklas Ekman
6+
* Copyright (c) 2018 Niklas Ekman
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy of
99
* this software and associated documentation files (the "Software"), to deal in
@@ -44,11 +44,9 @@ public function isValid(NumberInterface $number): bool
4444
throw new \InvalidArgumentException("Check digit is null.");
4545
}
4646

47-
$checksum = $this->calcChecksum($number);
48-
$sum = $checksum + $number->getCheckDigit();
47+
$checksum = $this->calcChecksum($number) + $number->getCheckDigit();
4948

50-
// If the checksum is divisible by 10 it is valid.
51-
return ($sum % 10) === 0;
49+
return ($checksum % 10) === 0;
5250
}
5351

5452
/**
@@ -61,7 +59,6 @@ public function calcCheckDigit(NumberInterface $number): int
6159
// Get the last digit of the checksum.
6260
$checkDigit = $checksum % 10;
6361

64-
// If the check digit is not 0, then subtract the value from 10.
6562
return $checkDigit === 0
6663
? $checkDigit
6764
: 10 - $checkDigit;
@@ -72,14 +69,13 @@ public function calcCheckDigit(NumberInterface $number): int
7269
*/
7370
public function calcChecksum(NumberInterface $number): int
7471
{
75-
$number = (string) $number->getNumber();
76-
// Need to account for the check digit.
77-
$nDigits = strlen($number) + 1;
78-
$parity = $nDigits % 2;
72+
$nDigits = strlen($number->getNumber());
73+
// Need to account for check digit
74+
$parity = ($nDigits + 1) % 2;
7975
$checksum = 0;
8076

81-
for ($i = 0; $i < $nDigits - 1; $i++) {
82-
$digit = (int) $number[$i];
77+
for ($i = 0; $i < $nDigits; $i++) {
78+
$digit = (int) $number->getNumber()[$i];
8379

8480
// Every other digit, starting from the rightmost,
8581
// shall be doubled.

src/LuhnAlgorithmFactory.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2014 Niklas Ekman
6+
* Copyright (c) 2018 Niklas Ekman
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy of
99
* this software and associated documentation files (the "Software"), to deal in
@@ -34,6 +34,9 @@
3434
*/
3535
class LuhnAlgorithmFactory
3636
{
37+
/**
38+
* @codeCoverageIgnore
39+
*/
3740
private function __construct()
3841
{
3942
// Only static methods.

src/Number.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2014 Niklas Ekman
6+
* Copyright (c) 2018 Niklas Ekman
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy of
99
* this software and associated documentation files (the "Software"), to deal in

tests/LuhnAlgorithmFactoryTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2014 Niklas Ekman
6+
* Copyright (c) 2018 Niklas Ekman
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy of
99
* this software and associated documentation files (the "Software"), to deal in

tests/LuhnAlgorithmTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2014 Niklas Ekman
6+
* Copyright (c) 2018 Niklas Ekman
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy of
99
* this software and associated documentation files (the "Software"), to deal in

tests/NumberTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2014 Niklas Ekman
6+
* Copyright (c) 2018 Niklas Ekman
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy of
99
* this software and associated documentation files (the "Software"), to deal in

0 commit comments

Comments
 (0)