Completed
Push — master ( 70fcc2...406cf9 )
by Ronan
01:53
created

Bsn   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 5
Bugs 0 Features 2
Metric Value
wmc 6
c 5
b 0
f 2
lcom 0
cbo 0
dl 0
loc 32
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B validate() 0 24 6
1
<?php
2
3
namespace IsoCodes;
4
5
/**
6
 * In the Netherlands, the citizen service number (BSN) is a unique personal number
7
 * allocated to everyone registered in the Municipal Personal Records Database.
8
 *
9
 * @link https://www.government.nl/topics/identification-documents/contents/the-citizen-service-number
10
 * @link https://nl.wikipedia.org/wiki/Elfproef (dutch)
11
 * @link https://nl.wikipedia.org/wiki/Burgerservicenummer (dutch)
12
 * @link http://datavaluetalk.com/data-quality/remarkable-facts-on-dutch-national-personal-identification-number-burgerservicenummer-bsn/
13
 *
14
 * @author  Albert Bakker <[email protected]>
15
 */
16
final class Bsn implements IsoCodeInterface
17
{
18
    /**
19
     * @param string $value
20
     *
21
     * @return bool
22
     */
23
    public static function validate($value)
24
    {
25
        if (!is_numeric($value)) {
26
            return false;
27
        }
28
29
        $stringLength = strlen($value);
30
31
        if ($stringLength !== 9 && $stringLength !== 8) {
32
            return false;
33
        }
34
35
        $sum = 0;
36
        $multiplier = $stringLength;
37
        for ($counter = 0; $counter < $stringLength; $counter++, $multiplier--) {
38
            if ($multiplier == 1) {
39
                $multiplier = -1;
40
            }
41
42
            $sum += substr($value, $counter, 1) * $multiplier;
43
        }
44
45
        return $sum % 11 === 0;
46
    }
47
}
48