psalm / psalm-plugin-laravel

A Psalm plugin for Laravel
MIT License
307 stars 72 forks source link

Support non-null assertions with throw_if #294

Closed dpash closed 1 year ago

dpash commented 1 year ago

Is your feature request related to a problem? Please describe.

You can assert that a variable is non-null using

    throw_if(is_null($value), new Exception('is null'));

This is equivalent of

    if (is_null($value)) { 
        throw new Exception('is null'); 
    }

Psalm will assert that $value is non-null in the latter instance, but not with the former.

Describe the solution you'd like Psalm should support throw_if and throw_unless so that psalm knows variables are non-null

Describe alternatives you've considered Not using throw_if

Additional context Can't think of anything