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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ final class ShortNameResolverTest extends AbstractLazyTestCase

protected function setUp(): void
{
// @todo let dynamic source locator know about parsed files
parent::setUp();

$this->shortNameResolver = $this->make(ShortNameResolver::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if ($node->params === []) {
return null;
}

// has params with at least one missing type
if (! $this->hasAtLeastOneParamWithoutType($node)) {
return null;
}

if ($node instanceof ClassMethod && $this->shouldSkipClassMethod($node)) {
return null;
}
Expand All @@ -116,7 +125,17 @@ public function refactor(Node $node): ?Node
[StaticCall::class, MethodCall::class, FuncCall::class]
);

$hasChanged = $this->refactorFunctionLike($node, $callers);
// keep only callers with args
$callersWithArgs = array_filter(
$callers,
fn (StaticCall|MethodCall|FuncCall $caller): bool => $caller->args !== []
);

if ($callersWithArgs === []) {
return null;
}

$hasChanged = $this->refactorFunctionLike($node, $callersWithArgs);
if ($hasChanged) {
return $node;
}
Expand All @@ -126,10 +145,6 @@ public function refactor(Node $node): ?Node

private function shouldSkipClassMethod(ClassMethod $classMethod): bool
{
if ($classMethod->params === []) {
return true;
}

$isMissingParameterTypes = false;
foreach ($classMethod->params as $param) {
if ($param->type instanceof Node) {
Expand Down Expand Up @@ -218,4 +233,15 @@ private function refactorFunctionLike(

return $hasChanged;
}

private function hasAtLeastOneParamWithoutType(ClassMethod|Function_|Closure|ArrowFunction $functionLike): bool
{
foreach ($functionLike->params as $param) {
if (! $param->type instanceof Node) {
return true;
}
}

return false;
}
}