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
1 change: 1 addition & 0 deletions ecs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ parameters:
- 'src/Rector/Annotation/RenameAnnotationRector.php'
- 'packages/NetteToSymfony/src/Event/EventInfosFactory.php'
- 'packages/NetteTesterToPHPUnit/src/AssertManipulator.php'
- 'src/PhpParser/Node/Manipulator/CallManipulator.php'

Symplify\CodingStandard\Sniffs\CleanCode\ForbiddenStaticFunctionSniff:
- 'src/Util/*.php'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Rector\Php\Tests\Rector\FuncCall\RemoveExtraParametersRector\Fixture;

use ReflectionClass;

class SkipInvoke
{
public function run($traitMock)
{
$reflectionClass = new ReflectionClass('SomeClass');
$method = $reflectionClass->getMethod('getSetItems');

$method->invoke($traitMock, 'some-param', 4, 5, 6);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function test(): void
__DIR__ . '/Fixture/static_call_parent.php.inc',
__DIR__ . '/Fixture/skip_commented_param_func_get_args.php.inc',
__DIR__ . '/Fixture/skip_call_user_func_array.php.inc',
__DIR__ . '/Fixture/skip_invoke.php.inc',
]);
}

Expand Down
20 changes: 20 additions & 0 deletions src/PhpParser/Node/Manipulator/CallManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public function isVariadic(ReflectionFunctionAbstract $reflectionFunctionAbstrac
return true;
}

if ($this->isVariadicByName($reflectionFunctionAbstract)) {
return true;
}

if ($reflectionFunctionAbstract instanceof ReflectionFunction) {
$functionNode = $this->parsedNodesByType->findFunction($reflectionFunctionAbstract->getName());
if ($functionNode === null) {
Expand Down Expand Up @@ -160,4 +164,20 @@ private function resolveMotherType(Node $callNode): string
{
return $callNode instanceof FuncCall ? Function_::class : ClassMethod::class;
}

/**
* native PHP bug fix
*/
private function isVariadicByName(ReflectionFunctionAbstract $reflectionFunctionAbstract): bool
{
if (! $reflectionFunctionAbstract instanceof ReflectionMethod) {
return false;
}

if ($reflectionFunctionAbstract->getDeclaringClass()->getName() !== 'ReflectionMethod') {
return false;
}

return $reflectionFunctionAbstract->getName() === 'invoke';
}
}