| Conditions | 4 |
| Paths | 3 |
| Total Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 7 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | 187 | public function validate(AccountNumber $number): ResultInterface |
|
| 15 | { |
||
| 16 | 187 | if ($number->getCheckDigit() === '' || $number->getSerialNumber() === '') { |
|
| 17 | 1 | return new Failure('Unable to validate checkdigit, not enough digits'); |
|
| 18 | } |
||
| 19 | |||
| 20 | 187 | $expected = $this->calculateCheckDigit($number); |
|
| 21 | |||
| 22 | 187 | if ($number->getCheckDigit() == $expected) { |
|
| 23 | 146 | return new Success("Valid check digit $expected"); |
|
| 24 | } |
||
| 25 | |||
| 26 | 116 | return new Failure("Invalid check digit {$number->getCheckDigit()}, expected $expected"); |
|
| 27 | } |
||
| 28 | |||
| 34 |