BoolValue::__toString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/value-object 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
namespace Daikon\ValueObject;
10
11
use Daikon\Interop\Assertion;
12
13
final class BoolValue implements ValueObjectInterface
14
{
15
    private bool $value;
16
17
    /** @param bool $value */
18 6
    public static function fromNative($value): self
19
    {
20 6
        Assertion::boolean($value, 'Trying to create BoolValue VO from unsupported value type.');
21 6
        return new self($value);
22
    }
23
24
    public static function false(): self
25
    {
26
        return new self(false);
27
    }
28
29
    public static function true(): self
30
    {
31
        return new self(true);
32
    }
33
34 3
    public function toNative(): bool
35
    {
36 3
        return $this->value;
37
    }
38
39
    /** @param self $comparator */
40 1
    public function equals($comparator): bool
41
    {
42 1
        Assertion::isInstanceOf($comparator, self::class);
43 1
        return $this->toNative() === $comparator->toNative();
44
    }
45
46 1
    public function __toString(): string
47
    {
48 1
        return $this->value ? 'true' : 'false';
49
    }
50
51 1
    public function isTrue(): bool
52
    {
53 1
        return $this->value === true;
54
    }
55
56 1
    public function isFalse(): bool
57
    {
58 1
        return $this->value === false;
59
    }
60
61 1
    public function negate(): self
62
    {
63 1
        $clone = clone $this;
64 1
        $clone->value = !$this->value;
65 1
        return $clone;
66
    }
67
68 6
    private function __construct(bool $value)
69
    {
70 6
        $this->value = $value;
71 6
    }
72
}
73