diff --git a/composer.json b/composer.json index 632c97b2ca9..bb7399ad78b 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,7 @@ "rector/type-perfect": "^2.1", "shipmonk/composer-dependency-analyser": "^1.8", "symplify/phpstan-extensions": "^12.0.2", - "symplify/phpstan-rules": "^14.8", + "symplify/phpstan-rules": "^14.8.4", "symplify/vendor-patches": "^11.5", "tomasvotruba/class-leak": "^2.0", "tracy/tracy": "^2.11" diff --git a/rules/Php85/Rector/FuncCall/RemoveFinfoBufferContextArgRector.php b/rules/Php85/Rector/FuncCall/RemoveFinfoBufferContextArgRector.php index 70604712e08..17ce17e29e2 100644 --- a/rules/Php85/Rector/FuncCall/RemoveFinfoBufferContextArgRector.php +++ b/rules/Php85/Rector/FuncCall/RemoveFinfoBufferContextArgRector.php @@ -5,8 +5,6 @@ namespace Rector\Php85\Rector\FuncCall; use PhpParser\Node; -use PhpParser\Node\Arg; -use PhpParser\Node\Expr\CallLike; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Identifier; @@ -58,6 +56,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { + if ($node->isFirstClassCallable()) { + return null; + } + if ($node instanceof FuncCall && ! $this->isName($node->name, 'finfo_buffer')) { return null; } @@ -82,10 +84,7 @@ public function provideMinPhpVersion(): int return PhpVersionFeature::DEPRECATE_FINFO_BUFFER_CONTEXT; } - /** - * @param FuncCall|MethodCall $callLike - */ - private function removeContextArg(CallLike $callLike): bool + private function removeContextArg(FuncCall|MethodCall $callLike): bool { // In `finfo::buffer` method calls, the first parameter, compared to `finfo_buffer`, does not exist. $methodArgCorrection = 0; @@ -97,15 +96,7 @@ private function removeContextArg(CallLike $callLike): bool return false; } - // Cannot handle variadic args - foreach ($callLike->args as $position => $arg) { - if (! $arg instanceof Arg) { - return false; - } - } - - /** @var array $args */ - $args = $callLike->args; + $args = $callLike->getArgs(); // Argument 3 ($flags) and argument 4 ($context) are optional, thus named parameters must be considered if (! $this->argsAnalyzer->hasNamedArg($args)) { @@ -119,7 +110,7 @@ private function removeContextArg(CallLike $callLike): bool } foreach ($args as $position => $arg) { - if ($arg->name instanceof Identifier && $arg->name->name === 'context') { + if ($arg->name instanceof Identifier && $this->isName($arg->name, 'context')) { unset($callLike->args[$position]); return true;