Skip to content
Merged
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 @@ -107,20 +107,29 @@ public function refactor(Node $node): ?Node
}

// special case for collections
$hasChangedCollection = false;
if ($this->formCollectionAnalyzer->isCollectionType($node)) {
$this->refactorCollectionOptions($node);
$hasChangedCollection = $this->refactorCollectionOptions($node);
}

return $this->formInstanceToFormClassConstFetchConverter->processNewInstance($node, 1, 2);
$newMethodCall = $this->formInstanceToFormClassConstFetchConverter->processNewInstance($node, 1, 2);
if ($newMethodCall instanceof MethodCall) {
return $newMethodCall;
}

// collection options were mutated in place, report the change via the return value
return $hasChangedCollection ? $node : null;
}

private function refactorCollectionOptions(MethodCall $methodCall): void
private function refactorCollectionOptions(MethodCall $methodCall): bool
{
$optionsArray = $this->formOptionsArrayMatcher->match($methodCall);
if (! $optionsArray instanceof Array_) {
return;
return false;
}

$hasChanged = false;

foreach ($optionsArray->items as $arrayItem) {
if (! $arrayItem instanceof ArrayItem) {
continue;
Expand All @@ -145,6 +154,9 @@ private function refactorCollectionOptions(MethodCall $methodCall): void
}

$arrayItem->value = $this->nodeFactory->createClassConstReference($newClass->toString());
$hasChanged = true;
}

return $hasChanged;
}
}
Loading