Skip to content

Symfony: Add support for #[MapRequestPayload] and #[MapQueryString] DTOs#339

Draft
janedbal wants to merge 1 commit intomasterfrom
feature/symfony-map-request-payload
Draft

Symfony: Add support for #[MapRequestPayload] and #[MapQueryString] DTOs#339
janedbal wants to merge 1 commit intomasterfrom
feature/symfony-map-request-payload

Conversation

@janedbal
Copy link
Copy Markdown
Member

Problem

When a Symfony controller parameter uses #[MapRequestPayload] or #[MapQueryString], the framework's RequestPayloadValueResolver uses the serializer to create the DTO object. The DTO's constructor is called and its properties are populated — all invisible in user source code. This causes false positives where the DTO constructor, properties, and setter methods are reported as dead code.

The serializer behavior depends on the normalizer used. With the default ObjectNormalizer (registered at priority -1000 in Symfony's framework-bundle):

  • Constructor is called with matching parameters
  • Setter methods (setFoo()) are called via PropertyAccessor
  • Public properties are written directly if no setter exists

Changes

  • Detect #[MapRequestPayload] and #[MapQueryString] attributes on controller method parameters
  • Resolve the parameter type to the DTO class
  • Mark the DTO constructor as used
  • Mark all declared properties as written
  • Mark setter methods (set*) matching a property name as used
  • Add ReflectionProvider dependency to SymfonyUsageProvider
  • Add tests covering promoted constructor properties, query string DTOs, and setter-based DTOs

Co-Authored-By: Claude Code

@janedbal janedbal changed the title Add support for #[MapRequestPayload] and #[MapQueryString] DTOs Symfony: Add support for #[MapRequestPayload] and #[MapQueryString] DTOs Apr 11, 2026
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.

1 participant