Symfony: Add support for #[MapInput] console command DTOs#340
Merged
Symfony: Add support for #[MapInput] console command DTOs#340
Conversation
87a951c to
b217503
Compare
Co-Authored-By: Claude Code
Co-Authored-By: Claude Code
Recurse into DTO properties annotated with #[MapInput] so their reported as dead. The host property is marked read+written.
b217503 to
d76d366
Compare
Symfony Console 7.x (which introduced MapInput/Argument/Option attributes) requires PHP 8.2+, so on PHP 8.1 those classes are unknown and PHPStan rejects the literal class-string. Uses reportUnmatched: false so the ignore doesn't fail on PHP 8.2+.
Fits under the same "allow referencing any attribute classes" block as the Class/Method variants.
Only process #[MapInput] parameters when the method is __invoke and the owning class has #[AsCommand] or extends Command.
An enum cannot be a command, so the isCommand check already handles that case — no need for an instanceof ReflectionEnum guard.
- Return list instead of mutating &$usages parameter - Use hasAttribute() for all attribute checks (IdentifierNotFound guard) - Use createPropertyUsage() instead of inline construction - Extract getNativeReflection() to local variable - Drop redundant hasClass check from caller
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.
Problem
When a Symfony console command uses
#[MapInput]on a method parameter, the framework creates a DTO vianewInstanceWithoutConstructor()and writes directly to public properties decorated with#[Argument]or#[Option]. It also reads those properties back insetValue(). Methods with#[Interact]on the DTO are called for interactive input.#[MapInput]can also be placed on a DTO property to nest another input DTO. All of this is invisible in user source code, causing false positives.Approach
Detection is anchored at the
#[MapInput]usage site — we only mark DTO properties as used when the DTO class is actually referenced by a#[MapInput]parameter (directly or via nesting). A class with#[Argument]/#[Option]properties that is never referenced by#[MapInput]will still be reported as dead.Changes
#[MapInput]attribute on method parameters#[Argument]or#[Option]as both read and written#[Interact]as used#[MapInput]properties on the DTO (the host property is marked read+written, cycles prevented via visited set)#[MapInput]), and nested-DTO testCo-Authored-By: Claude Code