Skip to content

Replace Psalm with PHPStan + Minor fix - #259

Merged
vjik merged 5 commits into
masterfrom
phpstan
Nov 28, 2026
Merged

vjik merged 5 commits into
masterfrom
phpstan

Conversation

@vjik

@vjik vjik commented Nov 21, 2026 •

Copy link
Copy Markdown
Member
Q A
Is bugfix? ❌
New feature? ❌
Breaks BC? ❌

Summary by Sourcery

Replace Psalm with PHPStan while refining paginator type annotations and removing a redundant sortability check.

Bug Fixes:

  • Remove a redundant paginator capability check when determining whether offset pagination can be sorted.

Enhancements:

  • Migrate project static analysis from Psalm to PHPStan and update PHPDoc annotations and generic type definitions accordingly.
  • Add PHP 8.5 to the static analysis matrix and update project documentation and status badges for PHPStan.

Build:

  • Add PHPStan as a development dependency and provide a Composer command for running it.
  • Remove the Psalm configuration and tooling.

CI:

  • Update static analysis and mutation-test workflow triggers to use PHPStan configuration and run PHPStan across supported PHP versions.

Documentation:

  • Update internal static-analysis instructions to use PHPStan.

@sourcery-ai

sourcery-ai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Update public generic interfaces and their PHPStan type contracts, including default template types and corrected return and iterable annotations.

  • src/Paginator/PaginatorInterface.php L19-162 (7 small edits)
  • src/Processor/DataProcessorInterface.php L10-11, L18-22
  • src/Reader/CountableDataInterface.php L15
  • src/Reader/DataReaderInterface.php L19-20
  • src/Reader/FilterableDataInterface.php L18-19
  • src/Reader/Iterable/IterableFilterHandlerInterface.php L12-13, L21-22, L33
  • src/Reader/LimitableDataInterface.php L12-33 (4 small edits)
  • src/Reader/OffsetableDataInterface.php L10-11, L22
  • src/Reader/ReadableDataInterface.php L10-11, L18, L26
  • src/Reader/SortableDataInterface.php L11-12, L24 (removed lines)
  • src/Writer/DeletableInterface.php L15
  • src/Writer/WriteableInterface.php L15

Implementation

Apply the new analyzer’s generic filter-handler typing and associated annotations across iterable readers, filter handlers, and sorting helpers.

  • src/Reader/Filter/In.php L31-33
  • src/Reader/Iterable/Context.php L17, L24-36, L43-47
  • src/Reader/Iterable/FilterHandler/AllHandler.php L15-16
  • src/Reader/Iterable/FilterHandler/AndXHandler.php L15-16, L27 (removed lines)
  • src/Reader/Iterable/FilterHandler/BetweenHandler.php L15-16, L27 (removed lines)
  • src/Reader/Iterable/FilterHandler/EqualsHandler.php L14-15, L26 (removed lines)
  • src/Reader/Iterable/FilterHandler/EqualsNullHandler.php L14-15, L26 (removed lines)
  • src/Reader/Iterable/FilterHandler/GreaterThanHandler.php L14-15, L26 (removed lines)
  • src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php L15-16, L27 (removed lines)
  • src/Reader/Iterable/FilterHandler/InHandler.php L16-17, L28 (removed lines)
  • src/Reader/Iterable/FilterHandler/LessThanHandler.php L14-15, L26 (removed lines)
  • src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php L15-16, L27 (removed lines)
  • src/Reader/Iterable/FilterHandler/LikeHandler.php L17-18, L29 (removed lines)
  • src/Reader/Iterable/FilterHandler/NoneHandler.php L15-16
  • src/Reader/Iterable/FilterHandler/NotHandler.php L14-15, L26 (removed lines)
  • src/Reader/Iterable/FilterHandler/OrXHandler.php L15-16, L27 (removed lines)
  • src/Reader/Iterable/IterableDataReader.php L238-241 (+12 small edits)
  • src/Reader/Iterable/ValueReader/ValueReaderInterface.php L9-13
  • src/Reader/OrderHelper.php L15-57 (4 small edits)
  • src/Reader/Sort.php L43-47 (+11 small edits)

Review paginator implementation changes together, including the redundant sortability check removal and PHPStan-compatible type assertions.

  • src/Paginator/KeysetPaginator.php L48-53 (+18 small edits)
  • src/Paginator/OffsetPaginator.php L120-124, L244-248 (+13 small edits)

Remove Psalm-specific exception suppressions and update the stub’s type annotation.

  • tests/Support/StubOffsetData.php L19
  • src/Processor/DataProcessorException.php L13 (removed lines)
  • src/Reader/DataReaderException.php L13 (removed lines)
  • src/Writer/DataWriterException.php L13 (removed lines)

Configuration

Replace Psalm tooling with PHPStan in Composer scripts, CI workflows, and analysis configuration.

  • .github/workflows/mutation.yml L9, L19
  • .github/workflows/static.yml L29-30, L35
  • composer.json L42, L78
  • phpstan.neon L1-5
  • psalm.xml (deleted)
  • tools/psalm/composer.json (deleted)

Documentation

Document the analyzer migration and remove the obsolete Psalm and type-coverage badges.

  • CHANGELOG.md L5-7
  • docs/internals.md L22-25
  • README.md L15 (removed lines)

