Skip to content

Commit 71529cb

Browse files
committed
refactor: adds final to methods
1 parent 189c478 commit 71529cb

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

src/Common/AbstractEnum.php

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ abstract class AbstractEnum
5858
* @param string|int $value The enum value
5959
* @param string $name The constant name
6060
*/
61-
private function __construct($value, string $name)
61+
final private function __construct($value, string $name)
6262
{
6363
$this->value = $value;
6464
$this->name = $name;
@@ -71,7 +71,7 @@ private function __construct($value, string $name)
7171
* @return mixed
7272
* @throws BadMethodCallException If property doesn't exist
7373
*/
74-
public function __get(string $property)
74+
final public function __get(string $property)
7575
{
7676
if ($property === 'value' || $property === 'name') {
7777
return $this->$property;
@@ -89,7 +89,7 @@ public function __get(string $property)
8989
* @param mixed $value The value to set
9090
* @throws BadMethodCallException Always, as enum properties are read-only
9191
*/
92-
public function __set(string $property, $value): void
92+
final public function __set(string $property, $value): void
9393
{
9494
throw new BadMethodCallException(
9595
sprintf('Cannot modify property %s::%s - enum properties are read-only', static::class, $property)
@@ -103,7 +103,7 @@ public function __set(string $property, $value): void
103103
* @return static
104104
* @throws InvalidArgumentException If the value is not valid
105105
*/
106-
public static function from($value): self
106+
final public static function from($value): self
107107
{
108108
$instance = self::tryFrom($value);
109109
if ($instance === null) {
@@ -120,7 +120,7 @@ public static function from($value): self
120120
* @param string|int $value The enum value
121121
* @return static|null
122122
*/
123-
public static function tryFrom($value): ?self
123+
final public static function tryFrom($value): ?self
124124
{
125125
$constants = self::getConstants();
126126
foreach ($constants as $name => $constantValue) {
@@ -136,7 +136,7 @@ public static function tryFrom($value): ?self
136136
*
137137
* @return static[]
138138
*/
139-
public static function cases(): array
139+
final public static function cases(): array
140140
{
141141
$cases = [];
142142
$constants = self::getConstants();
@@ -152,7 +152,7 @@ public static function cases(): array
152152
* @param string|int|self $other The value or enum to compare
153153
* @return bool
154154
*/
155-
public function equals($other): bool
155+
final public function equals($other): bool
156156
{
157157
if ($other instanceof self) {
158158
return $this->is($other);
@@ -167,7 +167,7 @@ public function equals($other): bool
167167
* @param self $other The other enum to compare
168168
* @return bool
169169
*/
170-
public function is(self $other): bool
170+
final public function is(self $other): bool
171171
{
172172
return $this === $other; // Since we're using singletons, we can use identity comparison
173173
}
@@ -177,7 +177,7 @@ public function is(self $other): bool
177177
*
178178
* @return array<string, string|int>
179179
*/
180-
public static function getValues(): array
180+
final public static function getValues(): array
181181
{
182182
return self::getConstants();
183183
}
@@ -188,31 +188,17 @@ public static function getValues(): array
188188
* @param string|int $value The value to check
189189
* @return bool
190190
*/
191-
public static function isValidValue($value): bool
191+
final public static function isValidValue($value): bool
192192
{
193193
return in_array($value, self::getValues(), true);
194194
}
195195

196-
/**
197-
* Create an enum instance from a value (deprecated, use from() instead)
198-
*
199-
* @param string|int $value The enum value
200-
* @return static
201-
* @throws InvalidArgumentException If the value is not valid
202-
* @deprecated Use from() method instead
203-
*/
204-
public static function fromValue($value): self
205-
{
206-
return self::from($value);
207-
}
208-
209196
/**
210197
* Get or create a singleton instance for the given value and name
211198
*
212199
* @param string|int $value The enum value
213200
* @param string $name The constant name
214201
* @return static
215-
* @phpstan-return static
216202
*/
217203
private static function getInstance($value, string $name): self
218204
{
@@ -237,7 +223,7 @@ private static function getInstance($value, string $name): self
237223
* @return array<string, string|int>
238224
* @throws \RuntimeException If invalid constant found
239225
*/
240-
protected static function getConstants(): array
226+
final protected static function getConstants(): array
241227
{
242228
$className = static::class;
243229

@@ -289,7 +275,7 @@ protected static function getConstants(): array
289275
* @return bool
290276
* @throws BadMethodCallException If the method doesn't exist
291277
*/
292-
public function __call(string $name, array $arguments)
278+
final public function __call(string $name, array $arguments): bool
293279
{
294280
// Handle is* methods
295281
if (strpos($name, 'is') === 0) {
@@ -314,7 +300,7 @@ public function __call(string $name, array $arguments)
314300
* @return static
315301
* @throws BadMethodCallException If the method doesn't exist
316302
*/
317-
public static function __callStatic(string $name, array $arguments)
303+
final public static function __callStatic(string $name, array $arguments): self
318304
{
319305
$constantName = self::camelCaseToConstant($name);
320306
$constants = self::getConstants();
@@ -348,7 +334,7 @@ private static function camelCaseToConstant(string $camelCase): string
348334
*
349335
* @return string
350336
*/
351-
public function __toString(): string
337+
final public function __toString(): string
352338
{
353339
return (string) $this->value;
354340
}

0 commit comments

Comments
 (0)