Skip to content

Documented list of allowed DTO property types has drifted from the PHPStan rule #439

Description

@mattgoud

CONTEXT.md and .claude/REVIEW_PROMPT.md state that a public DTO property may only be a scalar (int, string, bool) or an array, with two exceptions, DecimalNumber and DateTimeImmutable.

The CI-enforced rule allows more than that. tests/PHPStan/ApiResourcePropertyTypeRule.php:

private const ALLOWED_SCALAR_TYPES = ['bool', 'int', 'string', 'array'];

private const ALLOWED_CLASS_SHORT_NAMES = ['DecimalNumber', 'DateTimeImmutable', 'File'];

private const ALLOWED_CLASS_FQCNS = [
    'PrestaShop\Decimal\DecimalNumber',
    'DateTimeImmutable',
    ...
    'PrestaShop\PrestaShop\Core\Util\DateTime\DateImmutable',
];

So Symfony\Component\HttpFoundation\File\File and Core\Util\DateTime\DateImmutable are both accepted by the rule and both missing from the documentation.

Why it is worth fixing

The documentation is what the automated pre-review reads. On #422, which needs ?File properties for a multipart upload, it produced a hard blocker against a resource that the rule accepts and whose CI is green. Every future multipart endpoint will hit the same false positive, and a contributor who trusts the report will rewrite working code.

Suggested fix

Bring both documents in line with the rule, and say what each exception is for:

  • DecimalNumber, mandatory instead of float
  • DateTimeImmutable and Core\Util\DateTime\DateImmutable for date and datetime properties
  • File for multipart upload properties, which are normally paired with #[ApiProperty(readable: false)] so they stay out of responses

Since the rule is the thing CI enforces, it may be worth having the documentation point at ALLOWED_CLASS_SHORT_NAMES explicitly so the two cannot drift again.

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions