feat: resolve phpdoc array shapes to object schemas#2027
Merged
Conversation
d7d44c5 to
7a659c2
Compare
DerManoMann
reviewed
Jun 27, 2026
| $shape = $type->getShape(); | ||
|
|
||
| // A purely integer-keyed shape (array{0: T, 1: U}) is a positional list, not a keyed object. | ||
| if ($this->arrayShapeIsPositional($shape)) { |
Collaborator
There was a problem hiding this comment.
Could this use array_is_list?
7a659c2 to
b15befd
Compare
DerManoMann
requested changes
Jun 29, 2026
DerManoMann
left a comment
Collaborator
There was a problem hiding this comment.
Just the comment fix-up, then good to go. Sorry about the small iterations.
Comment on lines
+224
to
+226
| // An unsealed shape (array{a: int, ...} or array{a: int, ...<T>}) permits extra entries, so allow additional properties. | ||
| // The rest value type (...<T>) is left open because symfony/type-info resolves it inconsistently across versions (string vs int|string vs unresolved for the same ...<string>), so emitting it would be unstable and sometimes invalid. | ||
| // ArrayShapeType::isSealed() is defined as a null extra value type, so a non-null one means the shape is open. |
Collaborator
There was a problem hiding this comment.
could this comment be put into a multiline /* ... */ comment with more line breaks?
Resolve array{...} to object schemas (properties/required) instead of collapsing them to a homogeneous map.
b15befd to
97b25e4
Compare
Collaborator
|
thanks @alleknalle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolve array{...} to object schemas (properties/required) instead of collapsing them to a homogeneous map.
Summary
ArrayShapeTypeextendsCollectionType, soarray{...}phpdoc shapes fell into thegeneric collection branch and were collapsed to a homogeneous map, losing member names
and required-ness.
TypeInfoTypeResolvernow resolves them to object schemas:objectwithproperties; non-optional keys →requiredarray{0: T, 1: U}) →arraywith mergeditemsarray{a: int, ...}) →additionalPropertiesfrom the extra-value typearray{}→ unchanged (falls through to existing collection handling)Members resolve recursively (object members →
$ref, nested shapes, nullable/union members).Matched before
CollectionType, so other collection handling is untouched.Type of Change
New feature (non-breaking change that adds functionality)
Test Plan
Added cases to
tests/Type/TypeResolverTest(3.0 and 3.1) via newDocblockAndTypehintTypesfixture properties: scalar/optional/typed-open/untyped-open/positional/object-member/nested/
nullable-member/empty shapes.
LegacyTypeResolveroutput left unchanged. Rancomposer testand
composer analyselocally — all green.Checklist