Total Complexity | 9 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | abstract class Document extends AbstractValidation |
||
10 | { |
||
11 | public function __construct(private bool $mask = true, ?string $message = 'Invalid document') |
||
12 | { |
||
13 | parent::__construct($message); |
||
14 | } |
||
15 | |||
16 | public function evaluate($input, array $context = []): bool |
||
17 | { |
||
18 | try { |
||
19 | $document = (string) $input; |
||
20 | } catch (Throwable) { |
||
|
|||
21 | return false; |
||
22 | } |
||
23 | |||
24 | if ($this->mask) { |
||
25 | if (!$this->isValidMask($document)) { |
||
26 | return false; |
||
27 | } |
||
28 | |||
29 | $document = $this->unmaskNumber($document); |
||
30 | } |
||
31 | |||
32 | $document = $this->adjustZeroPadding($document); |
||
33 | return $this->isValidDocument($document); |
||
34 | } |
||
35 | |||
36 | public function isValidMask(string $input): bool |
||
37 | { |
||
38 | return preg_match($this->maskPattern(), $input) === 1; |
||
39 | } |
||
40 | |||
41 | public function unmaskNumber(string $input): string |
||
42 | { |
||
43 | return preg_replace('/\D/', '', $input); |
||
44 | } |
||
45 | |||
46 | public function adjustZeroPadding(string $input): string |
||
49 | } |
||
50 | |||
51 | public function validateNumbersWithCorrectLength(string $unmaskedInput): bool |
||
52 | { |
||
55 | } |
||
56 | |||
57 | abstract public function isValidDocument(string $input): bool; |
||
58 | |||
59 | abstract public function maskPattern(): string; |
||
60 | |||
61 | abstract public function unmaskedLength(): int; |
||
62 | } |
||
63 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.