Repository navigation
Update ondrejmirtes/simple-downgrader to 2.4.0, use ?-> where possible - #7043
Merged
Merged
Conversation
2.4.0 downgrades the nullsafe operator ?-> for PHP < 8.0, so it can be used in phpstan-src. Amp-Thread-ID: https://ampcode.com/threads/T-01a1cf65-c8c9-76e6-a6c6-639c9057ca36
… property fetch
Reports $a !== null ? $a->b() : null (and the === null form) and
if ($a !== null) { $a->b(); }, when $a is a variable or a property fetch
that can be evaluated twice. The 150 places it found were fixed with
phpstan --fix. ondrejmirtes/simple-downgrader 2.4.0 downgrades ?-> for
PHP 7.4.
Amp-Thread-ID: https://ampcode.com/threads/T-01a1cf65-c8c9-76e6-a6c6-639c9057ca36
simple-downgrader 2.4.0 downgrades it, so the writeToFixer() helper added in edbc256 is no longer needed. Amp-Thread-ID: https://ampcode.com/threads/T-01a1cf65-c8c9-76e6-a6c6-639c9057ca36
This file contains hidden or 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
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.
simple-downgrader 2.4.0 downgrades the nullsafe operator
?->for PHP < 8.0, so it can be used in phpstan-src.The rest of the chain is short-circuited like in PHP, non-variable bases are evaluated once, and
isset(),empty()and??keep their no-warning semantics.Using
?->in phpstan-srcNew build rule
PHPStan\Build\NullsafeOperatorRule(identifierphpstan.nullsafeOperator, fixable) reports:$a !== null ? $a->b()->c : nulland$a === null ? null : $a->b()→$a?->b()->cif ($a !== null) { $a->b(); }without else →$a?->b();It only reports when
$ais a variable, a property fetch or a static property fetch, so the replacement doesn't change how many times anything is called. It skips first-class callables, which can't be nullsafe. When the call's arguments span several lines, the error isn't fixable, because the printer would put them on one line.phpstan --fixreplaced the 150 places it found in 68 files. I removed redundant parentheses left around a few of them, such as?? ($a?->b()).FixerApplicationuses$this->fixerEncoder?->write()again instead of thewriteToFixer()helper from edbc256.I left out
$a instanceof Foo ? $a->b() : null. In phpstan-src these narrow between types, such asIdentifier|Name, rather than check for null.I downgraded the result to PHP 7.4 with
compiler/vendor/bin/simple-downgrade. No?->remained, and every downgraded file passesphp -l.