Completed
Pull Request — master (#18)
by Hannes
06:53
created

PersonalIdDateValidator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 10
c 0
b 0
f 0
ccs 7
cts 7
cp 1
wmc 2
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 12 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace byrokrat\banking\Validator;
6
7
use byrokrat\banking\AccountNumber;
8
9
/**
10
 * Validate that account numbers contains dates as in swedish personal ids
11
 */
12
class PersonalIdDateValidator implements ValidatorInterface
13
{
14 61
    public function validate(AccountNumber $number): ResultInterface
15
    {
16 61
        $day = (int)substr($number->getSerialNumber(), -5, 2);
17 61
        $month = (int)substr($number->getSerialNumber(), -7, 2);
18 61
        $year = (int)substr($number->getSerialNumber(), 0, -7);
19
20 61
        if (!checkdate($month, $day, $year)) {
21 54
            return new Failure("Account number is not a valid personal id number");
22
        }
23
24 23
        return new Success("Valid personal id number");
25
    }
26
}
27