Skip to content

Replace Psalm with PHPStan - #289

Merged
vjik merged 2 commits into
masterfrom
phpstan
Nov 22, 2026
Merged

vjik merged 2 commits into
masterfrom
phpstan

Conversation

@vjik

@vjik vjik commented Nov 22, 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.

Enhancements:

  • Replace Psalm with PHPStan for project static analysis and update the codebase annotations and types accordingly.

Build:

  • Add PHPStan as a development dependency and provide a Composer script and configuration for running static analysis.

CI:

  • Update static-analysis and workflow path triggers to use PHPStan, including coverage for PHP 8.5.

Documentation:

  • Update the internals documentation and changelog to reference PHPStan, and remove Psalm-specific badges from the README.

Chores:

  • Remove the Psalm configuration and development dependency.

@sourcery-ai

sourcery-ai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Update public PHPDoc parameter and return types to PHPStan-compatible annotations, including the refined attribute-array and non-empty-string types.

  • src/Html.php L2510-2517 (+137 small edits)
  • src/Tag/Base/Tag.php L17-126 (8 small edits)
  • src/Tag/CustomTag.php L54
  • src/Tag/Select.php L20-142 (5 small edits)

Implementation

Replace Psalm-specific assertions and suppressions with PHPStan equivalents or targeted ignores where dynamic attribute values are intentionally cast or treated as CSS data.

  • src/Html.php L202-293 (4 small edits)
  • src/Tag/Base/BooleanInputTag.php L18-189 (5 small edits)
  • src/Tag/Input/File.php L17-91 (4 small edits)
  • src/Tag/Input/Range.php L23-32, L147-151 (+3 small edits)
  • src/Tag/Option.php L61
  • src/Tag/Select.php L249, L275
  • src/Widget/ButtonGroup.php L21-123 (7 small edits)
  • src/Tag/Base/MediaTag.php L14 (removed lines), L16 (removed lines), L18 (removed lines)

Configuration

Replace Psalm CI jobs and workflow path filters with PHPStan, add PHP 8.5 to the static-analysis matrix, and swap the Composer dependency and command entry for PHPStan.

  • .github/workflows/bc.yml L11, L22
  • .github/workflows/build.yml L10, L21
  • .github/workflows/mutation.yml L9, L19
  • .github/workflows/static.yml L29-30, L35
  • composer.json L36-40, L61
  • phpstan.neon L1-5
  • psalm.xml (deleted)

Documentation

Document the move to PHPStan and remove the obsolete Psalm badges.

  • CHANGELOG.md L7
  • docs/internals.md L21-24
  • README.md L15 (removed lines)

Other changes

Files not grouped.

  • src/IdGenerator.php L20
  • src/Tag/Base/ListTag.php L32
  • src/Tag/Base/TagContentTrait.php L20
  • src/Tag/Fieldset.php L18-20
  • src/Tag/Optgroup.php L17-23, L38
  • src/Tag/Tr.php L43-112 (6 small edits)
  • src/Widget/CheckboxList/CheckboxItem.php L11-14
  • src/Widget/CheckboxList/CheckboxList.php L23-40 (+13 small edits)
  • src/Widget/RadioList/RadioItem.php L11-14
  • src/Widget/RadioList/RadioList.php L20-37 (+11 small edits)

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

@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (119c06c) to head (c08b843).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##              master      #289   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity      1067      1067           
===========================================
  Files            138       138           
  Lines           2763      2764    +1     
===========================================
+ Hits            2763      2764    +1     

☔ 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 2 issues

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

## Individual Comments

### Comment 1
<location path="src/Tag/Select.php" line_range="20" />
<code_context>
  * @link https://www.w3.org/TR/html52/sec-forms.html#the-select-element
  *
- * @psalm-type OptionsData = array<array-key, string|Stringable|int|float|null|array<array-key,string|Stringable|int|float|null>>
+ * @phpstan-type OptionsData = (string|Stringable|int|float|null|(string|Stringable|int|float|null)[])[]
  */
 final class Select extends NormalTag
</code_context>
<issue_to_address>
**Valid string-keyed inputs fail analysis**

When callers pass string-keyed option data, option or group attribute maps, or CSS classes, pHPStan treats the `[]` annotations in `OptionsData`, the attribute maps, and `$class` as integer-keyed arrays, so it rejects these runtime-supported inputs and reports false analysis errors.

Use explicit `array<array-key, ...>` types for these arrays, including the nested arrays in `OptionsData`.

Also at `src/Tag/Select.php:107`, `src/Tag/Select.php:141-143`, `src/Tag/Optgroup.php:38`, `src/Html.php:2464`.
</issue_to_address>

### Comment 2
<location path="src/Widget/CheckboxList/CheckboxList.php" line_range="337" />
<code_context>

     /**
-     * @psalm-param Closure(CheckboxItem):string|null $formatter
+     * @param Closure(CheckboxItem):string|null $formatter
      */
     public function itemFormatter(?Closure $formatter): self
</code_context>
<issue_to_address>
**Null formatters appear invalid**

When callers pass null to clear a formatter, pHPStan reads `:string|null` as a nullable callback return type, not a nullable callback. The documented parameter therefore excludes `null` even though both methods accept `?Closure`, so callers using `itemFormatter(null)` to clear a formatter get false analysis errors.

Document each formatter as `(Closure(Item): string)|null`, with the actual item class substituted for `Item`.

Also at `src/Widget/RadioList/RadioList.php:318`.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: src/Tag/Select.php:20, src/Widget/CheckboxList/CheckboxList.php:337


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

Comment thread src/Tag/Select.php Resolved
@vjik
vjik merged commit e760c0e into master Nov 22, 2026
31 checks passed
@vjik
vjik deleted the phpstan branch November 22, 2026 10:38
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