Total Complexity | 6 |
Total Lines | 50 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class ArticleStatus |
||
10 | { |
||
11 | public const string UNDER_CONSTRUCTION = 'UNDER CONSTRUCTION'; |
||
|
|||
12 | public const string PUBLISHED = 'PUBLISHED'; |
||
13 | public const string CANCELED = 'CANCELED'; |
||
14 | |||
15 | public const array VALUES = [ |
||
16 | self::UNDER_CONSTRUCTION, |
||
17 | self::PUBLISHED, |
||
18 | self::CANCELED, |
||
19 | ]; |
||
20 | |||
21 | private string $value; |
||
22 | |||
23 | public function __construct(string $value) |
||
24 | { |
||
25 | self::inArray($value); |
||
26 | |||
27 | $this->value = $value; |
||
28 | } |
||
29 | |||
30 | public static function inArray(string $value): void |
||
31 | { |
||
32 | Assert::inArray($value, self::VALUES); |
||
33 | } |
||
34 | |||
35 | public function getValue(): string |
||
36 | { |
||
37 | return $this->value; |
||
38 | } |
||
39 | |||
40 | public function isPublished(): bool |
||
41 | { |
||
42 | return $this->value === self::PUBLISHED; |
||
43 | } |
||
44 | |||
45 | public function __toString(): string |
||
46 | { |
||
47 | return $this->value; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @return string[] |
||
52 | */ |
||
53 | public static function getStatusChoices(): array |
||
54 | { |
||
55 | return [ |
||
56 | self::UNDER_CONSTRUCTION => self::UNDER_CONSTRUCTION, |
||
57 | self::PUBLISHED => self::PUBLISHED, |
||
58 | self::CANCELED => self::CANCELED |
||
59 | ]; |
||
62 |