wordpress-develop icon indicating copy to clipboard operation
wordpress-develop copied to clipboard

#52217 - PHPStan config and fixes

Open johnbillion opened this issue 4 years ago • 6 comments

Trac ticket: https://core.trac.wordpress.org/ticket/52217

This introduces config for PHPStan with plenty of exclusions so we can identify real issues that need to be fixed.

Changes:

johnbillion avatar Jan 04 '21 22:01 johnbillion

Problems of using PHPStan as an inline inspection tool

PHPStan - and Psalm as well for that matter - work best with well-typed code bases, the stricter the better. WordPress is most definitely not such a code base, so the noise from false positives will be huge.

I agree. I'd like to echo and add to @jrfnl's concerns.

PHPStan will generate a huge volume of false positives. Why is this a problem?

  • Significant effort will be needed to investigate each PHPStan incident to determine if it's a valid positive AND if it's something that could or should be changed for WordPress specifically without causing a backwards-compat issue. I've witnessed this with the work being done in Trac ticket 51423. It's time-consuming work and the type of work that requires deep knowledge about not only PHP but also WordPress itself.

  • Risk of changing the codebase to make PHPStan happy without adding value to the codebase.

  • Bottlenecks in the workflow for contributors, maintainers, and committers.

  • Frustration pain point for contributors in figuring out how to make PHPStan happy.

Where does PHPStan fit into the project?

I do think it's a good idea to do intermittent, ad-hoc runs with tools like PHPStan, Psalm, Exakat and other tools

I agree. This tool and others can serve WordPress as a periodic auditing tool.

What about this PR?

There are valid fixes and improvements in this PR:

  • Some look like bug fixes These could be broken out into separate tickets for tracking, history, and isolated discussion and testing.
  • Some are potential code improvements, though many need testing to ensure each is valid and does not cause a backwards compat issue. These could be also be broken out from the PHPStan work as a separate ticket and PR.

By splitting out the work we can ensure these are not lost (along with the extensive code reviews) in the debate about whether to use PHPStan as an inline CI tool or not.

hellofromtonya avatar Jul 16 '21 16:07 hellofromtonya

@hellofromtonya I've addressed your main concern about the impact of introducing static analysis in the comments on https://core.trac.wordpress.org/ticket/52217, but in short I don't believe that it introduces the sort of significant burden and large number of false positives that you've seen on https://core.trac.wordpress.org/ticket/51423 . This ticket aims to start at level 1, whereas 51423 aims to tackle type related problems that are several steps ahead of where we are now.

johnbillion avatar Jul 19 '21 20:07 johnbillion

I'm going to update the description of this PR with notes about each change. I realise that it's not clear why quite a few of these changes have been made.

johnbillion avatar Jul 19 '21 20:07 johnbillion

https://core.trac.wordpress.org/changeset/51850

johnbillion avatar Sep 22 '21 21:09 johnbillion

https://core.trac.wordpress.org/changeset/51851

johnbillion avatar Sep 22 '21 21:09 johnbillion

This is an interesting point and seems easy to add to the project, what can we do to push it?

samuelsolis avatar Oct 11 '23 13:10 samuelsolis