mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-29 22:23:30 +00:00
[CodingStyle] Skip override parent method on UnSpreadOperatorRector (#2223)
* Add failing test fixture for UnSpreadOperatorRector # Failing Test for UnSpreadOperatorRector Based on https://getrector.org/demo/f83cf736-ff98-4bc4-86a8-4611c8dd8804 * Fixes #2220 * fixture * [ci-review] Rector Rectify Co-authored-by: Alies Lapatsin <lptn@users.noreply.github.com> Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
e978256f4d
commit
6327904617
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\CodingStyle\Rector\ClassMethod\UnSpreadOperatorRector\Fixture;
|
||||
|
||||
use Rector\Tests\CodingStyle\Rector\ClassMethod\UnSpreadOperatorRector\Source\ParentClass;
|
||||
|
||||
final class SkipOverrideMethod extends ParentClass
|
||||
{
|
||||
public static function make(... $arguments): static
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\CodingStyle\Rector\ClassMethod\UnSpreadOperatorRector\Source;
|
||||
|
||||
class ParentClass
|
||||
{
|
||||
public static function make(... $arguments): static
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
}
|
|
@ -10,14 +10,13 @@ use PhpParser\Node\Expr\Array_;
|
|||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Reflection\MethodReflection;
|
||||
use Rector\CodingStyle\NodeAnalyzer\SpreadVariablesCollector;
|
||||
use Rector\CodingStyle\Reflection\VendorLocationDetector;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\FamilyTree\NodeAnalyzer\ClassChildAnalyzer;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
|
@ -29,7 +28,8 @@ final class UnSpreadOperatorRector extends AbstractRector
|
|||
public function __construct(
|
||||
private readonly SpreadVariablesCollector $spreadVariablesCollector,
|
||||
private readonly ReflectionResolver $reflectionResolver,
|
||||
private readonly VendorLocationDetector $vendorLocationDetector
|
||||
private readonly VendorLocationDetector $vendorLocationDetector,
|
||||
private readonly ClassChildAnalyzer $classChildAnalyzer
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,17 @@ CODE_SAMPLE
|
|||
|
||||
private function refactorClassMethod(ClassMethod $classMethod): ?ClassMethod
|
||||
{
|
||||
if ($this->isInPHPUnitTestCase($classMethod)) {
|
||||
$classReflection = $this->reflectionResolver->resolveClassReflection($classMethod);
|
||||
if (! $classReflection instanceof ClassReflection) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->isInPHPUnitTestCase($classReflection, $classMethod)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$methodName = $this->nodeNameResolver->getName($classMethod);
|
||||
if ($this->classChildAnalyzer->hasParentClassMethod($classReflection, $methodName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -216,22 +226,12 @@ CODE_SAMPLE
|
|||
return false;
|
||||
}
|
||||
|
||||
private function isInPHPUnitTestCase(ClassMethod $classMethod): bool
|
||||
private function isInPHPUnitTestCase(ClassReflection $classReflection, ClassMethod $classMethod): bool
|
||||
{
|
||||
$scope = $classMethod->getAttribute(AttributeKey::SCOPE);
|
||||
if (! $scope instanceof Scope) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $classMethod->isPublic()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$classReflection = $scope->getClassReflection();
|
||||
if (! $classReflection instanceof ClassReflection) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $classReflection->isSubclassOf('PHPUnit\Framework\TestCase');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user