Skip to content
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,16 @@
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector\Fixture;

use Rector\Contract\Rector\RectorInterface;

#[\Attribute]
final class SkipAttributeMarker
{
/**
* @param RectorInterface $someClass
*/
public function __construct(string $someClass)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\DeadCode\Rector\ClassMethod;

use PhpParser\Comment\Doc;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
Expand Down Expand Up @@ -91,11 +92,17 @@ public function refactor(Node $node): ?Node

$interfaces = $classReflection->getInterfaces();
foreach ($interfaces as $interface) {
// parameters are contract required → skip
if ($interface->hasNativeMethod(MethodName::CONSTRUCT)) {
return null;
}
}

// attributes can be used as markers
if ($classReflection->isAttributeClass() && $constructorClassMethod->getDocComment() instanceof Doc) {
return null;
}

$changedConstructorClassMethod = $this->classMethodParamRemover->processRemoveParams($constructorClassMethod);
if (! $changedConstructorClassMethod instanceof ClassMethod) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
->withRules([
ClassPropertyAssignToConstructorPromotionRector::class,
RemoveParentDelegatingConstructorRector::class,
]);
]);
Loading