Passed
Push — master ( 819f30...8ceff2 )
by Thorsten
02:22
created

Boolean::isTrue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Daikon\Entity\ValueObject;
4
5
use Daikon\Entity\Assert\Assertion;
6
7
final class Boolean implements ValueObjectInterface
8
{
9
    /**
10
     * @var bool
11
     */
12
    private $value;
13
14
    /**
15
     * @param bool $nativeValue
16
     * @return self
17
     */
18 19
    public static function fromNative($nativeValue): self
19
    {
20 19
        Assertion::boolean($nativeValue);
21 19
        return new self($nativeValue);
22
    }
23
24 4
    public function toNative(): bool
25
    {
26 4
        return $this->value;
27
    }
28
29 1
    public function equals(ValueObjectInterface $otherValue): bool
30
    {
31 1
        return $otherValue instanceof self && $this->toNative() === $otherValue->toNative();
32
    }
33
34 1
    public function __toString(): string
35
    {
36 1
        return $this->value ? "true" : "false";
37
    }
38
39 1
    public function isTrue(): bool
40
    {
41 1
        return $this->value === true;
42
    }
43
44 1
    public function isFalse(): bool
45
    {
46 1
        return $this->value === false;
47
    }
48
49 1
    public function negate(): self
50
    {
51 1
        $clone = clone $this;
52 1
        $clone->value = !$this->value;
53 1
        return $clone;
54
    }
55
56 19
    private function __construct(bool $value)
57
    {
58 19
        $this->value = $value;
59 19
    }
60
}
61