Skip to content

Commit e99fc17

Browse files
committed
final protected is more better to prevent to override
1 parent f30006f commit e99fc17

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Enum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function __toString(): string
8181
* @throws LogicException Enums are not cloneable
8282
* because instances are implemented as singletons
8383
*/
84-
private function __clone()
84+
final protected function __clone()
8585
{
8686
throw new LogicException('Enums are not cloneable');
8787
}

tests/MabeEnumTest/EnumTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public function testGetNamesConstantsNotDetected(): void
245245
$this->assertSame($expectedNames[$i], $names[$i]);
246246
}
247247
}
248-
248+
249249
public function testGetOrdinals(): void
250250
{
251251
$constants = EnumInheritance::getConstants();
@@ -376,7 +376,8 @@ public function testCloneNotCallableAndThrowsLogicException(): void
376376

377377
$reflectionClass = new ReflectionClass($enum);
378378
$reflectionMethod = $reflectionClass->getMethod('__clone');
379-
$this->assertTrue($reflectionMethod->isPrivate(), 'The method __clone must be private');
379+
$this->assertTrue($reflectionMethod->isProtected(), 'The method __clone must be protected');
380+
$this->assertTrue($reflectionMethod->isFinal(), 'The method __clone must be final');
380381

381382
$reflectionMethod->setAccessible(true);
382383
$this->expectException(LogicException::class);
@@ -431,7 +432,7 @@ public function testConstVisibility(): void
431432
'PUB' => ConstVisibilityEnum::PUB,
432433
), $constants);
433434
}
434-
435+
435436
public function testConstVisibilityExtended(): void
436437
{
437438
$constants = ConstVisibilityEnumExtended::getConstants();

0 commit comments

Comments
 (0)