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

Boolean   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 0
cbo 0
dl 0
loc 34
ccs 16
cts 16
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 24 5
A value() 0 4 1
1
<?php
2
3
namespace Equip\ValueObject;
4
5
use InvalidArgumentException;
6
7
class Boolean
8
{
9
    private $value;
10
11 17
    public function __construct($value, $default = null)
12
    {
13 17
        static $empty_values = [null, ''];
14
15 17
        if (is_bool($default) && in_array($value, $empty_values, true)) {
16 1
            $value = $default;
17 1
        }
18
19 17
        if (!is_scalar($value)) {
20 2
            throw new InvalidArgumentException('Value must a possible boolean');
21
        }
22
23
        $options = [
24 15
            'flags' => \FILTER_NULL_ON_FAILURE,
25 15
        ];
26
27 15
        $value = filter_var($value, \FILTER_VALIDATE_BOOLEAN, $options);
28
29 15
        if ($value === null) {
30 3
            throw new InvalidArgumentException('Value must be boolean');
31
        }
32
33 12
        $this->value = $value;
34 12
    }
35
36 12
    public function value()
37
    {
38 12
        return $this->value;
39
    }
40
}
41