Completed
Push — master ( 23ade5...b523b7 )
by Woody
10s
created

Identifier::value()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Equip\ValueObject;
4
5
use InvalidArgumentException;
6
7
class Identifier
8
{
9
    /**
10
     * @var int|null
11
     */
12
    private $id;
13
14 13
    public function __construct($id, $is_required = true)
15
    {
16 13
        static $empty_values = [null, false, 0, '0', ''];
17
18 13
        if (in_array($id, $empty_values, true) && !$is_required) {
19 3
            $id = null;
20
        } else {
21
            $options = [
22 10
                'flags' => \FILTER_REQUIRE_SCALAR,
23
                'options' => [
24
                    'min_range' => 1,
25
                ],
26
            ];
27
28 10
            if (filter_var($id, \FILTER_VALIDATE_INT, $options) === false) {
29 7
                throw new InvalidArgumentException('Value must be a valid identifier');
30
            }
31
32 3
            $id = (int) $id;
33
        }
34
35 6
        $this->id = $id;
36 6
    }
37
38 6
    public function value()
39
    {
40 6
        return $this->id;
41
    }
42
}
43