Tests

Remove Psalm-only test-trait constraints that are no longer needed after the analyzer migration.

  • tests/Paginator/PageTokenAssertTrait.php L9 (removed lines), L11 (removed lines)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 24338d3c-2bd6-4156-a325-a3bd98b3c49a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (e5a108f) to head (878a38a).

Additional details and impacted files
@@             Coverage Diff             @@
##              master      #259   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
+ Complexity       256       255    -1     
===========================================
  Files             33        33           
  Lines            647       647           
===========================================
  Hits             647       647           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/Reader/Iterable/IterableDataReader.php" line_range="68" />
<code_context>
  *
- * @psalm-type FilterCallback = Closure(GreaterThan|LessThan|GreaterThanOrEqual|LessThanOrEqual,KeysetFilterContext):FilterInterface
+ * @phpstan-type FilterCallback = Closure(GreaterThan|LessThan|GreaterThanOrEqual|LessThanOrEqual,KeysetFilterContext):FilterInterface
  */
 final class KeysetPaginator implements PaginatorInterface
 {
</code_context>
<issue_to_address>
**Custom handlers fail static analysis**

When a PHPStan-checked caller passes a handler parameterized by its concrete filter type, `IterableDataReader::__construct` types `$extraFilterHandlers` as `IterableFilterHandlerInterface<FilterInterface>[]`; because the interface's filter type is invariant, PHPStan rejects the concrete handler and the caller cannot use the extension point without weakening types or suppressing the error.

Adjust the constructor's `$extraFilterHandlers` generic annotation so handlers specialized to concrete filter types are accepted.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: src/Reader/Iterable/IterableDataReader.php:68


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

@vjik
vjik requested a review from a team November 21, 2026 19:23
@vjik vjik added the status:code review The pull request needs review. label Nov 21, 2026
* @param int $offset Offset.
*
* @return $this New instance.
* @psalm-return $this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While removing this Psalm tag, can we also change the @return $this line above to @return static? $this means the method returns the same object, but IterableDataReader::withOffset() returns a clone.

/** @var OffsetableDataInterface<int, array{id: int}> $reader */
$reader = new IterableDataReader([['id' => 1]]);
var_dump($reader === $reader->withOffset(1)); // false

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread src/Reader/Iterable/Context.php Outdated
Comment on lines +24 to +26
* @param class-string<FilterInterface> $class
*
* @return IterableFilterHandlerInterface<FilterInterface>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPStan accepts getFilterHandler(Equals::class)->match([], new None(), $context), but the call throws a TypeError at runtime. Can we use the filter class to tell PHPStan which filter the returned handler accepts?

Suggested change
* @param class-string<FilterInterface> $class
*
* @return IterableFilterHandlerInterface<FilterInterface>
* @template TFilter of FilterInterface
* @param class-string<TFilter> $class
*
* @return IterableFilterHandlerInterface<TFilter>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

* Iterable filter handler checks whether an item matches criteria defined
* in the filter with the same operator.
*
* @template TFilter of FilterInterface

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPStan now reports missingType.generics for existing custom handlers that implement this interface without a type argument. A default lets those handlers keep working and still allows new handlers to specify a filter type.

Suggested change
* @template TFilter of FilterInterface
* @template TFilter of FilterInterface = FilterInterface

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

* Write items specified.
*
* @param iterable $items Items to write.
* @param iterable<array<mixed>|object> $items Items to write.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPStan now rejects $writer->write([42]). The previous iterable type allowed scalar items. Can we keep accepting them?

Suggested change
* @param iterable<array<mixed>|object> $items Items to write.
* @param iterable<mixed> $items Items to write.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this package an item is always an array or an object (a structure with named fields, see "Concepts" in README). So scalars are not valid items, and this type just makes the writer consistent with the readers.

* Delete items specified.
*
* @param iterable $items Items to delete.
* @param iterable<array<mixed>|object> $items Items to delete.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPStan now rejects $deleter->delete([42]). The previous iterable type allowed scalar items. Can we keep accepting them?

Suggested change
* @param iterable<array<mixed>|object> $items Items to delete.
* @param iterable<mixed> $items Items to delete.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this package an item is always an array or an object (a structure with named fields, see "Concepts" in README). So scalars are not valid items, and this type just makes the writer consistent with the readers.

vjik added 3 commits November 27, 2026 17:38
…erface`

`withOffset()` returns a clone rather than the same object, so `$this` was
inaccurate. Aligns the interface with the other `with*()` methods and the
native `: static` return type.
PHPStan now infers `IterableFilterHandlerInterface<TFilter>` from the
`class-string<TFilter>` argument, so passing a wrong filter to the returned
handler is reported at analysis time instead of failing with a `TypeError`
at runtime.
PHPStan reports `missingType.generics` for existing custom handlers, readers,
paginators, and processors that implement these interfaces without specifying
type arguments. Defaulting each template to its upper bound keeps such
implementations valid while still allowing new ones to narrow the types.
@vjik
vjik requested a review from samdark November 27, 2026 14:58
@vjik
vjik merged commit 233d56e into master Nov 28, 2026
31 checks passed
@vjik
vjik deleted the phpstan branch November 28, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:code review The pull request needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants