Skip to content

Commit

Permalink
[CodingStyle] Skip test method in UnSpreadOperatorRector (#1106)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Oct 29, 2021
1 parent 5ca93fd commit 9efb3a5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\ClassMethod\UnSpreadOperatorRector\Fixture;

use PHPUnit\Framework\TestCase;

final class SkipTestMethod extends TestCase
{
public function test(string $name, ...$items)
{
}
}
19 changes: 15 additions & 4 deletions rules/CodingStyle/Rector/ClassMethod/UnSpreadOperatorRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPUnit\Framework\TestCase;
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 Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand Down Expand Up @@ -79,14 +82,22 @@ public function getNodeTypes(): array
public function refactor(Node $node): ?Node
{
if ($node instanceof ClassMethod) {
return $this->processUnspreadOperatorClassMethodParams($node);
return $this->refactorClassMethod($node);
}

return $this->processUnspreadOperatorMethodCallArgs($node);
return $this->refactorMethodCall($node);
}

private function processUnspreadOperatorClassMethodParams(ClassMethod $classMethod): ?ClassMethod
private function refactorClassMethod(ClassMethod $classMethod): ?ClassMethod
{
$scope = $classMethod->getAttribute(AttributeKey::SCOPE);
if ($scope instanceof Scope && $classMethod->isPublic()) {
$classReflection = $scope->getClassReflection();
if ($classReflection->isSubclassOf(TestCase::class)) {
return null;
}
}

$spreadParams = $this->spreadVariablesCollector->resolveFromClassMethod($classMethod);
if ($spreadParams === []) {
return null;
Expand All @@ -101,7 +112,7 @@ private function processUnspreadOperatorClassMethodParams(ClassMethod $classMeth
return $classMethod;
}

private function processUnspreadOperatorMethodCallArgs(MethodCall $methodCall): ?MethodCall
private function refactorMethodCall(MethodCall $methodCall): ?MethodCall
{
$methodReflection = $this->reflectionResolver->resolveMethodReflectionFromMethodCall($methodCall);
if (! $methodReflection instanceof MethodReflection) {
Expand Down

0 comments on commit 9efb3a5

Please sign in to comment.