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

GameStatus   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 18
c 1
b 0
f 0
dl 0
loc 54
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A inArray() 0 3 1
A getIndex() 0 3 1
A getStatusChoices() 0 5 1
A __toString() 0 3 1
A isInactive() 0 3 1
A __construct() 0 5 1
A isActive() 0 3 1
A getValue() 0 3 1
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
}