-
-
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.
[DowngradePhp72] Skip implements built in interface method on Downgra…
…deParameterTypeWideningRector (#766) Co-authored-by: Bobab12 <bobab12@users.noreply.github.com>
- Loading branch information
1 parent
5b5b94b
commit 47ad54d
Showing
4 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...DowngradeParameterTypeWideningRector/Fixture/indirect_implements_native_interface.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,42 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\Fixture; | ||
|
||
abstract class ParentClass implements \SplObserver | ||
{ | ||
public function update(\SplSubject $subject): void | ||
{ | ||
} | ||
} | ||
|
||
class IndirectImplementsNativeInterface extends ParentClass | ||
{ | ||
public function update($subject): void | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\Fixture; | ||
|
||
abstract class ParentClass implements \SplObserver | ||
{ | ||
/** | ||
* @param \SplSubject $subject | ||
*/ | ||
public function update($subject): void | ||
{ | ||
} | ||
} | ||
|
||
class IndirectImplementsNativeInterface extends ParentClass | ||
{ | ||
public function update($subject): void | ||
{ | ||
} | ||
} | ||
|
||
?> |
10 changes: 10 additions & 0 deletions
10
...or/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/skip_native_interface.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\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\Fixture; | ||
|
||
class SkipNativeInterface implements \SplObserver | ||
{ | ||
public function update(\SplSubject $subject): void | ||
{ | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
rules/DowngradePhp72/NodeAnalyzer/BuiltInMethodAnalyzer.php
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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\DowngradePhp72\NodeAnalyzer; | ||
|
||
use PhpParser\Node\Stmt\ClassMethod; | ||
use PHPStan\Reflection\ClassReflection; | ||
use Rector\FamilyTree\NodeAnalyzer\ClassChildAnalyzer; | ||
use Rector\NodeNameResolver\NodeNameResolver; | ||
|
||
final class BuiltInMethodAnalyzer | ||
{ | ||
public function __construct(private NodeNameResolver $nodeNameResolver, private ClassChildAnalyzer $classChildAnalyzer) | ||
{ | ||
} | ||
|
||
public function isImplementsBuiltInInterface(ClassReflection $classReflection, ClassMethod $classMethod): bool | ||
{ | ||
if (! $classReflection->isClass()) { | ||
return false; | ||
} | ||
|
||
$methodName = $this->nodeNameResolver->getName($classMethod); | ||
if ($this->classChildAnalyzer->hasChildClassMethod($classReflection, $methodName)) { | ||
return false; | ||
} | ||
|
||
foreach ($classReflection->getInterfaces() as $interfaceReflection) { | ||
if (! $interfaceReflection->isBuiltIn()) { | ||
continue; | ||
} | ||
|
||
if (! $interfaceReflection->hasMethod($methodName)) { | ||
continue; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
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