Completed
Branch master (933e97)
by Torsten
04:46
created

EnumerableStatus   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 57
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2
ccs 14
cts 14
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A fromString() 0 4 1
A options() 0 4 1
A toString() 0 4 1
A isEqual() 0 5 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lej\Component\Domain\Model;
6
7
use Assert\Assert;
8
9
class EnumerableStatus implements Status
10
{
11
    /**
12
     * @var string[]
13
     */
14
    protected $options;
15
16
    /**
17
     * @var string
18
     */
19
    protected $value;
20
21
    /**
22
     * The constructor.
23
     * @param string $value
24
     */
25 9
    public function __construct(string $value)
26
    {
27 9
        Assert::that($value)->notEmpty();
28 7
        Assert::that($value)->choice($this->options());
29 7
        $this->value = $value;
30 7
    }
31
32
    /**
33
     * @param string $value
34
     * @return EnumerableStatus
35
     */
36 1
    public static function fromString(string $value): EnumerableStatus
37
    {
38 1
        return new static($value);
39
    }
40
41
    /**
42
     * @return string[]
43
     */
44 7
    public function options(): array
45
    {
46 7
        return $this->options;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 5
    public function toString(): string
53
    {
54 5
        return $this->value;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 3
    public function isEqual(ValueObject $object): bool
61
    {
62 3
        return $object instanceof static
63 3
            && $object->toString() === $this->toString();
64
    }
65
}
66