Skip to content

Fix Type\shape cross-major Psl compatibility (positional allowUnknownFields)#5

Merged
robertvansteen merged 3 commits into
mainfrom
fix/psl-shape-positional-arg
Jun 11, 2026
Merged

Fix Type\shape cross-major Psl compatibility (positional allowUnknownFields)#5
robertvansteen merged 3 commits into
mainfrom
fix/psl-shape-positional-arg

Conversation

@robertvansteen

@robertvansteen robertvansteen commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Problem

The package requires php-standard-library: ^4.0 || ^5.0 || ^6.0, but Psl renamed Type\shape()'s second parameter between majors:

  • Psl 4.x: bool $allow_unknown_fields
  • Psl 5.x / 6.x: bool $allowUnknownFields

RestrictImplicitDependencyUsage calls it by name (allowUnknownFields:), so it only works on a subset of supported majors. Under Psl 4.x it throws Unknown named parameter $allowUnknownFields at rule registration, which aborts PHPStan entirely for any downstream consumer pinned to Psl 4.x (e.g. product-catalogue). Worse, PHPStan exits 0 in that state, so the consumer's type-check silently passes without analysing anything.

The commit that introduced this (c81f12f) switched snake→camel to satisfy Psl 6.x in this repo's own dev env, inadvertently breaking 4.x consumers.

Fix

Pass the argument positionally (Type\shape([...], true)). The parameter's position is stable across all supported majors, so the rule works regardless of which Psl major the consumer resolves.

Verification

Validated locally against both majors:

Psl major allowUnknownFields: (before) positional (after)
4.x Unknown parameter $allowUnknownFields clean
6.x clean clean

Follow-up suggestion

Add a Psl-version matrix (4.x / 5.x / 6.x) to CI so a named-arg regression like this fails here instead of in consumers.

🤖 Generated with Claude Code

Robert van Steen and others added 3 commits June 10, 2026 17:39
…r support

The package supports php-standard-library ^4.0 || ^5.0 || ^6.0, but Psl
renamed Type\shape()'s second parameter between majors: `allow_unknown_fields`
in 4.x and `allowUnknownFields` in 5.x/6.x. Calling it by name therefore only
ever works on a subset of supported majors — under Psl 4.x the named call
throws "Unknown named parameter $allowUnknownFields" at rule-registration,
which aborts PHPStan for every downstream consumer pinned to 4.x.

Pass the argument positionally instead; the parameter's position is stable
across all supported majors, so the rule works regardless of the Psl version
resolved by the consumer.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pre-existing failures unrelated to the Psl arg fix, surfaced now that the
suite runs to completion:

- StrictComparisonOfObjectsRule::processNode() must return
  list<IdentifierRuleError>; add ->identifier() so the builder yields one.
- basepath(): realpath() is string|false. Guard both calls so preg_match
  receives a string and the function never returns false.
- RestrictImplicitDependencyUsage test used Psl\Collection\Vector as the
  "undefined package" example, but php-standard-library is now a declared
  dependency (the rule itself uses Psl\Type), so Psl\ is an allowed
  namespace. Use SebastianBergmann\Diff\Differ — installed transitively via
  phpunit but not declared — which is genuinely an implicit dependency.
- Raise phpstan/phpstan floor to ^2.1.13: the rule implements
  RestrictedClassNameUsageExtension, added in 2.1.13, so prefer-lowest
  previously resolved 2.1.0 (missing the interface) and fatal-errored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
On windows-latest + PHP 8.3 + prefer-stable, php-standard-library 5.x/6.x
require PHP ~8.4, so composer must resolve to 4.x — which requires
ext-sodium. sodium is bundled on the Ubuntu images but not enabled on
Windows unless requested, so the install step failed there. Add it to the
setup-php extensions list.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@robertvansteen robertvansteen requested a review from erikgaal June 10, 2026 18:41
@robertvansteen robertvansteen merged commit 76f122b into main Jun 11, 2026
8 checks passed
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.

2 participants