psalm / psalm-plugin-laravel

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

Collection isNotNull isNull methods #239

Closed Legion112 closed 1 year ago

Legion112 commented 2 years ago

Should be something like this

    /**
     * @psalm-assert-if-true TValue !empty($this->items)
     * @psalm-assert-if-true TValue $this->first()
     * @psalm-mutation-free
     */
    public function isNotEmpty():bool {}

Also this option have to be set to support this check https://psalm.dev/docs/running_psalm/configuration/#memoizemethodcallresults https://psalm.dev/docs/annotating_code/adding_assertions/

Example from documentation:

image
alies-dev commented 1 year ago

$this->first() has parameters, so it's not correct to use @psalm-assert-if-true TValue $this->first(). I've added some very basic code here: https://github.com/psalm/psalm-plugin-laravel/pull/313/files

Feel free to improve this PR and suggest more changes