Skip to content

chore: update PHPStan PHP version to 8.1 #6668

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

Merged
merged 3 commits into from
Oct 15, 2022

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Oct 11, 2022

Description
PHP 8.1 is the most used version with Composer.

Screenshot 2022-10-12 8 15 14

Checklist:

  • Securely signed commits
  • [] Component(s) with PHPDoc blocks, only if necessary or adds value
  • [] Unit testing, with >80% coverage
  • [] User guide updated
  • [] Conforms to style guide

Since the version is specified in PHPStan config, there is no need to run in PHP 8.0.
@kenjis kenjis added the github_actions Pull requests that update Github_actions code label Oct 12, 2022
Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

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

Shouldn't we be running PHPStan against each version of PHP we want to support? There doesn't appear to be a command line argument for it but we could have a config file for each that imports the main file.

@kenjis
Copy link
Member Author

kenjis commented Oct 12, 2022

Shouldn't we be running PHPStan against each version of PHP we want to support?

Ideally yes, but IIRC we were not able to support PHP 7.4 and 8.0 at the same time.
And PHP 8.1 has new classes like PgSql\Result, so it seems we cannot support 8.0 and 8.1 after all.

Or if we prepare phpstan.neon.dist and phpstan-baseline.neon.dist for each version, we can do it?
But it costs more.

@paulbalandan
Copy link
Member

It would be cumbersome to maintain, as shown before. We have code flagged by phpstan in a lower PHP version which we add @phpstan-ignore-line. However, that line is perfectly okay with phpstan when run on a higher PHP version, erroring now at "No error to ignore..."

@kenjis
Copy link
Member Author

kenjis commented Oct 12, 2022

It seems to me that rather than increasing the number of PHP versions to check, we should focus on reducing phpstan-baseline.neon.dist and @phpstan-ignore-line and increasing the level (now level: 5).

@MGatner
Copy link
Member

MGatner commented Oct 13, 2022

I disagree. Baselining is very easy, and if the only hindrance to supporting multiple PHP versions is the error variance then we just baseline them separately. There is nothing special about the baseline config- you can add the same type of error ignores to any. So we can have a single phpstan.neon.dist with whatever we want our "standard" to be, then phpstan-x.x.neon for each PHP version we want to support, including version-specific baselining.

I would be glad to take on this work, I've been doing something similar at my day job. Let's proceed with this change now since it is ready, but please voice any objections in this thread.

@kenjis
Copy link
Member Author

kenjis commented Oct 13, 2022

I think if we have phpstan-x.x.neon, we can run PHPStan for all supported PHP versions.
My question is: is it worth doing?

@MGatner
Copy link
Member

MGatner commented Oct 14, 2022

Is it worth doing?

What other language versioning safety nets do we have? Obviously if a test case tries to use a deprecated or not-yet-available feature that will fail, but that requires test coverage.

I work regularly across 7.4, 8.0, and 8.1 these days and frequently have to look things up. Maybe other people have their heads around that better, but I don't necessarily trust myself to catch a mistake during a code review.

@kenjis
Copy link
Member Author

kenjis commented Oct 14, 2022

Okay, it is true that the current code coverage is a bit low.
I'm not sure PHPStan helps us so much, but if you say so, let's try to run in the different PHP versions.

Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

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

Let's proceed with this for now. The version of PHP running shouldn't affect the version of analysis.

@kenjis kenjis merged commit 253133b into codeigniter4:develop Oct 15, 2022
@kenjis kenjis deleted the update-phpstan-php-8.1 branch October 15, 2022 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
github_actions Pull requests that update Github_actions code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants