Kpp::isValid()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 8
c 1
b 0
f 1
nc 3
nop 1
dl 0
loc 17
rs 10
1
<?php
2
3
namespace Kontrolio\Rules\Core;
4
5
use Kontrolio\Rules\AbstractRule;
6
7
class Kpp 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
        $input = (string) $input;
19
20
        if (strlen($input) != 9) {
21
            $this->violations[] = 'length';
22
23
            return false;
24
        }
25
26
        if (!preg_match('/\d{4}[\dA-Z][\dA-Z]\d{3}/', $input)) {
27
            $this->violations[] = 'format';
28
29
            return false;
30
        }
31
32
        return true;
33
    }
34
}
35