-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
[Downgrade PHP 7.0] Add Exception fallback for instanceof Throwable #1608
Conversation
rules/DowngradePhp70/Rector/Instanceof_/DowngradeInstanceofThrowableRector.php
Outdated
Show resolved
Hide resolved
rules/DowngradePhp70/Rector/Instanceof_/DowngradeInstanceofThrowableRector.php
Outdated
Show resolved
Hide resolved
021afcd
to
73bb117
Compare
73bb117
to
648199e
Compare
rules/DowngradePhp70/Rector/Instanceof_/DowngradeInstanceofThrowableRector.php
Outdated
Show resolved
Hide resolved
rules/DowngradePhp70/Rector/Instanceof_/DowngradeInstanceofThrowableRector.php
Show resolved
Hide resolved
rules/DowngradePhp70/Rector/Instanceof_/DowngradeInstanceofThrowableRector.php
Outdated
Show resolved
Hide resolved
rules/DowngradePhp70/Rector/Instanceof_/DowngradeInstanceofThrowableRector.php
Show resolved
Hide resolved
.../DowngradePhp70/Rector/Instanceof_/DowngradeInstanceofThrowableRector/Fixture/nested.php.inc
Show resolved
Hide resolved
95f974e
to
44c089c
Compare
...hp70/Rector/Instanceof_/DowngradeInstanceofThrowableRector/Fixture/already-processed.php.inc
Show resolved
Hide resolved
4e238a3
to
617ffca
Compare
} | ||
|
||
$expectedDisjunct = $this->createFallbackCheck($var); | ||
return $this->nodeComparator->isNodeEqual($expectedDisjunct, $disjuncts); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this extended algorithm, it will also skip $e instanceof \Exception || ($e = $e->getPrevious()) || $e instanceof Throwable
, which the previous variant would correctly change to $e instanceof \Exception || ($e = $e->getPrevious()) || ($e instanceof Throwable || $e instanceof \Exception)
Also, should I move each commit into a separate PR? The merge method you use appears to be destructive (squashes independent commits and removes commit messages). |
a845807
to
ad8194a
Compare
*/ | ||
public function findConditions(BinaryOp $binaryOp, string $binaryOpClass): array | ||
public function findConditions(Expr $binaryOp, string $binaryOpClass): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think BinaryOp
should be kept to ensure the usage is on BinaryOp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the last commit, it makes for much nicer definitions that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Especially with b76243b.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a test case and comment making it clearer.
ad8194a
to
8c24899
Compare
8c24899
to
901a5b1
Compare
PHP 7.0 introduced Throwable and changed the exception hierarchy, adding Throwable as its new root. This means various error handlers will now check for Throwable: $e instanceof Throwable To preserve compatibility with PHP 5.6, we need to check for both Throwable and Exception. And since the value can possibly produce side-effects, we need to assign it to a temporary variable: (($throwable = $loggedMessage->getExtraObject()) instanceof Throwable || $throwable instanceof \Exception)
This is to prevent the following PHPStan error: rules/DowngradePhp70/Rector/Instanceof_/DowngradeInstanceofThrowableRector.php:124 - '#Parameter \#2 \$offset of function array_slice expects int, int\|string given#'
Previously, we ensured idempotency by checking for one of the following expressions: (<var> = <expr>) instanceof Throwable || <var> instanceof Exception <var> instanceof Throwable || <var> instanceof Exception The latter was used to detect similar manual transformation, which would not use assignment because variable access is side-effect free. But in that case, it makes sense to also allow the opposite order <var> instanceof Exception || <var> instanceof Throwable or even extra disjuncts: <var> instanceof Exception || foo() || bar() || <var> instanceof Throwable
This allows nicer definition of some tree operations by considering such nodes the trivial case of single operand.
901a5b1
to
f65d464
Compare
Rebased. |
Thank you 👏 |
Looks like the merge destroyed the commit messages again 😿 |
What do you mean? |
Well then the commit messages are lost from git history (no way to get them e.g. with |
Yes, that's expected trade off. |
Keeping Commits like the ones in this PR should IMO be preserved in the git history so that developer can run If you want nice and independent commits in the history, require it in review (interactive rebase is developer’s best friend). If you want a linear history, rebase before merging. If you want to associate a pull-request with the commits, GitHub already shows that association on the commit page. And it might also be useful to look into merge automation. For GitLab, Marge bot works quite well for GNOME, it also adds |
Thanks. While the GitHub merges will produce messy history with “tramlines” (lines linking to parents in commit graph resembling a public transport lines map), it is indeed better than no history at all. Or you might prefer rebase merging if you want a linear history. Unfortunately, GitHub does not offer anything better without running custom bots. |
No description provided.