Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodingStyle] Skip test method in UnSpreadOperatorRector #1106

Merged
merged 1 commit into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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