Increase PHPStan level and ensure issues exist for each entry in the baseline

Created on 22 January 2025, 7 days ago

Problem/Motivation

πŸ› WSOD when using settings to limit sources to recipes Active fixed a case where the code was strictly comparing an object to a bool. It was never going to work, but it was valid PHP.

This is where PHPStan comes in to save the day.
Level 4 is great, but there are things in Levels 5-8 that are very helpful.

The biggest problem with the higher levels is when it starts complaining about array keys and values, and their types. That can all be sidestepped.
Experience Builder conforms to level 8, we can too.

Steps to reproduce

To see errors:

rm .phpstan-baseline.php
../../vendor/bin/phpstan analyze . --configuration=./phpstan.neon --memory-limit=-1

To regenerate baseline:

../../vendor/bin/phpstan analyze . --configuration=./phpstan.neon --memory-limit=-1 --generate-baseline .phpstan-baseline.php --allow-empty-baseline -vv

Proposed resolution

Each level is a separate commit or series of commits, see MR.
There might be some more clean-up with regard to BC.

Additionally, there are three classes of ignored errors now:

  1. the aforementioned array problem: missingType.iterableValue
  2. upstream issues, either core or Package Manager (as seen in phpstan.neon, these have explanations but need issues)
  3. issues that are in our codebase (as seen in .phpstan-baseline.php)
πŸ“Œ Task
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States tim.plunkett Philadelphia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @tim.plunkett
  • Merge request !678Resolve #3501590 "Increase phpstan level" β†’ (Merged) created by tim.plunkett
  • Pipeline finished with Failed
    7 days ago
    Total: 330s
    #403222
  • Pipeline finished with Failed
    7 days ago
    Total: 468s
    #403234
  • Pipeline finished with Failed
    7 days ago
    Total: 670s
    #403251
  • Pipeline finished with Failed
    7 days ago
    Total: 490s
    #403267
  • Pipeline finished with Success
    7 days ago
    Total: 462s
    #403272
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    This is really good to see, I found a few small points (who am I kidding, this entire MR is nothing but small points), but this represents a great bulwark against bugs and is a quality of life improvement. I still have a prickly relationship with PHPStan but the revelation that you can turn off array structure validation is eye-opening.

  • Pipeline finished with Success
    6 days ago
    Total: 379s
    #403998
  • Pipeline finished with Failed
    6 days ago
    Total: 750s
    #404022
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    I'm pretty much okay with this. Some minor nits we could argue over, but nothing that's worth blocking it.

  • Pipeline finished with Failed
    6 days ago
    Total: 789s
    #404040
  • πŸ‡ΊπŸ‡ΈUnited States tim.plunkett Philadelphia

    One last step is to document the additions to the phpstan.neon

  • Pipeline finished with Success
    6 days ago
    Total: 372s
    #404052
  • Pipeline finished with Success
    6 days ago
    Total: 532s
    #404101
  • πŸ‡ΊπŸ‡ΈUnited States tim.plunkett Philadelphia

    Opened πŸ› Resolve type issues caught by PHPStan usage in Project Browser Active for the actual "bugs" upstream in Package Manager (as opposed to the ones stemming from the weirdness of legacy core code).

  • πŸ‡ΊπŸ‡ΈUnited States tim.plunkett Philadelphia

    This was merged, which is good, but by me, which is not.

Production build 0.71.5 2024