Skip to content

Commit

Permalink
Updated Rector to commit 93bccca72e6a617d679bda6d49cdec76859b7d91
Browse files Browse the repository at this point in the history
rectorphp/rector-src@93bccca Fix message handler removal in RemoveUnusedPublicMethodParameterRector (#6001)
  • Loading branch information
TomasVotruba committed Jun 22, 2024
1 parent 4950e4b commit 7e1af3a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Rector\DeadCode\NodeManipulator\ClassMethodParamRemover;
use Rector\DeadCode\NodeManipulator\VariadicFunctionLikeDetector;
use Rector\NodeAnalyzer\MagicClassMethodAnalyzer;
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand All @@ -33,11 +34,17 @@ final class RemoveUnusedPublicMethodParameterRector extends AbstractRector
* @var \Rector\NodeAnalyzer\MagicClassMethodAnalyzer
*/
private $magicClassMethodAnalyzer;
public function __construct(VariadicFunctionLikeDetector $variadicFunctionLikeDetector, ClassMethodParamRemover $classMethodParamRemover, MagicClassMethodAnalyzer $magicClassMethodAnalyzer)
/**
* @readonly
* @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer
*/
private $phpAttributeAnalyzer;
public function __construct(VariadicFunctionLikeDetector $variadicFunctionLikeDetector, ClassMethodParamRemover $classMethodParamRemover, MagicClassMethodAnalyzer $magicClassMethodAnalyzer, PhpAttributeAnalyzer $phpAttributeAnalyzer)
{
$this->variadicFunctionLikeDetector = $variadicFunctionLikeDetector;
$this->classMethodParamRemover = $classMethodParamRemover;
$this->magicClassMethodAnalyzer = $magicClassMethodAnalyzer;
$this->phpAttributeAnalyzer = $phpAttributeAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
Expand Down Expand Up @@ -73,22 +80,13 @@ public function getNodeTypes() : array
*/
public function refactor(Node $node) : ?Node
{
// may has child, or override parent that needs follow signature
// may have child, or override parent that needs to follow the signature
if (!$node->isFinal() || $node->extends instanceof FullyQualified || $node->implements !== []) {
return null;
}
$hasChanged = \false;
foreach ($node->getMethods() as $classMethod) {
if (!$classMethod->isPublic()) {
continue;
}
if ($classMethod->params === []) {
continue;
}
if ($this->magicClassMethodAnalyzer->isUnsafeOverridden($classMethod)) {
continue;
}
if ($this->variadicFunctionLikeDetector->isVariadic($classMethod)) {
if ($this->shouldSkipClassMethod($classMethod, $node)) {
continue;
}
$changedMethod = $this->classMethodParamRemover->processRemoveParams($classMethod);
Expand All @@ -102,4 +100,22 @@ public function refactor(Node $node) : ?Node
}
return null;
}
private function shouldSkipClassMethod(ClassMethod $classMethod, Class_ $class) : bool
{
// private method is handled by different rule
if (!$classMethod->isPublic()) {
return \true;
}
if ($classMethod->params === []) {
return \true;
}
// parameter is required for contract coupling
if ($this->isName($classMethod->name, '__invoke') && $this->phpAttributeAnalyzer->hasPhpAttribute($class, 'Symfony\\Component\\Messenger\\Attribute\\AsMessageHandler')) {
return \true;
}
if ($this->magicClassMethodAnalyzer->isUnsafeOverridden($classMethod)) {
return \true;
}
return $this->variadicFunctionLikeDetector->isVariadic($classMethod);
}
}
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '657bf470b6450ad4f0ee29ea3ec1257c6e975be1';
public const PACKAGE_VERSION = '93bccca72e6a617d679bda6d49cdec76859b7d91';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-06-21 15:48:13';
public const RELEASE_DATE = '2024-06-22 03:21:11';
/**
* @var int
*/
Expand Down

0 comments on commit 7e1af3a

Please sign in to comment.