Completed
Push — master ( 0de93f...7d590b )
by Ronan
02:51 queued 53s
created

Sedol   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 0
dl 0
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 21 4
1
<?php
2
3
namespace IsoCodes;
4
5
/**
6
 * @link https://en.wikipedia.org/wiki/SEDOL
7
 *
8
 * @author Sullivan Senechal <[email protected]>
9
 */
10
class Sedol implements IsoCodeInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public static function validate($value)
16
    {
17
        if (strlen($value) !== 7) {
18
            return false;
19
        }
20
21
        $char6 = substr($value, 0, 6);
22
23
        if (!preg_match('/^[0-9BCDFGHJKLMNPQRSTVWXYZ]{6}$/', $char6)) {
24
            return false;
25
        }
26
27
        $weight = [1, 3, 1, 7, 3, 9, 1];
28
        $sum = 0;
29
        for ($i = 0; $i < 6; ++$i) {
30
            $sum += $weight[$i] * intval($char6[$i], 36);
31
        }
32
        $check = (10 - $sum % 10) % 10;
33
34
        return $value === $char6 . $check;
35
    }
36
}
37