BooleanValueObject::getValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TimiTao\ValueObject\Beberlei\Nullable;
6
7
use Exception;
8
use TimiTao\ValueObject\Nullable\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