BoolValue   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 58
ccs 20
cts 24
cp 0.8333
rs 10
c 1
b 0
f 0
wmc 11

10 Methods

Rating   Name   Duplication   Size   Complexity  
A isTrue() 0 3 1
A false() 0 3 1
A toNative() 0 3 1
A negate() 0 5 1
A __construct() 0 3 1
A fromNative() 0 4 1
A isFalse() 0 3 1
A equals() 0 4 1
A __toString() 0 3 2
A true() 0 3 1
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