Skip to content

Commit 848bb4a

Browse files
authored
Tidy up RemoveFinfoBufferContextArgRector (#7648)
* bump phpstan rules * tidy up RemoveFinfoBufferContextArgRector
1 parent 4dce718 commit 848bb4a

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"rector/type-perfect": "^2.1",
5757
"shipmonk/composer-dependency-analyser": "^1.8",
5858
"symplify/phpstan-extensions": "^12.0.2",
59-
"symplify/phpstan-rules": "^14.8",
59+
"symplify/phpstan-rules": "^14.8.4",
6060
"symplify/vendor-patches": "^11.5",
6161
"tomasvotruba/class-leak": "^2.0",
6262
"tracy/tracy": "^2.11"

rules/Php85/Rector/FuncCall/RemoveFinfoBufferContextArgRector.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
namespace Rector\Php85\Rector\FuncCall;
66

77
use PhpParser\Node;
8-
use PhpParser\Node\Arg;
9-
use PhpParser\Node\Expr\CallLike;
108
use PhpParser\Node\Expr\FuncCall;
119
use PhpParser\Node\Expr\MethodCall;
1210
use PhpParser\Node\Identifier;
@@ -58,6 +56,10 @@ public function getNodeTypes(): array
5856
*/
5957
public function refactor(Node $node): ?Node
6058
{
59+
if ($node->isFirstClassCallable()) {
60+
return null;
61+
}
62+
6163
if ($node instanceof FuncCall && ! $this->isName($node->name, 'finfo_buffer')) {
6264
return null;
6365
}
@@ -82,10 +84,7 @@ public function provideMinPhpVersion(): int
8284
return PhpVersionFeature::DEPRECATE_FINFO_BUFFER_CONTEXT;
8385
}
8486

85-
/**
86-
* @param FuncCall|MethodCall $callLike
87-
*/
88-
private function removeContextArg(CallLike $callLike): bool
87+
private function removeContextArg(FuncCall|MethodCall $callLike): bool
8988
{
9089
// In `finfo::buffer` method calls, the first parameter, compared to `finfo_buffer`, does not exist.
9190
$methodArgCorrection = 0;
@@ -97,15 +96,7 @@ private function removeContextArg(CallLike $callLike): bool
9796
return false;
9897
}
9998

100-
// Cannot handle variadic args
101-
foreach ($callLike->args as $position => $arg) {
102-
if (! $arg instanceof Arg) {
103-
return false;
104-
}
105-
}
106-
107-
/** @var array<Arg> $args */
108-
$args = $callLike->args;
99+
$args = $callLike->getArgs();
109100

110101
// Argument 3 ($flags) and argument 4 ($context) are optional, thus named parameters must be considered
111102
if (! $this->argsAnalyzer->hasNamedArg($args)) {
@@ -119,7 +110,7 @@ private function removeContextArg(CallLike $callLike): bool
119110
}
120111

121112
foreach ($args as $position => $arg) {
122-
if ($arg->name instanceof Identifier && $arg->name->name === 'context') {
113+
if ($arg->name instanceof Identifier && $this->isName($arg->name, 'context')) {
123114
unset($callLike->args[$position]);
124115

125116
return true;

0 commit comments

Comments
 (0)