Skip to content

Commit

Permalink
Ensure check isFirstClassCallable() before getArgs() call on CallLike (
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik authored Sep 29, 2024
1 parent 3f726bd commit daac9f0
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ public function refactor(Node $node): ?Node
$classReflection = $this->reflectionResolver->resolveClassReflection($node);
if ($classReflection instanceof ClassReflection && $classReflection->hasNativeMethod($methodName)) {
$method = $classReflection->getNativeMethod($methodName);

if ($node->isFirstClassCallable()) {
return null;
}

if ($method->isStatic()) {
$hasChanged = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

$hasChanged = true;
return $this->nodeFactory->createMethodCall('this', $methodName, $node->getArgs());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public function refactor(Node $node): MethodCall|StaticCall|null
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

if (count($node->getArgs()) < 2) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

$args = $node->getArgs();

$firstValue = $args[0]->value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public function refactor(Node $node): MethodCall|null
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

$firstArg = $node->getArgs()[0];

// skip as most likely nested array of unique values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public function refactor(Node $node): MethodCall|null
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

if (count($node->getArgs()) !== 1) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ private function matchAndRefactorExpectsMethodCall(Expression $expression): Meth
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

$firstArg = $node->getArgs()[0];
if (! $firstArg->value instanceof MethodCall && ! $firstArg->value instanceof StaticCall) {
return null;
Expand Down

0 comments on commit daac9f0

Please sign in to comment.