Skip to content

Replace Psalm with PHPStan + Minor fix - #259

Open
vjik wants to merge 2 commits into
masterfrom
phpstan
Open

vjik wants to merge 2 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 as the project's static-analysis tool and align paginator behavior and type documentation with the new analyzer.

Bug Fixes:

  • Remove the redundant limitability check from offset paginator sortability detection.

Enhancements:

  • Replace Psalm with PHPStan for static analysis and update the codebase's type annotations accordingly.
  • Strengthen generic and iterable type documentation across data readers, filters, processors, paginators, and writers.
  • Add explicit filter-handler type metadata and refine static-analysis suppressions.

Build:

  • Add PHPStan as a development dependency and expose it through the Composer scripts.
  • Remove the Psalm configuration and tooling dependencies.

CI:

  • Switch static-analysis and mutation workflow triggers from Psalm configuration to PHPStan configuration.
  • Run PHPStan static analysis against PHP 8.5 in addition to the existing supported versions.

Documentation:

  • Update internal static-analysis instructions to use PHPStan and remove obsolete Psalm badges from the README.

@sourcery-ai

sourcery-ai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Migrate public data and paginator contracts to PHPStan generic and refined-type annotations, keeping their declared runtime APIs unchanged.

  • 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/LimitableDataInterface.php L12-33 (4 small edits)
  • src/Reader/OffsetableDataInterface.php L10-11, L23 (removed lines)
  • 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

Update paginator internals for PHPStan annotations and remove the redundant limitability check now that the reader contract guarantees that capability.

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

Migrate keyset pagination's internal types and assertions to PHPStan and add targeted suppressions for values whose safety follows from runtime control flow.

  • src/Paginator/KeysetPaginator.php L48-53 (+18 small edits)

Add PHPStan-compatible input and item types to iterable filters, readers, value readers, and filter handlers.

  • src/Reader/Filter/In.php L31-33
  • src/Reader/Iterable/Context.php L17, L24-34, L41-45
  • 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/IterableFilterHandlerInterface.php L12-13, L21-22, L33
  • 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)
  • tests/Support/StubOffsetData.php L19

Configuration

Switch static-analysis CI to PHPStan, add its development dependency and Composer command, and configure the migration's analysis settings.

  • .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

Update project-facing static-analysis instructions and changelog, and remove obsolete Psalm badges.

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

Tests

Remove Psalm-specific test-trait requirements that are no longer relevant after the analyzer migration.

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

Other changes

Files not grouped.

  • src/Processor/DataProcessorException.php L13 (removed lines)
  • src/Reader/DataReaderException.php L13 (removed lines)
  • src/Writer/DataWriterException.php L13 (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: 5a6497b4-93c2-4d06-bf48-8934662d6efd

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 (e379016).

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

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>

* 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

* 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.

* 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.

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