Skip to content

re #96 clear PHPStan 'unsafe new static()' via @phpstan-consistent-constructor#108

Merged
tonydspaniard merged 1 commit into
masterfrom
feat/96-phpstan-burndown-5
May 28, 2026
Merged

re #96 clear PHPStan 'unsafe new static()' via @phpstan-consistent-constructor#108
tonydspaniard merged 1 commit into
masterfrom
feat/96-phpstan-burndown-5

Conversation

@tonydspaniard
Copy link
Copy Markdown
Member

Summary

Part of the #96 PHPStan burn-down (Phase 4). Clears all 27 Unsafe usage of new static() findings from the level-6 baseline.

  • Annotates the Structure base collections (Map, Set, Queue, Stack, Pair, PriorityQueue) and the two Courier classes (InMemoryCommandLocatorService, CommandRunnerMiddlewareStrategy) that copy themselves via new static() with @phpstan-consistent-constructor.
  • Verified first that no subclass overrides the inherited constructor, so the annotation documents and enforces a real invariant (subclasses must keep a compatible constructor) rather than silencing the checker. PHPStan now errors if that invariant is ever broken.
  • Map's annotation propagates to CookieCollection / SetCookieCollection, clearing their new static() findings without touching those files.
  • Regenerated phpstan-baseline.neon: 92 → 65 errors (72 → 62 entries), no entries added.

Out of scope (follow-ups)

The remaining baseline entries that looked like "optional-dep class-not-found" turned out to be real API-version-mismatch bugs, not ignorable artifacts — they will be handled in dedicated PRs:

  • Altair\Http\Jwt\* targets the lcobucci/jwt 3.x API while ^5.3 is required/installed (security-sensitive; needs migration + security review).
  • FormatNegotiator uses AcceptHeader::getValue() which is gone in willdurand/negotiation 3.x.

Test plan

  • composer cs — clean
  • composer stan[OK] No errors
  • vendor/bin/rector process --dry-run (touched files) — clean
  • composer test — 5541 pass (the only local errors are MongoSessionHandlerTest, a pre-existing env issue when ext-mongodb is absent; CI loads mongodb)

…nstructor

Annotate the Structure base collections (Map, Set, Queue, Stack, Pair,
PriorityQueue) and the two Courier classes that copy themselves through
new static() with @phpstan-consistent-constructor. No subclass overrides
the inherited constructor, so the annotation documents and enforces a
real invariant rather than silencing the checker. The annotation on Map
propagates to its subclasses (CookieCollection, SetCookieCollection),
clearing their new static() findings too.

Regenerate phpstan-baseline.neon: 27 'unsafe new static()' errors across
11 entries drop out; no entries added. Baseline 92 -> 65 errors.
@tonydspaniard tonydspaniard merged commit 2eb62ab into master May 28, 2026
3 checks passed
@tonydspaniard tonydspaniard deleted the feat/96-phpstan-burndown-5 branch May 28, 2026 05:21
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