Skip to content

Commit 8ee8fef

Browse files
authored
Update to PHP 8 (#32)
1 parent 6da2145 commit 8ee8fef

20 files changed

+631
-417
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ index.php
22
nbproject/
33
.idea/
44
.php_cs.cache
5+
.phpunit.result.cache
56

67
# Eclipse
78
.buildpath

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
language: php
22

33
php:
4-
- 7.0
5-
- 7.1
6-
- 7.2
7-
- 7.3
84
- 7.4
5+
- 8.0
96
- nightly
107

118
matrix:

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ composer require nekman/luhn-algorithm
1616
## Usage
1717

1818
In order to instantiate a new instance of the library, use the factory:
19-
19+
2020
```php
2121
use Nekman\LuhnAlgorithm\LuhnAlgorithmFactory;
22-
22+
2323
$luhn = LuhnAlgorithmFactory::create();
2424
```
2525

2626
You can find [the library facade in the `LuhnAlgorithmInterface.php` file](src/Contract/LuhnAlgorithmInterface.php).
2727

2828
[The `Number` class](src/Number.php) is a container class that holds the actual number and the check digit. It does no validation nor does it calculate the check digit. It exists to clearly separate the number from the check digit and to define when the check digit exists or not. To simplify the process of validating a number you can use the named constructor `Number::fromString()` like this:
29-
29+
3030
```php
3131
use Nekman\LuhnAlgorithm\Number;
3232

@@ -49,3 +49,7 @@ $checksum = $luhn->calcChecksum($number);
4949

5050
$checkDigit = $luhn->calcCheckDigit($number);
5151
```
52+
53+
## Changelog
54+
55+
For a complete list of changes, and how to migrate between major versions, see [releases page](https://github.com/Ekman/luhn-algorithm/releases).

composer.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,23 @@
2525
"autoload": {
2626
"psr-4": {
2727
"Nekman\\LuhnAlgorithm\\": "src"
28-
}
28+
},
29+
"files": [
30+
"src/functions.php"
31+
]
2932
},
3033
"autoload-dev": {
3134
"psr-4": {
3235
"Nekman\\LuhnAlgorithm\\Test\\": "tests"
3336
}
3437
},
3538
"require": {
36-
"php": "^7.0"
39+
"php": "^7.4||^8.0"
3740
},
3841
"require-dev": {
39-
"phpunit/phpunit": "^6.0||^7.0",
42+
"phpunit/phpunit": "^9.0",
4043
"friendsofphp/php-cs-fixer": "^2.15",
41-
"php-coveralls/php-coveralls": "^2.1",
42-
"symfony/yaml": "^5.0"
44+
"php-coveralls/php-coveralls": "^2.1"
4345
},
4446
"scripts": {
4547
"lint": "php-cs-fixer fix",

coverage/clover.xml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<coverage generated="1610217580">
3+
<project timestamp="1610217580">
4+
<file name="C:\Users\Niklas Ekman\MyStuff\workspaces\luhn-algorithm\src\Contract\LuhnAlgorithmExceptionInterface.php">
5+
<metrics loc="37" ncloc="12" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
6+
</file>
7+
<file name="C:\Users\Niklas Ekman\MyStuff\workspaces\luhn-algorithm\src\Contract\LuhnAlgorithmInterface.php">
8+
<metrics loc="67" ncloc="17" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
9+
</file>
10+
<file name="C:\Users\Niklas Ekman\MyStuff\workspaces\luhn-algorithm\src\Contract\NumberInterface.php">
11+
<metrics loc="48" ncloc="13" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
12+
</file>
13+
<package name="Nekman\LuhnAlgorithm\Exceptions">
14+
<file name="C:\Users\Niklas Ekman\MyStuff\workspaces\luhn-algorithm\src\Exceptions\ArgumentIsNotNumericException.php">
15+
<class name="Nekman\LuhnAlgorithm\Exceptions\ArgumentIsNotNumericException" namespace="Nekman\LuhnAlgorithm\Exceptions">
16+
<metrics complexity="1" methods="1" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="2" coveredstatements="2" elements="3" coveredelements="3"/>
17+
</class>
18+
<line num="38" type="method" name="__construct" visibility="public" complexity="1" crap="1" count="8"/>
19+
<line num="40" type="stmt" count="8"/>
20+
<line num="41" type="stmt" count="8"/>
21+
<metrics loc="42" ncloc="17" classes="1" methods="1" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="2" coveredstatements="2" elements="3" coveredelements="3"/>
22+
</file>
23+
<file name="C:\Users\Niklas Ekman\MyStuff\workspaces\luhn-algorithm\src\Exceptions\MissingCheckDigitException.php">
24+
<class name="Nekman\LuhnAlgorithm\Exceptions\MissingCheckDigitException" namespace="Nekman\LuhnAlgorithm\Exceptions">
25+
<metrics complexity="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
26+
</class>
27+
<metrics loc="37" ncloc="12" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
28+
</file>
29+
</package>
30+
<package name="Nekman\LuhnAlgorithm">
31+
<file name="C:\Users\Niklas Ekman\MyStuff\workspaces\luhn-algorithm\src\LuhnAlgorithm.php">
32+
<class name="Nekman\LuhnAlgorithm\LuhnAlgorithm" namespace="Nekman\LuhnAlgorithm">
33+
<metrics complexity="9" methods="4" coveredmethods="4" conditionals="0" coveredconditionals="0" statements="22" coveredstatements="22" elements="26" coveredelements="26"/>
34+
</class>
35+
<line num="44" type="method" name="__construct" visibility="public" complexity="1" crap="1" count="16"/>
36+
<line num="46" type="stmt" count="16"/>
37+
<line num="51" type="method" name="isValid" visibility="public" complexity="2" crap="2" count="9"/>
38+
<line num="53" type="stmt" count="9"/>
39+
<line num="54" type="stmt" count="3"/>
40+
<line num="57" type="stmt" count="6"/>
41+
<line num="59" type="stmt" count="6"/>
42+
<line num="65" type="method" name="calcChecksum" visibility="public" complexity="4" crap="4" count="12"/>
43+
<line num="67" type="stmt" count="12"/>
44+
<line num="68" type="stmt" count="12"/>
45+
<line num="70" type="stmt" count="12"/>
46+
<line num="71" type="stmt" count="12"/>
47+
<line num="73" type="stmt" count="12"/>
48+
<line num="74" type="stmt" count="12"/>
49+
<line num="78" type="stmt" count="12"/>
50+
<line num="79" type="stmt" count="12"/>
51+
<line num="81" type="stmt" count="12"/>
52+
<line num="82" type="stmt" count="11"/>
53+
<line num="86" type="stmt" count="12"/>
54+
<line num="89" type="stmt" count="12"/>
55+
<line num="95" type="method" name="calcCheckDigit" visibility="public" complexity="2" crap="2" count="4"/>
56+
<line num="97" type="stmt" count="4"/>
57+
<line num="100" type="stmt" count="4"/>
58+
<line num="102" type="stmt" count="4"/>
59+
<line num="103" type="stmt" count="1"/>
60+
<line num="104" type="stmt" count="4"/>
61+
<metrics loc="106" ncloc="59" classes="1" methods="4" coveredmethods="4" conditionals="0" coveredconditionals="0" statements="22" coveredstatements="22" elements="26" coveredelements="26"/>
62+
</file>
63+
<file name="C:\Users\Niklas Ekman\MyStuff\workspaces\luhn-algorithm\src\LuhnAlgorithmFactory.php">
64+
<class name="Nekman\LuhnAlgorithm\LuhnAlgorithmFactory" namespace="Nekman\LuhnAlgorithm">
65+
<metrics complexity="2" methods="1" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="1" coveredstatements="1" elements="2" coveredelements="2"/>
66+
</class>
67+
<line num="50" type="method" name="create" visibility="public" complexity="1" crap="1" count="1"/>
68+
<line num="52" type="stmt" count="1"/>
69+
<metrics loc="54" ncloc="19" classes="1" methods="1" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="1" coveredstatements="1" elements="2" coveredelements="2"/>
70+
</file>
71+
<file name="C:\Users\Niklas Ekman\MyStuff\workspaces\luhn-algorithm\src\Number.php">
72+
<class name="Nekman\LuhnAlgorithm\Number" namespace="Nekman\LuhnAlgorithm">
73+
<metrics complexity="9" methods="7" coveredmethods="7" conditionals="0" coveredconditionals="0" statements="18" coveredstatements="18" elements="25" coveredelements="25"/>
74+
</class>
75+
<line num="55" type="method" name="__construct" visibility="public" complexity="2" crap="2" count="12"/>
76+
<line num="57" type="stmt" count="12"/>
77+
<line num="58" type="stmt" count="4"/>
78+
<line num="61" type="stmt" count="8"/>
79+
<line num="62" type="stmt" count="8"/>
80+
<line num="63" type="stmt" count="8"/>
81+
<line num="75" type="method" name="fromString" visibility="public" complexity="2" crap="2" count="9"/>
82+
<line num="77" type="stmt" count="9"/>
83+
<line num="79" type="stmt" count="9"/>
84+
<line num="80" type="stmt" count="4"/>
85+
<line num="83" type="stmt" count="5"/>
86+
<line num="86" type="stmt" count="5"/>
87+
<line num="89" type="stmt" count="5"/>
88+
<line num="91" type="stmt" count="5"/>
89+
<line num="97" type="method" name="getNumber" visibility="public" complexity="1" crap="1" count="15"/>
90+
<line num="99" type="stmt" count="15"/>
91+
<line num="105" type="method" name="getCheckDigit" visibility="public" complexity="1" crap="1" count="12"/>
92+
<line num="107" type="stmt" count="12"/>
93+
<line num="114" type="method" name="__toString" visibility="public" complexity="1" crap="1" count="1"/>
94+
<line num="116" type="stmt" count="1"/>
95+
<line num="119" type="method" name="serialize" visibility="public" complexity="1" crap="1" count="1"/>
96+
<line num="121" type="stmt" count="1"/>
97+
<line num="124" type="method" name="unserialize" visibility="public" complexity="1" crap="1" count="1"/>
98+
<line num="126" type="stmt" count="1"/>
99+
<line num="127" type="stmt" count="1"/>
100+
<metrics loc="128" ncloc="68" classes="1" methods="7" coveredmethods="7" conditionals="0" coveredconditionals="0" statements="18" coveredstatements="18" elements="25" coveredelements="25"/>
101+
</file>
102+
</package>
103+
<metrics files="8" loc="519" ncloc="217" classes="4" methods="13" coveredmethods="13" conditionals="0" coveredconditionals="0" statements="43" coveredstatements="43" elements="56" coveredelements="56"/>
104+
</project>
105+
</coverage>

phpunit.xml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
<?xml version="1.0"?>
12
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
3-
bootstrap="vendor/autoload.php">
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php">
4+
<coverage>
5+
<include>
6+
<directory suffix=".php">src</directory>
7+
</include>
8+
<report>
9+
<clover outputFile="/tmp/coverage-clover.xml"/>
10+
</report>
11+
</coverage>
412
<testsuites>
513
<testsuite name="Luhn Algorithm tests">
614
<directory>tests/</directory>
715
</testsuite>
816
</testsuites>
9-
<filter>
10-
<whitelist>
11-
<directory suffix=".php">src</directory>
12-
</whitelist>
13-
</filter>
14-
<logging>
15-
<log type="coverage-clover" target="/tmp/coverage-clover.xml"/>
16-
</logging>
17+
<logging/>
1718
</phpunit>

src/Contract/LuhnAlgorithmExceptionInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2020 Niklas Ekman
6+
* Copyright (c) 2021 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/LuhnAlgorithmInterface.php

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2020 Niklas Ekman
6+
* Copyright (c) 2021 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
@@ -36,32 +36,28 @@
3636
*/
3737
interface LuhnAlgorithmInterface
3838
{
39-
/**
40-
* Determine if a number is valid according to the Luhn Algorithm.
41-
*
42-
* @param NumberInterface $number The number to validate.
43-
*
44-
* @return bool true if number is valid, false otherwise.
45-
*
46-
* @throws MissingCheckDigitException If the check digit in the number is not set.
47-
*/
48-
public function isValid(NumberInterface $number): bool;
39+
/**
40+
* Determine if a number is valid according to the Luhn Algorithm.
41+
* @param NumberInterface $number The number to validate.
42+
* @throws MissingCheckDigitException If the check digit in the number is not set.
43+
* @throws LuhnAlgorithmExceptionInterface
44+
* @return bool true if number is valid, false otherwise.
45+
*/
46+
public function isValid(NumberInterface $number): bool;
4947

50-
/**
51-
* Calculate the check digit for an input.
52-
*
53-
* @param NumberInterface $number The number to calculate the check digit for.
54-
*
55-
* @return int The check digit.
56-
*/
57-
public function calcCheckDigit(NumberInterface $number): int;
48+
/**
49+
* Calculate the check digit for an input.
50+
* @param NumberInterface $number The number to calculate the check digit for.
51+
* @throws LuhnAlgorithmExceptionInterface
52+
* @return int The check digit.
53+
*/
54+
public function calcCheckDigit(NumberInterface $number): int;
5855

59-
/**
60-
* Calulates the checksum for number.
61-
*
62-
* @param NumberInterface $number The number to calculate the checksum for.
63-
*
64-
* @return int The checksum.
65-
*/
66-
public function calcChecksum(NumberInterface $number): int;
56+
/**
57+
* Calculates the checksum for number.
58+
* @param NumberInterface $number The number to calculate the checksum for.
59+
* @throws LuhnAlgorithmExceptionInterface
60+
* @return int The checksum.
61+
*/
62+
public function calcChecksum(NumberInterface $number): int;
6763
}

src/Contract/NumberInterface.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2020 Niklas Ekman
6+
* Copyright (c) 2021 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
@@ -32,17 +32,15 @@
3232
*/
3333
interface NumberInterface
3434
{
35-
/**
36-
* Get the number, without check digit.
37-
*
38-
* @return string
39-
*/
40-
public function getNumber(): string;
35+
/**
36+
* Get the number, without check digit.
37+
* @return string
38+
*/
39+
public function getNumber(): string;
4140

42-
/**
43-
* Get the check digit for the number.
44-
*
45-
* @return int|null The check digit or null if it has not been calculated yet.
46-
*/
47-
public function getCheckDigit();
41+
/**
42+
* Get the check digit for the number.
43+
* @return int|null The check digit or null if it has not been calculated yet.
44+
*/
45+
public function getCheckDigit(): ?int;
4846
}

src/Exceptions/ArgumentIsNotNumericException.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2020 Niklas Ekman
6+
* Copyright (c) 2021 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
@@ -35,8 +35,8 @@
3535
*/
3636
class ArgumentIsNotNumericException extends InvalidArgumentException implements LuhnAlgorithmExceptionInterface
3737
{
38-
public function __construct(string $number)
39-
{
40-
parent::__construct("Expects \$number to be a number, \"{$number}\" given.");
41-
}
38+
public function __construct(string $number)
39+
{
40+
parent::__construct("Expects \$number to be a number, \"{$number}\" given.");
41+
}
4242
}

src/Exceptions/MissingCheckDigitException.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2020 Niklas Ekman
6+
* Copyright (c) 2021 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
@@ -27,11 +27,12 @@
2727

2828
namespace Nekman\LuhnAlgorithm\Exceptions;
2929

30+
use InvalidArgumentException;
3031
use Nekman\LuhnAlgorithm\Contract\LuhnAlgorithmExceptionInterface;
3132

3233
/**
3334
* Indicates that the check digit should be present, but is in fact not.
3435
*/
35-
class MissingCheckDigitException extends \InvalidArgumentException implements LuhnAlgorithmExceptionInterface
36+
class MissingCheckDigitException extends InvalidArgumentException implements LuhnAlgorithmExceptionInterface
3637
{
3738
}

0 commit comments

Comments
 (0)