Passed
Branch develop (caeacb)
by BENARD
05:23
created

GameStatus::isInactive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace VideoGamesRecords\CoreBundle\ValueObject;
4
5
use Webmozart\Assert\Assert;
6
7
class GameStatus
8
{
9
    const STATUS_ACTIVE = 'ACTIF';
10
    const STATUS_INACTIVE = 'INACTIF';
11
12
    public const VALUES = [
13
        self::STATUS_ACTIVE,
14
        self::STATUS_INACTIVE,
15
    ];
16
17
    private string $value;
18
19
    public function __construct(string $value)
20
    {
21
        self::inArray($value);
22
23
        $this->value = $value;
24
    }
25
26
    public static function inArray(string $value): void
27
    {
28
        Assert::inArray($value, self::VALUES);
29
    }
30
31
    public function getValue(): string
32
    {
33
        return $this->value;
34
    }
35
36
    public function getIndex(): int
37
    {
38
        return array_search($this->value, self::VALUES);
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_search($this->value, self::VALUES) could return the type string which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
39
    }
40
41
    public function __toString(): string
42
    {
43
        return $this->value;
44
    }
45
46
    public function isActive(): bool
47
    {
48
        return self::STATUS_ACTIVE === $this->value;
49
    }
50
51
    public function isInactive(): bool
52
    {
53
        return self::STATUS_INACTIVE === $this->value;
54
    }
55
56
    public static function getStatusChoices(): array
57
    {
58
        return [
59
            self::STATUS_ACTIVE => self::STATUS_ACTIVE,
60
            self::STATUS_INACTIVE => self::STATUS_INACTIVE,
61
        ];
62
    }
63
}