Conversation
Hook-backed properties (`@hook` directive) whose invokable returns a
collection type (`list<X>`, `array<K, V>`) were generated as
`public array $field { ... }` with no `@var` docblock. PHPStan at level
6+ rejects these with `missingType.iterableValue`, which made `@hook`
effectively unusable for bulk-find-by-ids and other list-returning
lookups — users had to wrap results in a boilerplate value object.
The regular-field branch of `DataClassGenerator` already emits `@var`
when the naked property type is a `CollectionType`. The hook branch
skipped that step entirely. Even if it hadn't, `getNakedType()` only
unwraps `NullableType`, so passing a `HookPropertyType` wrapper through
would never reach the inner collection. Fix by unwrapping
`HookPropertyType` via `getWrappedType()` before the naked-type check
and dumping the wrapped type (not the wrapper) through `TypeDumper`.
Also pulls `phpstan/phpdoc-parser` in as a runtime dependency. Symfony's
`TypeResolver::create()` only wraps its reflection resolvers with
`PhpDocAwareReflectionTypeResolver` when that package is loadable —
without it, `@return list<User>` on a hook invokable falls back to
`array<int|string, mixed>` and the inner value type is lost. Making it
a hard dep means hook return types declared via PHPDoc resolve
correctly out of the box. Whitelisted in
`composer-dependency-analyser.php` because it's never imported
directly; Symfony's TypeResolver probes for it via `class_exists`.
Regression test in `tests/HooksWithListReturn/` covers a list-returning
hook end-to-end: generated output carries `@var list<User>` above the
property, and the runtime invocation returns the expected objects.
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.
Hook-backed properties (
@hookdirective) whose invokable returns a collection type (list<X>,array<K, V>) were generated aspublic array $field { ... }with no@vardocblock. PHPStan at level 6+ rejects these withmissingType.iterableValue, which made@hookeffectively unusable for bulk-find-by-ids and other list-returning lookups — users had to wrap results in a boilerplate value object.The regular-field branch of
DataClassGeneratoralready emits@varwhen the naked property type is aCollectionType. The hook branch skipped that step entirely. Even if it hadn't,getNakedType()only unwrapsNullableType, so passing aHookPropertyTypewrapper through would never reach the inner collection. Fix by unwrappingHookPropertyTypeviagetWrappedType()before the naked-type check and dumping the wrapped type (not the wrapper) throughTypeDumper.Also pulls
phpstan/phpdoc-parserin as a runtime dependency. Symfony'sTypeResolver::create()only wraps its reflection resolvers withPhpDocAwareReflectionTypeResolverwhen that package is loadable — without it,@return list<User>on a hook invokable falls back toarray<int|string, mixed>and the inner value type is lost. Making it a hard dep means hook return types declared via PHPDoc resolve correctly out of the box. Whitelisted incomposer-dependency-analyser.phpbecause it's never imported directly; Symfony's TypeResolver probes for it viaclass_exists.Regression test in
tests/HooksWithListReturn/covers a list-returning hook end-to-end: generated output carries@var list<User>above the property, and the runtime invocation returns the expected objects.