-
-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Privatization] Skip parent class unknown on PrivatizeFinalClassMetho…
…dRector (#4671)
- Loading branch information
1 parent
625fccc
commit f45662a
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...tor/ClassMethod/PrivatizeFinalClassMethodRector/Fixture/skip_unknown_parent_class.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,10 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeFinalClassMethodRector\Fixture; | ||
|
||
final class SkipUnknownParentClass extends SomeUnknownParent | ||
{ | ||
protected function someMethod() | ||
{ | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Privatization\Guard; | ||
|
||
use PhpParser\Node\Name\FullyQualified; | ||
use PhpParser\Node\Stmt\Class_; | ||
use PHPStan\Reflection\ReflectionProvider; | ||
|
||
/** | ||
* Verify whether Class_'s method or property allowed to be overridden by verify class parent or implements exists | ||
*/ | ||
final class OverrideByParentClassGuard | ||
{ | ||
public function __construct(private readonly ReflectionProvider $reflectionProvider) | ||
{ | ||
} | ||
|
||
public function isLegal(Class_ $class): bool | ||
{ | ||
if ($class->extends instanceof FullyQualified && ! $this->reflectionProvider->hasClass($class->extends->toString())) { | ||
return false; | ||
} | ||
|
||
foreach ($class->implements as $implement) { | ||
if (! $this->reflectionProvider->hasClass($implement->toString())) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
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