Completed
Pull Request — master (#4)
by Woody
02:12
created

Boolean::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 18
ccs 11
cts 11
cp 1
rs 9.4285
cc 2
eloc 9
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Equip\ValueObject;
4
5
use function Assert\that;
6
7
class Boolean
8
{
9
    /**
10
     * @var bool|null
11
     */
12
    private $value;
13
14
    /**
15
     * @param string|boolean|null $value
16
     * @param string|boolean|null $default
17
     */
18 17
    public function __construct($value, $default = null)
19
    {
20 17
        if ($value === null) {
21 1
            $value = $default;
22 1
        }
23
24 17
        that($value)->nullOr()->scalar();
25
26
        $options = [
27 15
            'flags' => \FILTER_NULL_ON_FAILURE,
28 15
        ];
29
30 15
        $value = filter_var($value, \FILTER_VALIDATE_BOOLEAN, $options);
31
32 15
        that($value)->boolean();
33
34 12
        $this->value = $value;
35 12
    }
36
37
    /**
38
     * @return boolean
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
39
     */
40 12
    public function value()
41
    {
42 12
        return $this->value;
43
    }
44
}
45