Skip to content

Conversation

@samsonasik
Copy link
Member

it currently only got last objects, which cause phpstan notice:

Generator expects value type array<int, array<DateTimeImmutable|string>>, array<int, array<int, DateTime|string>> given.

see https://phpstan.org/r/db520ab6-fc4f-4c45-ac1f-b91801f2e065

@samsonasik
Copy link
Member Author

It seems there is bug on TypeFactory and TypeHasher

private function unwrapConstantArrayTypes(ConstantArrayType $constantArrayType): array
{
$unwrappedTypes = [];
$flattenKeyTypes = TypeUtils::flattenTypes($constantArrayType->getIterableKeyType());
$flattenItemTypes = TypeUtils::flattenTypes($constantArrayType->getIterableValueType());
foreach ($flattenItemTypes as $position => $nestedFlattenItemType) {
$nestedFlattenKeyType = $flattenKeyTypes[$position] ?? null;
if (! $nestedFlattenKeyType instanceof Type) {
$nestedFlattenKeyType = new MixedType();
}
$unwrappedTypes[] = new ArrayType($nestedFlattenKeyType, $nestedFlattenItemType);
}
return $unwrappedTypes;

public function createTypeHash(Type $type): string
{
if ($type instanceof MixedType) {
return $type->describe(VerbosityLevel::precise()) . $type->isExplicitMixed();
}
if ($type instanceof ArrayType) {
return $this->createTypeHash($type->getIterableValueType()) . $this->createTypeHash(
$type->getIterableKeyType()
) . '[]';
}
if ($type instanceof GenericObjectType) {
return $type->describe(VerbosityLevel::precise());
}
if ($type instanceof TypeWithClassName) {
return $this->resolveUniqueTypeWithClassNameHash($type);
}
if ($type->isConstantValue()->yes()) {
return $type::class;
}
$type = $this->normalizeObjectType($type);
return $type->describe(VerbosityLevel::value());
}

@samsonasik
Copy link
Member Author

Fixed 🎉

* @var int
*/
private const MAX_PRINTED_UNION_DOC_LENGHT = 60;
private const MAX_PRINTED_UNION_DOC_LENGHT = 77;
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

This might be tricky to keep in readable line. The longer the docblock will be, the more mess might get int. But let's give 77 a try.

Comment on lines +208 to +216
if ($nestedFlattenItemType instanceof ConstantArrayType) {
$innerArrayTypes = $this->unwrapConstantArrayTypes($nestedFlattenItemType);
foreach ($innerArrayTypes as $innerArrayType) {
// preserve outer array -> inner array structure: array<outerKey, innerArray>
$unwrappedTypes[] = new ArrayType($nestedFlattenKeyType, $innerArrayType);
}

continue;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

this loop again to make result of inner constant array to avoid just added the last one,

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba I am merging it ;)

@samsonasik samsonasik merged commit 180d36c into main Sep 16, 2025
49 checks passed
@samsonasik samsonasik deleted the already-return-iterable branch September 16, 2025 20:01
@TomasVotruba
Copy link
Member

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants