SKAlgorithm   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isFollowLength() 0 7 2
A validate() 0 7 2
1
<?php
2
3
namespace LeKoala\Tin\Algo;
4
5
use LeKoala\Tin\Util\StringUtil;
6
7
/**
8
 * Slovakia
9
 */
10
class SKAlgorithm extends TINAlgorithm
11
{
12
    const LENGTH = 10;
13
14
    public function validate(string $tin)
15
    {
16
        $str = StringUtil::clearString($tin);
17
        if (!$this->isFollowLength($str)) {
18
            return StatusCode::INVALID_LENGTH;
19
        }
20
        return StatusCode::VALID;
21
    }
22
23
    public function isFollowLength(string $tin)
24
    {
25
        $c1c2 = StringUtil::substring($tin, 0, 2);
26
        if ($c1c2 < 54) {
27
            return StringUtil::isFollowLength($tin, self::LENGTH - 1);
28
        }
29
        return StringUtil::isFollowLength($tin, self::LENGTH);
30
    }
31
}
32