Passed
Branch develop (a13b53)
by BENARD
12:48
created

ChartStatus::getIndex()   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;
0 ignored issues
show
Bug introduced by
The type Webmozart\Assert\Assert was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
class ChartStatus
8
{
9
    const STATUS_NORMAL = 'NORMAL';
10
    const STATUS_MAJ = 'MAJ';
11
    const STATUS_ERROR = 'ERROR';
12
13
    public const VALUES = [
14
        self::STATUS_NORMAL => self::STATUS_NORMAL,
15
        self::STATUS_MAJ => self::STATUS_MAJ,
16
        self::STATUS_ERROR => self::STATUS_ERROR,
17
    ];
18
19
    private string $value;
20
21
    public function __construct(string $value)
22
    {
23
        self::inArray($value);
24
25
        $this->value = $value;
26
    }
27
28
    public static function inArray(string $value): void
29
    {
30
        Assert::inArray($value, self::VALUES);
31
    }
32
33
    public function getValue(): string
34
    {
35
        return $this->value;
36
    }
37
38
    public function getIndex(): int
39
    {
40
        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...
41
    }
42
43
    public function __toString(): string
44
    {
45
        return $this->value;
46
    }
47
48
    public function isNormal(): bool
49
    {
50
        return self::STATUS_NORMAL === $this->value;
51
    }
52
53
    public function isMaj(): bool
54
    {
55
        return self::STATUS_MAJ === $this->value;
56
    }
57
58
    public function isError(): bool
59
    {
60
        return self::STATUS_ERROR === $this->value;
61
    }
62
63
    public static function getStatusChoices(): array
64
    {
65
        return [
66
            'label.chart.status.normal' => self::STATUS_NORMAL,
67
            'label.chart.status.maj' => self::STATUS_MAJ,
68
            'label.chart.status.error' => self::STATUS_ERROR,
69
        ];
70
    }
71
}