Passed
Push — master ( 373c52...ed53b1 )
by Thorsten
03:30
created

BoolValue::isFalse()   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
 * This file is part of the daikon-cqrs/entity project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
declare(strict_types=1);
10
11
namespace Daikon\Entity\ValueObject;
12
13
use Daikon\Entity\Assert\Assertion;
14
15
final class BoolValue implements ValueObjectInterface
16
{
17
    /**
18
     * @var bool
19
     */
20
    private $value;
21
22
    /**
23
     * @param bool $nativeValue
24
     * @return BoolValue
25
     */
26 16
    public static function fromNative($nativeValue): BoolValue
27
    {
28 16
        Assertion::boolean($nativeValue, 'Trying to create BoolValue VO from unsupported value type.');
29 16
        return new static($nativeValue);
30
    }
31
32 4
    public function toNative(): bool
33
    {
34 4
        return $this->value;
35
    }
36
37 1
    public function equals(ValueObjectInterface $value): bool
38
    {
39 1
        return $value instanceof static && $this->toNative() === $value->toNative();
40
    }
41
42 1
    public function __toString(): string
43
    {
44 1
        return $this->value ? 'true' : 'false';
45
    }
46
47 1
    public function isTrue(): bool
48
    {
49 1
        return $this->value === true;
50
    }
51
52 1
    public function isFalse(): bool
53
    {
54 1
        return $this->value === false;
55
    }
56
57 1
    public function negate(): BoolValue
58
    {
59 1
        $clone = clone $this;
60 1
        $clone->value = !$this->value;
61
        /** @noinspection PhpStrictTypeCheckingInspection */
62 1
        return $clone;
63
    }
64
65 16
    private function __construct(bool $value)
66
    {
67 16
        $this->value = $value;
68 16
    }
69
}
70