Passed
Push — master ( ebc79e...6104c3 )
by Mr
02:19
created

InvoiceState::equals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the ngutech/lightning-interop 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 NGUtech\Lightning\ValueObject;
10
11
use Daikon\Interop\Assertion;
12
use Daikon\Interop\MakeEmptyInterface;
13
use Daikon\ValueObject\ValueObjectInterface;
14
15
final class InvoiceState implements MakeEmptyInterface, ValueObjectInterface
16
{
17
    public const PENDING = 'pending';
18
    public const SETTLED = 'settled';
19
    public const CANCELLED = 'cancelled';
20
21
    public const STATES = [
22
        self::PENDING,
23
        self::SETTLED,
24
        self::CANCELLED,
25
    ];
26
27
    private ?string $state;
28
29
    /** @param null|string $state */
30
    public static function fromNative($state): self
31
    {
32
        Assertion::nullOrString($state);
33
        return new self($state);
34
    }
35
36
    public function toNative(): ?string
37
    {
38
        return $this->state;
39
    }
40
41
    /** @param self $comparator */
42
    public function equals($comparator): bool
43
    {
44
        Assertion::isInstanceOf($comparator, self::class);
45
        return $this->toNative() === $comparator->toNative();
46
    }
47
48
    public static function makeEmpty(): self
49
    {
50
        return new self;
51
    }
52
53
    public function isEmpty(): bool
54
    {
55
        return $this->state === null;
56
    }
57
58
    public function isPending(): bool
59
    {
60
        return $this->state === self::PENDING;
61
    }
62
63
    public function isSettled(): bool
64
    {
65
        return $this->state === self::SETTLED;
66
    }
67
68
    public function isCancelled(): bool
69
    {
70
        return $this->state === self::CANCELLED;
71
    }
72
73
    public function __toString(): string
74
    {
75
        return (string)$this->state;
76
    }
77
78
    private function __construct(?string $state = null)
79
    {
80
        Assertion::nullOrinArray($state, self::STATES);
81
        $this->state = $state;
82
    }
83
}
84