Skip to content

Commit 14d31de

Browse files
committed
refactor: migrated/fixed error: PHPStan, PHPUnit, PHPCS.
remove: scanning test files for static analysis. update: PHPCS config for sub-repos.
1 parent be8b7ff commit 14d31de

File tree

6 files changed

+130
-156
lines changed

6 files changed

+130
-156
lines changed

Src/Luhn.php

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
<?php
2-
/**
3-
* Luhn Algorithm creator.
4-
*
5-
* @package TheWebSolver\Codegarage\Validation
6-
*/
2+
declare( strict_types = 1 );
73

8-
declare( strict_types = 1 );
9-
10-
namespace TheWebSolver\Codegarage;
4+
namespace TheWebSolver\Codegarage;
115

126
use LogicException;
137

148
trait Luhn {
159
private const ALLOWED_PATTERN = '/[^0-9]/';
16-
private const EMPTY = 'REPRESENTS EMPTY CHECKSUM VALUE @' . self::class;
10+
private const EMPTY_VALUE = 'REPRESENTS EMPTY CHECKSUM VALUE @Luhn';
1711

1812
private bool $needsDoubling = false;
19-
private string $digits = '0';
13+
private string $digits = '0';
2014
private int $checksum;
2115
private mixed $raw;
2216

@@ -36,7 +30,7 @@ public function __toString(): string {
3630

3731
/** @throws LogicException When initialized without value or constructor value & invoked value mismatch. */
3832
public function __invoke( mixed $data = null ): bool {
39-
return $this->ensureNumber( $data ?? self::EMPTY )->isValid();
33+
return $this->ensureNumber( $data ?? self::EMPTY_VALUE )->isValid();
4034
}
4135

4236
/**
@@ -59,7 +53,7 @@ public static function validate( mixed $value ): bool {
5953

6054
/** @throws LogicException When initialized without value. */
6155
public function checksum(): int {
62-
return $this->checksum ??= $this->ensureNumber( $this->raw ?? self::EMPTY )->add();
56+
return $this->checksum ??= $this->ensureNumber( $this->raw ?? self::EMPTY_VALUE )->add();
6357
}
6458

6559
/** @throws LogicException When initialized without value. */
@@ -110,10 +104,10 @@ private function maybeDoubleAndAddDigits( int $value ): int {
110104

111105
private function ensureNumber( mixed $value ): static {
112106
if ( ! isset( $this->raw ) ) {
113-
return self::EMPTY !== $value ? $this->runAlgorithm( $value ) : $this->throw( hasValue: false );
107+
return self::EMPTY_VALUE !== $value ? $this->runAlgorithm( $value ) : $this->throw( hasValue: false );
114108
}
115109

116-
return ( self::EMPTY === $value || $this->raw === $value ) ? $this : $this->throw( hasValue: true );
110+
return ( self::EMPTY_VALUE === $value || $this->raw === $value ) ? $this : $this->throw( hasValue: true );
117111
}
118112

119113
private function throw( bool $hasValue ): never {

Src/LuhnAlgorithm.php

-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
<?php
2-
/**
3-
* Luhn Algorithm.
4-
*
5-
* @package TheWebSolver\Codegarage\Validation
6-
*/
7-
82
declare( strict_types = 1 );
93

104
namespace TheWebSolver\Codegarage;

Tests/LuhnTest.php

-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
<?php
2-
/**
3-
* Luhn Algorithm test.
4-
*
5-
* @package TheWebSolver\Codegarage\Test
6-
*/
7-
82
declare( strict_types = 1 );
93

104
use PHPUnit\Framework\TestCase;

0 commit comments

Comments
 (0)