-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Php80] Handle crash Property ReflectionEnum::$betterReflectionClass …
…does not exist on AddParamBasedOnParentClassMethodRector on Enum usage (#4758) * [Php80] Handle crash Property ReflectionEnum::$betterReflectionClass does not exist on AddParamBasedOnParentClassMethodRector on Enum usage * Fixed 🎉 * Fixed 🎉 * [ci-review] Rector Rectify * [ci-review] Rector Rectify * clean up comment --------- Co-authored-by: GitHub Action <actions@github.com>
- Loading branch information
1 parent
e9ff73f
commit 0bdace5
Showing
5 changed files
with
61 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...Php80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector/Fixture/skip_enum.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Fixture; | ||
|
||
enum SkipEnum: string | ||
{ | ||
case EN = 'en'; | ||
|
||
public static function ui(): array | ||
{ | ||
return [ | ||
self::EN, | ||
]; | ||
} | ||
|
||
public static function dynamicContent(): array | ||
{ | ||
return self::cases(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Reflection; | ||
|
||
use ReflectionEnum; | ||
use PHPStan\Reflection\ClassReflection; | ||
use Rector\Core\Util\Reflection\PrivatesAccessor; | ||
use PHPStan\BetterReflection\Reflection\ReflectionClass; | ||
|
||
final class ClassReflectionAnalyzer | ||
{ | ||
public function __construct(private readonly PrivatesAccessor $privatesAccessor) | ||
{ | ||
} | ||
|
||
public function resolveParentClassName(ClassReflection $classReflection): ?string | ||
{ | ||
$nativeReflection = $classReflection->getNativeReflection(); | ||
if ($nativeReflection instanceof ReflectionEnum) { | ||
return null; | ||
} | ||
|
||
$betterReflectionClass = $this->privatesAccessor->getPrivateProperty( | ||
$nativeReflection, | ||
'betterReflectionClass' | ||
); | ||
/** @var ReflectionClass $betterReflectionClass */ | ||
return $betterReflectionClass->getParentClassName(); | ||
} | ||
} |