-
Notifications
You must be signed in to change notification settings - Fork 344
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
composer: Update PHPStan to 2.0 #1505
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
✅ Deploy Preview for selfoss canceled.
|
So that PHPStan 2.0 does not complain about `id` key being always present as declared by the PHPDoc `@param` type. This also makes the wrong input result in an error rather than silently ignoring the list items without an `id`.
PHP does not allow specifying an explicit default value on readonly properties and PHPStan 2.0 enforces the same for `@readonly` PHPDoc marker. Let’s move the initial values to else branches. This required turning the method into a constructor. Also fix `@readonly` for `$extraIds` property – it needs to be on a separate line for PHPStan to recognize it.
`Item::withExtraData()` is an instance of `Functor::map()` so it can change the `Item`’s generic argument type. But since PHPStan has no concept of transmuting types, it would start to complain after upgrading to version 2.0: PHPDoc tag @var with type spouts\Item<NewExtra> is not subtype of native type $this(spouts\Item<Extra>). 🪪 varTag.nativeType Let’s create a fresh instance instead.
We want to make sure we are checking all variants exhaustively but PHPStan 2.0 started to complain about using conjunction: 258 Strict comparison using === between 'media' and 'media' will always evaluate to true. 🪪 identical.alwaysTrue Let’s switch to `switch` statement for now, which supports exhaustiveness checking. Once we drop support PHP 7.4, we can port it to `match`.
`preg_match` without `PREG_UNMATCHED_AS_NULL` behaves inconsistently – trailing unmatched capture groups are omitted but non-trailing ones resolve to an empty string. This would have been confusing if we ever decided to modify the expression, so we were defensively checking for both options. But PHPStan 2.0 got smarter and knows the empty string cannot currently occur, so it started to complain: 71 Strict comparison using !== between non-empty-string and '' will always evaluate to true. 🪪 notIdentical.alwaysTrue Let’s just add `PREG_UNMATCHED_AS_NULL`, which will result in `null` in both cases since PHP 7.4. Though we still need to cast away the null since PHPStan is not smart enough to know one of the alternatives must be present.
Let’s create a new config from scratch, since getting it is deprecated. RFC: guzzle/guzzle#2514 Deprecation: guzzle/guzzle#2516
Keeping the code future proof.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://phpstan.org/blog/phpstan-2-0-released-level-10-elephpants