Imei   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 49
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 2
A validateLuhnAlgorithm() 0 14 4
1
<?php
2
3
namespace ValueObjects\Identity;
4
5
use ValueObjects\Exception\InvalidNativeArgumentException;
6
use ValueObjects\Number\Natural;
7
8
class Imei extends Natural
9
{
10
    /**
11
     * Returns an Imei number
12
     *
13
     * @param int $value
14
     */
15 4
    public function __construct($value)
16
    {
17
        $options = array(
18
            'options' => array(
19 4
                'min_range' => 100000000000000,
20
                'max_range' => 999999999999999
21 4
            )
22 4
        );
23
24 4
        $value = filter_var($value, FILTER_VALIDATE_INT, $options);
25
26 4
        if (false === $value) {
27 2
            throw new InvalidNativeArgumentException($value, array('int (15 digits)'));
28
        }
29
30 2
        $value = $this->validateLuhnAlgorithm($value);
31
32 1
        $this->value = $value;
33 1
    }
34
35
    /**
36
     * Checks the validity of the Imei using the Luhn algorithm
37
     *
38
     * @param int $value
0 ignored issues
show
Bug introduced by
There is no parameter named $value. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
39
     * @return int
40
     * @throws \ValueObjects\Exception\InvalidNativeArgumentException
41
     */
42 2
    private function validateLuhnAlgorithm($imei)
43
    {
44 2
        $str = '';
45
46 2
        foreach (str_split(strrev((string) $imei)) as $i => $d) {
47 2
            $str .= $i %2 !== 0 ? $d * 2 : $d;
48 2
        }
49
50 2
        if (array_sum(str_split($str)) % 10 !== 0) {
51 1
            throw new InvalidNativeArgumentException($imei, array('int (valid Imei code)'));
52
        }
53
54 1
        return $imei;
55
    }
56
}
57