Skip to content

Commit c94f45b

Browse files
authored
Add editorconfig (#33)
* Add editorconfig * fix
1 parent f1f7dfd commit c94f45b

13 files changed

+439
-420
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# See: https://editorconfig.org/#file-format-details
2+
root = true
3+
4+
[*]
5+
end_of_line = lf
6+
insert_final_newline = true
7+
charset = utf-8
8+
indent_style = tab
9+
trim_trailing_whitespace = true
10+
indent_size = 4
11+
12+
[*.yml]
13+
indent_style = space
14+
indent_size = 2

.travis.yml

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
language: php
2-
3-
php:
4-
- 7.0
5-
- 7.1
6-
- 7.2
7-
- 7.3
8-
- 7.4
9-
- nightly
10-
11-
matrix:
12-
allow_failures:
13-
- php: nightly
14-
15-
install: composer update --no-interaction --classmap-authoritative --no-suggest --ignore-platform-reqs --prefer-lowest
16-
17-
script: vendor/bin/phpunit --configuration phpunit.xml
18-
19-
after_success: vendor/bin/php-coveralls --verbose
20-
21-
notifications:
22-
email: false
23-
24-
cache:
25-
directories:
26-
- $HOME/.composer
1+
language: php
2+
3+
php:
4+
- 7.0
5+
- 7.1
6+
- 7.2
7+
- 7.3
8+
- 7.4
9+
- nightly
10+
11+
matrix:
12+
allow_failures:
13+
- php: nightly
14+
15+
install: composer update --no-interaction --classmap-authoritative --no-suggest --ignore-platform-reqs --prefer-lowest
16+
17+
script: vendor/bin/phpunit --configuration phpunit.xml
18+
19+
after_success: vendor/bin/php-coveralls --verbose
20+
21+
notifications:
22+
email: false
23+
24+
cache:
25+
directories:
26+
- $HOME/.composer

phpunit.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<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">
2+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
3+
bootstrap="vendor/autoload.php">
44
<testsuites>
55
<testsuite name="Luhn Algorithm tests">
66
<directory>tests/</directory>
77
</testsuite>
88
</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>
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>
1717
</phpunit>

src/Contract/LuhnAlgorithmExceptionInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727

2828
namespace Nekman\LuhnAlgorithm\Contract;
2929

30+
use Throwable;
31+
3032
/**
3133
* Base interface for all thrown exceptions in this library.
3234
*/
33-
interface LuhnAlgorithmExceptionInterface extends \Throwable
35+
interface LuhnAlgorithmExceptionInterface extends Throwable
3436
{
3537
}

src/Contract/LuhnAlgorithmInterface.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,32 @@
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-
* @throws MissingCheckDigitException If the check digit in the number is not set.
45-
* @return bool true if number is valid, false otherwise.
46-
*
47-
*/
48-
public function isValid(NumberInterface $number): bool;
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;
4949

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;
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;
5858

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;
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;
6767
}

src/Contract/NumberInterface.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@
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+
*
38+
* @return string
39+
*/
40+
public function getNumber(): string;
4141

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();
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();
4848
}

src/Exceptions/ArgumentIsNotNumericException.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@
2727

2828
namespace Nekman\LuhnAlgorithm\Exceptions;
2929

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

3233
/**
3334
* Indicates that an argument should be numeric, but is in fact not.
3435
*/
35-
class ArgumentIsNotNumericException extends \InvalidArgumentException implements LuhnAlgorithmExceptionInterface
36+
class ArgumentIsNotNumericException extends InvalidArgumentException implements LuhnAlgorithmExceptionInterface
3637
{
37-
public function __construct(string $number)
38-
{
39-
parent::__construct("Expects \$number to be a number, \"{$number}\" given.");
40-
}
38+
public function __construct(string $number)
39+
{
40+
parent::__construct("Expects \$number to be a number, \"{$number}\" given.");
41+
}
4142
}

