Skip to content

Commit

Permalink
[Php71] Skip First Class Callable on RemoveExtraParametersRector (#2622)
Browse files Browse the repository at this point in the history
* [Php71] Skip First Class Callable on RemoveExtraParametersRector

* crash on Expression directly

* Fixed 🎉
  • Loading branch information
samsonasik committed Jul 3, 2022
1 parent dfc6e1d commit 8eedf18
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Enum_;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Finally_;
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\Node\Stmt\Interface_;
Expand Down Expand Up @@ -109,6 +110,10 @@ public function processNodes(
$isScopeRefreshing,
$smartFileInfo
): void {
if ($node instanceof Expression) {
$node->expr->setAttribute(AttributeKey::SCOPE, $mutatingScope);
}

if ($node instanceof Ternary) {
$this->processTernary($node, $mutatingScope);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

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

final class SkipFirstClassCallable
{
public function getFunctions(): array
{
return [
new TwigFunction('app_seo_title', $this->getTitle(...), [
'is_safe' => ['html'],
]),
];
}

public function getTitle(): string
{
return 'title';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

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

final class SkipFirstClassCallableDirectExpression
{
public function getFunctions()
{
$this->getTitle(...);
}

public function getTitle(): string
{
return 'title';
}
}
4 changes: 4 additions & 0 deletions rules/Php71/Rector/FuncCall/RemoveExtraParametersRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public function refactor(Node $node): ?Node

$maximumAllowedParameterCount = $this->resolveMaximumAllowedParameterCount($functionLikeReflection);
//
if ($node->isFirstClassCallable()) {
return null;
}

$numberOfArguments = count($node->getRawArgs());
if ($numberOfArguments <= $maximumAllowedParameterCount) {
return null;
Expand Down

0 comments on commit 8eedf18

Please sign in to comment.