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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 7 additions & 16 deletions rules/Php85/Rector/FuncCall/RemoveFinfoBufferContextArgRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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<Arg> $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)) {
Expand All @@ -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;
Expand Down