driftingly / rector-laravel

Rector upgrades rules for Laravel
http://getrector.org
MIT License
500 stars 49 forks source link

Adds ThrowIfRector rule #154

Closed peterfox closed 9 months ago

peterfox commented 9 months ago

Changes

Why

I thought it would be a nice addition to be able to automatically convert simply if statements that are used to throw an exception.

Example code:

-if ($condition) {
-    throw new Exception();
-}
-if (!$condition) {
-    throw new Exception();
-}
+throw_if($condition, new Exception());
+throw_unless($condition, new Exception());