These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Backend\Modules\MediaLibraryImporter\Domain\MediaItemImport; |
||
4 | |||
5 | final class Status |
||
6 | { |
||
7 | const QUEUED = 'queued'; |
||
8 | const IMPORTED = 'imported'; |
||
9 | const EXISTING = 'existing'; |
||
10 | const ERROR = 'error'; |
||
11 | const POSSIBLE_VALUES = [ |
||
12 | self::QUEUED, |
||
13 | self::IMPORTED, |
||
14 | self::EXISTING, |
||
15 | self::ERROR, |
||
16 | ]; |
||
17 | const POSSIBLE_VALUES_FOR_IMPORT = [ |
||
18 | self::QUEUED, |
||
19 | self::ERROR, |
||
20 | ]; |
||
21 | const POSSIBLE_VALUES_FOR_IMPORTED = [ |
||
22 | self::IMPORTED, |
||
23 | self::EXISTING, |
||
24 | ]; |
||
25 | |||
26 | /** @var string */ |
||
27 | private $status; |
||
28 | |||
29 | /** |
||
30 | * @param string $status |
||
31 | */ |
||
32 | View Code Duplication | private function __construct(string $status) |
|
1 ignored issue
–
show
|
|||
33 | { |
||
34 | if (!in_array($status, self::POSSIBLE_VALUES, true)) { |
||
35 | throw new \InvalidArgumentException( |
||
36 | 'Invalid value for the MediaItemImport status. Possible values; ' . implode(',', self::POSSIBLE_VALUES) |
||
37 | ); |
||
38 | } |
||
39 | |||
40 | $this->status = $status; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @param string $status |
||
45 | * @return Status |
||
46 | */ |
||
47 | public static function fromString(string $status): self |
||
48 | { |
||
49 | return new self($status); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | public function __toString(): string |
||
56 | { |
||
57 | return $this->status; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @param Status $status |
||
62 | * @return bool |
||
63 | */ |
||
64 | public function equals(Status $status): bool |
||
65 | { |
||
66 | if (!$status instanceof $this) { |
||
67 | return false; |
||
68 | } |
||
69 | |||
70 | return $status == $this; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @return Status |
||
75 | */ |
||
76 | public static function queued(): self |
||
77 | { |
||
78 | return new self(self::QUEUED); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @return bool |
||
83 | */ |
||
84 | public function isQueued(): bool |
||
85 | { |
||
86 | return $this->equals(self::queued()); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @return Status |
||
91 | */ |
||
92 | public static function imported(): self |
||
93 | { |
||
94 | return new self(self::IMPORTED); |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @return bool |
||
99 | */ |
||
100 | public function isImported(): bool |
||
101 | { |
||
102 | return $this->equals(self::imported()); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @return Status |
||
107 | */ |
||
108 | public static function existing(): self |
||
109 | { |
||
110 | return new self(self::EXISTING); |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * @return bool |
||
115 | */ |
||
116 | public function isExisting(): bool |
||
117 | { |
||
118 | return $this->equals(self::existing()); |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * @return Status |
||
123 | */ |
||
124 | public static function error(): self |
||
125 | { |
||
126 | return new self(self::ERROR); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * @return bool |
||
131 | */ |
||
132 | public function isError(): bool |
||
133 | { |
||
134 | return $this->equals(self::error()); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * @return string |
||
139 | */ |
||
140 | public function getStatus(): string |
||
141 | { |
||
142 | return $this->status; |
||
143 | } |
||
144 | } |
||
145 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.