PortNumber::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 1
crap 2
1
<?php
2
3
namespace ValueObjects\Web;
4
5
use ValueObjects\Exception\InvalidNativeArgumentException;
6
use ValueObjects\Number\Natural;
7
8
class PortNumber extends Natural implements PortNumberInterface
9
{
10
    /**
11
     * Returns a PortNumber object.
12
     *
13
     * @param int $value
14
     */
15 15
    public function __construct($value)
16
    {
17
        $options = array(
18
            'options' => array(
19 15
                'min_range' => 0,
20
                'max_range' => 65535
21 15
            )
22 15
        );
23
24 15
        $filteredValue = filter_var($value, FILTER_VALIDATE_INT, $options);
25
26 15
        if (false === $filteredValue) {
27 1
            throw new InvalidNativeArgumentException($value, array('int (>=0, <=65535)'));
28
        }
29
30 14
        parent::__construct($filteredValue);
31 14
    }
32
}
33