Skip to content

Commit

Permalink
Add IntersectionType direct param type support on self detection on C…
Browse files Browse the repository at this point in the history
…ollectorMetadataPrinter (#7)

* Add IntersectionType direct param type support on self detection on CollectorMetadataPrinter

* Add IntersectionType direct param type support on self detection on CollectorMetadataPrinter
  • Loading branch information
samsonasik authored Jun 14, 2024
1 parent beaa416 commit a8d7852
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Printer/CollectorMetadataPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public function printParamTypesToString(ClassMethod $classMethod, ?string $class
$paramType = new UnionType([$paramType->type, new Identifier('null')]);
}

if ($paramType instanceof UnionType) {
$paramType = $this->resolveSortedUnionType($paramType, $className);
if ($paramType instanceof UnionType || $paramType instanceof NodeIntersectionType) {
$paramType = $this->resolveSortedTypes($paramType, $className);
}

$printedParamType = $this->printerStandard->prettyPrint([$paramType]);
Expand All @@ -110,11 +110,11 @@ private function transformSelfToClassName(Node $node, ?string $className): Node
return new FullyQualified($className);
}

private function resolveSortedUnionType(UnionType $unionType, ?string $className): UnionType
private function resolveSortedTypes(UnionType|NodeIntersectionType $paramType, ?string $className): UnionType|NodeIntersectionType
{
$typeNames = [];

foreach ($unionType->types as $type) {
foreach ($paramType->types as $type) {
if ($type instanceof NodeIntersectionType) {
foreach ($type->types as $intersectionType) {
/** @var Identifier|Name $intersectionType */
Expand All @@ -137,6 +137,10 @@ private function resolveSortedUnionType(UnionType $unionType, ?string $className
$types[] = new Identifier($typeName);
}

if ($paramType instanceof NodeIntersectionType) {
return new NodeIntersectionType($types);
}

return new UnionType($types);
}

Expand Down

0 comments on commit a8d7852

Please sign in to comment.