Ogrn   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 16
c 1
b 0
f 1
dl 0
loc 39
rs 10
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B isValid() 0 30 7
1
<?php
2
3
namespace Kontrolio\Rules\Core;
4
5
use Kontrolio\Rules\AbstractRule;
6
7
class Ogrn extends AbstractRule
8
{
9
    /**
10
     * Validates input.
11
     *
12
     * @param mixed $input
13
     *
14
     * @return bool
15
     */
16
    public function isValid($input = null)
17
    {
18
        if (!is_numeric($input)) {
19
            $this->violations[] = 'numeric';
20
21
            return false;
22
        }
23
        
24
        $input = (string) $input;
25
        $length = strlen($input);
26
        
27
        if ($length < 13 || $length > 15) {
28
            $this->violations[] = 'length';
29
30
            return false;
31
        }
32
        
33
        if ($length == 13) {
34
            $result = floor(($input / 10) % 11);
35
36
            return ($result == 10 ? $input[12] == 0 : $input[12] == $result);
37
        }
38
39
        if ($length == 15) {
40
            $result = floor(($input / 10) % 13);
41
42
            return ($input[14] == ($result % 10));
43
        }
44
45
        return false;
46
    }
47
}
48