Skip to content

fix(phpstan): correct json_decode args and prune stale ignores#8203

Merged
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/phpstan-json-decode-args
May 28, 2026
Merged

fix(phpstan): correct json_decode args and prune stale ignores#8203
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/phpstan-json-decode-args

Conversation

@soyuka
Copy link
Copy Markdown
Member

@soyuka soyuka commented May 28, 2026

Summary

PHPStan 2.x / Larastan updates surfaced two real arg-position bugs in json_decode calls, one type-contract drift on Eloquent rules, and two stale ignores:

  • GraphQl/Action/EntrypointAction: JSON_ERROR_NONE (an error-code constant from the json_last_error() family, value 0) was passed as $flags. Behaviorally a no-op, but semantically wrong. Replaced with default args.
  • Symfony/Bundle/Test/ApiTestAssertionsTrait: JSON_THROW_ON_ERROR was passed as $depth (3rd positional arg). Used named arg flags: to put it in the correct slot while keeping the default $depth of 512.
  • Laravel/Eloquent/Metadata/Factory/Resource/EloquentResourceCollectionMetadataFactory: Metadata::getRules() returns mixed; after is_array, PHPStan narrows to array<int|string, mixed>, losing the expected array<string, ...> shape required by replaceRequiredWithSometimes. Filter to string-keyed entries explicitly at the call site so the contract holds for both PHPStan and runtime (Laravel rules with non-string keys would silently break).
  • Metadata/Resource/Factory/ParameterResourceMetadataCollectionFactory: removed an obsolete @phpstan-ignore-line that no longer matches any reported error.
  • phpstan.neon.dist: dropped one unmatched ignore pattern (getInnermostType).

Test plan

  • vendor/bin/phpstan analyse[OK] No errors
  • cd src/Laravel && ./vendor/bin/phpstan analyse[OK] No errors
  • CI green

…stale ignores

- EntrypointAction: drop JSON_ERROR_NONE (wrong constant family for $flags), rely on defaults
- ApiTestAssertionsTrait: JSON_THROW_ON_ERROR belongs in $flags, not $depth; use named arg
- EloquentResourceCollectionMetadataFactory: filter rules to string-keyed entries before passing to replaceRequiredWithSometimes (Metadata::getRules() returns mixed, is_array narrows to array<int|string, mixed> which loses the expected shape)
- ParameterResourceMetadataCollectionFactory: remove obsolete @phpstan-ignore-line
- phpstan.neon.dist: drop unmatched getInnermostType ignore pattern
@soyuka soyuka force-pushed the fix/phpstan-json-decode-args branch from 4982a27 to b83b7d4 Compare May 28, 2026 13:13
@soyuka soyuka merged commit 8c95af6 into api-platform:4.3 May 28, 2026
119 of 120 checks passed
@soyuka soyuka deleted the fix/phpstan-json-decode-args branch May 28, 2026 13:35
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