Skip to content

[6.x] Add TKeyedArray::make() factory to 6.x for cross-version plugin compatibility#11810

Open
alies-dev wants to merge 2 commits intovimeo:6.xfrom
alies-dev:backport/tkeyedarray-make-factory-v2
Open

[6.x] Add TKeyedArray::make() factory to 6.x for cross-version plugin compatibility#11810
alies-dev wants to merge 2 commits intovimeo:6.xfrom
alies-dev:backport/tkeyedarray-make-factory-v2

Conversation

@alies-dev
Copy link
Copy Markdown
Contributor

@alies-dev alies-dev commented Apr 16, 2026

Summary

Backports the TKeyedArray::make() static factory method from master to 6.x, so plugin authors can use the same API (TKeyedArray::make($properties)) on both Psalm 6.x and master without version-checking.

Motivation

Currently, plugin code that constructs a TKeyedArray must branch on Psalm version:

  • 6.x: new TKeyedArray($properties) works (public constructor), but make() doesn't exist.
  • master: TKeyedArray::make($properties) is the only way (private constructor).

With this change, TKeyedArray::make($properties) works consistently on both branches.

Design decisions

  • new self() not new static() — avoids a silent argument-count mismatch when the method is inherited by TCallableKeyedArray, which has a 4-parameter constructor (no $is_list). Using static would mis-bind the 4th arg ($is_list) into $from_docblock.
  • Return type self — master's make() can return TArray for the never-type edge case; this 6.x shim delegates to the constructor which always returns static. Returning self is correct and honest.
  • @psalm-api on class — matching master; prevents Psalm dead-code detection from flagging make() as unused if no internal call sites exist.
  • Public constructor unchanged — full backward compatibility for existing new TKeyedArray() callers.

Note

Low Risk
Additive API-only change: introduces a static factory and @psalm-api annotation without altering existing constructor behavior. Low risk aside from potential downstream reliance on the new method signature.

Overview
Adds a new TKeyedArray::make() static factory (marked @psalm-pure) that forwards to the existing constructor, enabling a consistent construction API for plugins across Psalm versions.

Marks TKeyedArray as @psalm-api to formalize the public surface and avoid it being treated as internal/unused.

Reviewed by Cursor Bugbot for commit e2a839f. Bugbot is set up for automated code reviews on this repo. Configure here.

…ompatibility

Backports the static make() factory method from master so plugin authors
can use TKeyedArray::make(\$properties) on both 6.x and master without
version-checking. The constructor stays public for backward compatibility.

Uses new self() (not new static()) to avoid argument-count mismatch when
called through TCallableKeyedArray, which has a 4-param constructor.
@alies-dev alies-dev marked this pull request as draft April 16, 2026 10:23
@alies-dev alies-dev changed the title Add TKeyedArray::make() factory to 6.x for cross-version plugin compatibility Add TKeyedArray::make() factory to 6.x for cross-version plugin compatibility Apr 16, 2026
@alies-dev alies-dev marked this pull request as ready for review April 16, 2026 10:25
@alies-dev alies-dev changed the title Add TKeyedArray::make() factory to 6.x for cross-version plugin compatibility [6.x] Add TKeyedArray::make() factory to 6.x for cross-version plugin compatibility Apr 16, 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