Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from PHPStan to Psalm #63

Merged
merged 15 commits into from
Jan 4, 2022
Merged

Conversation

weierophinney
Copy link
Contributor

@weierophinney weierophinney commented Jan 3, 2022

This patch switches from PHPStan to Psalm for static analysis, via the following changes:

  • It replaces all usage of Prophecy with native PHPUnit mock objects.
  • It removes PHPStan dependencies and artifacts from the project.
  • It adds Psalm as a development dependency, and slates it for removal once the skeleton has been successfully installed.
  • It modifies the CI configuration to:
    • Add the --no-plugins and --no-scripts flags to Composer.
    • Add a new Composer script for enabling the phpcs plugins.
    • Add a CI pre-run script to call the above script, ensuring that phpcs can run correctly.

Finally, this patch also applies a number of auto-detected Psalm updates, as well as a few that were flagged and easily fixed. The majority of what is in the baseline are of the Mixed*-style warnings.

Fixes #36
Fixes #61
Replaces #57
Replaces #50

- Replace usage of Prophecy with native PHPUnit mock objects, adapting tests to accommodate multiple invocations properly.
- Ensure `composer.json` is copied to temp dir so that it is found.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
- Removes phpstan dependencies
- Removes phpstan from scripts
- Removes phpstan-related installer actions/metadata

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
- Adds Psalm as dev dependency
- Adds Psalm configuration

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Because no plugins/scripts will be run during update operations, we need to manually run the phpcs plugin that aggregates phpcs plugins.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
…pipeline

- Adds the `--no-scripts` and `--no-plugins` flags for Composer
- Adds a pre-run script that enables the phpcs plugins.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
@weierophinney weierophinney added this to the 3.11.0 milestone Jan 3, 2022
@weierophinney weierophinney added the Enhancement New feature or request label Jan 3, 2022
Bumps to 2.1, which ensures we get a compatible symfony/console version.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
- Picks up a fix for autoloading when running discrete processes.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Issues with duplicate and/or undeclared classes, largely from the fact this is a SKELETON.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
First that supports 8.1 properly.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
- Ensures PHP 8.1 compat.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
No longer necessary, and ensures we get deps that actually work with them when testing against lowest supported versions.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
"ignore_php_platform_requirements": {
"8.1": true
"8.0": false,
"8.1": false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've indicated that the --ignore-platform-requirement flag should NOT be used with PHP 8.0 and 8.1. composer update operations run normally without the flag, and, when using --prefer-lowest, we need to get requirements that are appropriate for those versions (otherwise, tests fail due to syntax errors!).

Copy link
Member

Choose a reason for hiding this comment

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

AFAIK, if the property ignore_php_platform_requirements is available, all PHP versions will have false by default.
So it would be enough to simply create the property as an empty object to ensure that platform reqs won't be ignored.

If the ignore_php_platform_requirements property is not available, PHP 8.0 will always have ignored platform reqs.

Comment on lines +102 to +110
"enable-codestandard": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run",
"cs-check": [
"@enable-codestandard",
"phpcs -s"
],
"cs-fix": [
"@enable-codestandard",
"phpcbf"
],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was proposed by @boesing in #57, and I expanded on it here as we need to install without plugins or scripts executing. These changes allow running phpcs/phpcbf even whn plugins are not installed.

Copy link
Member

Choose a reason for hiding this comment

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

TBH, we could automate some of this in the laminas CI setup (to auto-push to contributor branches after message confirmation, potentially)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is only necessary on projects where we are using the --disable-plugins and/or --disable-scripts switches. We might want to detect that, but I think there's only going to be a very small number of places where it will be useful; since there are ways to work around it with the existing tooling, I'm not sure if it makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this is somehow solvable in another way.
I remember that phpstan has some similar magic and most of my colleagues which do use phpstan in other projects (at work) got rid of that composer plugin magic and added the plugins path to their config.

Yes, I know that would mean we would have to change all repositories if we wanted to roll that out for all components but IMHO its only necessary here due to the fact that we do, in fact, ignore composer plugins intentional.

So instead of still relying on composer, we could simply change the path to the coding standard in the codestyle config instead. WDYT?

phpunit.xml.dist Show resolved Hide resolved
@@ -0,0 +1,348 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.17.0@6f4707aa41c9174353a6434bba3fc8840f981d9c">
<file src="config/pipeline.php">
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it's possible to fix any of these 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually fixed quite a few (spent a few hours on it this morning). The vast majority (as in all but maybe 5-10) were MixedAssignment-style warnings. This is to be expected, as we're testing how the application consumes our configuration and/or the Composer file itself. The amount of effort required really would be better spent on creating a different configuration system that had a schema or type system built-in; anything else is just playing whack-a-mole at this point.

@geerteltink geerteltink mentioned this pull request Jan 4, 2022
@Ocramius Ocramius self-assigned this Jan 4, 2022
@Ocramius Ocramius merged commit 407b486 into mezzio:3.11.x Jan 4, 2022
@Ocramius
Copy link
Member

Ocramius commented Jan 4, 2022

Thanks @weierophinney !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch from phpstan to psalm Psalm integration
4 participants