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
79 changes: 41 additions & 38 deletions src/Type/IntersectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,50 +304,53 @@ public function equals(Type $type): bool
public function describe(VerbosityLevel $level): string
{
return $level->handle(
function () use ($level): string {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract inline callable into separate method

$typeNames = [];
$isList = $this->isList()->yes();
$valueType = null;
foreach ($this->getSortedTypes() as $type) {
if ($isList) {
if ($type instanceof ArrayType || $type instanceof ConstantArrayType) {
$valueType = $type->getIterableValueType();
continue;
}
if ($type instanceof NonEmptyArrayType) {
continue;
}
}
if ($type instanceof AccessoryType) {
continue;
}
$typeNames[] = $type->generalize(GeneralizePrecision::lessSpecific())->describe($level);
fn (): string => $this->describeType($level),
fn (): string => $this->describeItself($level, true),
fn (): string => $this->describeItself($level, false),
);
}

private function describeType(VerbosityLevel $level): string
{
$typeNames = [];
$isList = $this->isList()->yes();
$valueType = null;
foreach ($this->getSortedTypes() as $type) {
if ($isList) {
if ($type instanceof ArrayType || $type instanceof ConstantArrayType) {
$valueType = $type->getIterableValueType();
continue;
}
if ($type instanceof NonEmptyArrayType) {
continue;
}
}
if ($type instanceof AccessoryType) {
continue;
}
$typeNames[] = $type->generalize(GeneralizePrecision::lessSpecific())->describe($level);
}

if ($isList) {
$isMixedValueType = $valueType instanceof MixedType && $valueType->describe(VerbosityLevel::precise()) === 'mixed' && !$valueType->isExplicitMixed();
$innerType = '';
if ($valueType !== null && !$isMixedValueType) {
$innerType = sprintf('<%s>', $valueType->describe($level));
}
if ($isList) {
$isMixedValueType = $valueType instanceof MixedType && $valueType->describe(VerbosityLevel::precise()) === 'mixed' && !$valueType->isExplicitMixed();
$innerType = '';
if ($valueType !== null && !$isMixedValueType) {
$innerType = sprintf('<%s>', $valueType->describe($level));
}

$typeNames[] = 'list' . $innerType;
}
$typeNames[] = 'list' . $innerType;
}

usort($typeNames, static function ($a, $b) {
$cmp = strcasecmp($a, $b);
if ($cmp !== 0) {
return $cmp;
}
usort($typeNames, static function ($a, $b) {
$cmp = strcasecmp($a, $b);
if ($cmp !== 0) {
return $cmp;
}

return $a <=> $b;
});
return $a <=> $b;
});

return implode('&', $typeNames);
},
fn (): string => $this->describeItself($level, true),
fn (): string => $this->describeItself($level, false),
);
return implode('&', $typeNames);
}

private function describeItself(VerbosityLevel $level, bool $skipAccessoryTypes): string
Expand Down
Loading