The issue you're experiencing with squiggly lines in PHPStorm after using throw_if is likely due to the IDE's static analysis not recognizing that the code execution might stop at that point due to an exception being thrown. This can cause PHPStorm to incorrectly assume that the code below might be unreachable or have other issues.
To resolve this, you can use PHPDoc annotations to inform PHPStorm about the behavior of your code. Here's how you can do it:
-
Suppress the Inspection: You can suppress the specific inspection that is causing the squiggly lines. Place the following comment above the
throw_ifline:/** @noinspection PhpUnhandledExceptionInspection */This tells PHPStorm to ignore the inspection for unhandled exceptions for the following line.
-
Use PHPDoc to Indicate Possible Exception: If you want to be more explicit about the exception that might be thrown, you can add a PHPDoc block above your function or method to indicate that an exception might be thrown:
/** * @throws \Exception */ function yourFunction() { throw_if($condition, \Exception::class, 'Error message'); // Your code here } -
Configure PHPStorm Inspections: If you frequently use
throw_ifand similar constructs, you might want to adjust PHPStorm's inspection settings:- Go to
File>Settings(orPHPStorm>Preferenceson macOS). - Navigate to
Editor>Inspections. - Search for "Unhandled exception" and adjust the settings to better fit your coding style.
- Go to
By using these methods, you should be able to reduce or eliminate the squiggly lines in PHPStorm when using throw_if.