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

Boolean::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.4285
cc 2
eloc 8
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Equip\ValueObject;
4
5
use InvalidArgumentException;
6
7
use function Assert\that;
8
9
class Boolean
10
{
11
    /**
12
     * @var bool|null
13
     */
14
    private $value;
15
16 17
    public function __construct($value, $default = null)
17
    {
18 17
        if ($value === null) {
19 1
            $value = $default;
20 1
        }
21
22
        $options = [
23 17
            'flags' => \FILTER_NULL_ON_FAILURE,
24 17
        ];
25
26 17
        $value = filter_var($value, \FILTER_VALIDATE_BOOLEAN, $options);
27
28 17
        $assert = that($value)->boolean();
0 ignored issues
show
Unused Code introduced by
$assert is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
29
30 13
        $this->value = $value;
31 13
    }
32
33 12
    public function value()
34
    {
35 12
        return $this->value;
36
    }
37
}
38