src/LuhnAlgorithm.php

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -36,71 +36,71 @@
3636
*/
3737
class LuhnAlgorithm implements LuhnAlgorithmInterface
3838
{
39-
/**
40-
* @internal The intended way to instantiate this object is through the factory.
41-
*
42-
* @see LuhnAlgorithmFactory
43-
*/
44-
public function __construct()
45-
{
46-
}
47-
48-
/**
49-
* {@inheritDoc}
50-
*/
51-
public function isValid(NumberInterface $number): bool
52-
{
53-
if ($number->getCheckDigit() === null) {
54-
throw new MissingCheckDigitException("Check digit is null.");
55-
}
56-
57-
$checksum = $this->calcChecksum($number) + $number->getCheckDigit();
58-
59-
return ($checksum % 10) === 0;
60-
}
61-
62-
/**
63-
* {@inheritDoc}
64-
*/
65-
public function calcCheckDigit(NumberInterface $number): int
66-
{
67-
$checksum = $this->calcChecksum($number);
68-
69-
// Get the last digit of the checksum.
70-
$checkDigit = $checksum % 10;
71-
72-
return $checkDigit === 0
73-
? $checkDigit
74-
: 10 - $checkDigit;
75-
}
76-
77-
/**
78-
* {@inheritDoc}
79-
*/
80-
public function calcChecksum(NumberInterface $number): int
81-
{
82-
$num = $number->getNumber();
83-
$nDigits = strlen($num);
84-
// Need to account for check digit
85-
$parity = ($nDigits + 1) % 2;
86-
$checksum = 0;
87-
88-
for ($i = 0; $i < $nDigits; $i++) {
89-
$digit = (int) $num[$i];
90-
91-
// Every other digit, starting from the rightmost,
92-
// shall be doubled.
93-
if (($i % 2) === $parity) {
94-
$digit *= 2;
95-
96-
if ($digit > 9) {
97-
$digit -= 9;
98-
}
99-
}
100-
101-
$checksum += $digit;
102-
}
103-
104-
return $checksum;
105-
}
39+
/**
40+
* @internal The intended way to instantiate this object is through the factory.
41+
*
42+
* @see LuhnAlgorithmFactory
43+
*/
44+
public function __construct()
45+
{
46+
}
47+
48+
/**
49+
* {@inheritDoc}
50+
*/
51+
public function isValid(NumberInterface $number): bool
52+
{
53+
if ($number->getCheckDigit() === null) {
54+
throw new MissingCheckDigitException("Check digit is null.");
55+
}
56+
57+
$checksum = $this->calcChecksum($number) + $number->getCheckDigit();
58+
59+
return ($checksum % 10) === 0;
60+
}
61+
62+
/**
63+
* {@inheritDoc}
64+
*/
65+
public function calcChecksum(NumberInterface $number): int
66+
{
67+
$num = $number->getNumber();
68+
$nDigits = strlen($num);
69+
// Need to account for check digit
70+
$parity = ($nDigits + 1) % 2;
71+
$checksum = 0;
72+
73+
for ($i = 0; $i < $nDigits; $i++) {
74+
$digit = (int)$num[$i];
75+
76+
// Every other digit, starting from the rightmost,
77+
// shall be doubled.
78+
if (($i % 2) === $parity) {
79+
$digit *= 2;
80+
81+
if ($digit > 9) {
82+
$digit -= 9;
83+
}
84+
}
85+
86+
$checksum += $digit;
87+
}
88+
89+
return $checksum;
90+
}
91+
92+
/**
93+
* {@inheritDoc}
94+
*/
95+
public function calcCheckDigit(NumberInterface $number): int
96+
{
97+
$checksum = $this->calcChecksum($number);
98+
99+
// Get the last digit of the checksum.
100+
$checkDigit = $checksum % 10;
101+
102+
return $checkDigit === 0
103+
? $checkDigit
104+
: 10 - $checkDigit;
105+
}
106106
}

src/LuhnAlgorithmFactory.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@
3434
*/
3535
class LuhnAlgorithmFactory
3636
{
37-
/**
38-
* @codeCoverageIgnore
39-
*/
40-
private function __construct()
41-
{
42-
// Only static methods.
43-
}
37+
/**
38+
* @codeCoverageIgnore
39+
*/
40+
private function __construct()
41+
{
42+
// Only static methods.
43+
}
4444

45-
/**
46-
* Create a new instance of an implementation of the Luhn Algorithm.
47-
*
48-
* @return LuhnAlgorithmInterface Implementation of the Luhn Algorithm.
49-
*/
50-
public static function create(): LuhnAlgorithmInterface
51-
{
52-
return new LuhnAlgorithm();
53-
}
45+
/**
46+
* Create a new instance of an implementation of the Luhn Algorithm.
47+
*
48+
* @return LuhnAlgorithmInterface Implementation of the Luhn Algorithm.
49+
*/
50+
public static function create(): LuhnAlgorithmInterface
51+
{
52+
return new LuhnAlgorithm();
53+
}
5454
}

0 commit comments

Comments
 (0)