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

Boolean   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 0
cbo 1
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 2
A value() 0 4 1
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