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
Expand Up @@ -28,6 +28,26 @@ final class RemoveUnusedParameterRector extends AbstractRector
*/
private $classMethodManipulator;

/**
* @var string[]
*/
private $magicMethods = [
'__call',
'__callStatic',
'__clone',
'__debugInfo',
'__destruct',
'__get',
'__invoke',
'__isset',
'__set',
'__set_state',
'__sleep',
'__toString',
'__unset',
'__wakeup',
];

public function __construct(ClassManipulator $classManipulator, ClassMethodManipulator $classMethodManipulator)
{
$this->classManipulator = $classManipulator;
Expand Down Expand Up @@ -83,6 +103,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($this->isNames($node, $this->magicMethods)) {
return null;
}

$class = $this->getName($classNode);
if ($class === null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

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

class SomeClassWithMagicMethods
{
public function __call($one, $two)
{
}

public function __get($one)
{
}

public function __set($one, $value)
{
}

public function __isset($one)
{
}

public static function __callStatic($one, $two)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function test(): void
__DIR__ . '/Fixture/parent_required.php.inc',
__DIR__ . '/Fixture/in_between_parameter.php.inc',
__DIR__ . '/Fixture/compact.php.inc',
__DIR__ . '/Fixture/keep_magic_methods_param.php.inc',
]);
}

Expand Down