BooleanValueObject   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 8
c 0
b 0
f 0
dl 0
loc 30
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
A __construct() 0 4 1
A equals() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TimiTao\ValueObject\Beberlei\Standard;
6
7
use Exception;
8
use TimiTao\ValueObject\Standard\ValueObject\BooleanValueObject as BooleanValueObjectInterface;
9
10
abstract class BooleanValueObject implements BooleanValueObjectInterface
11
{
12
    private $value;
13
14
    /**
15
     * @throws Exception if value is invalid
16
     */
17
    public function __construct(bool $value)
18
    {
19
        $this->guard($value);
20
        $this->value = $value;
21
    }
22
23
    public function equals(BooleanValueObjectInterface $other): bool
24
    {
25
        if (static::class !== get_class($other)) {
26
            return false;
27
        }
28
        return $this->getValue() === $other->getValue();
29
    }
30
31
    public function getValue(): bool
32
    {
33
        return $this->value;
34
    }
35
36
    /**
37
     * @throws Exception if value is invalid
38
     */
39
    abstract protected function guard(bool $value): void;
40
}
41