rectorphp / type-perfect

Next level type declaration check PHPStan rules
https://getrector.com/blog/introducing-type-perfect-for-extra-safety
MIT License
73 stars 3 forks source link

Wrong `null_over_false` detection #11

Closed mitelg closed 2 months ago

mitelg commented 2 months ago

hey :wave:

we are migrating from symplify/phpstan-rules to this package. I tried out the null_over_false config, and it found two wrong issues.

class Loader
{
    /**
     * @return bool
     */
    public function exists(string $name) // complains here about the return type
    {
        if (!$this->loadFromDb($name)) {
            return false;
        }

        return true;
    }

    private function loadFromDb(string $name): ?array
    {
        // do stuff
    }
}
class Entity
{
    /**
     * @param string $name
     *
     * @return bool
     */
    public function __isset($name) // complains here about the return type
    {
        if (!$this->isPropertyVisible($name)) {
            return false;
        }

        return isset($this->$name);
    }

    private function isPropertyVisible(string $name): bool
    {
        // some checks
    }
}

Hope this helps. If there is anything unclear, let me know.

Thanks in advance for fixing :+1:

samsonasik commented 2 months ago

@mitelg could you create a test, or probably simple reproducible repo for it? Thank you.

mitelg commented 2 months ago

hey @samsonasik

I added the described examples from here into test cases: https://github.com/rectorphp/type-perfect/pull/16

feel free to adjust this PR :slightly_smiling_face:

mitelg commented 2 months ago

@samsonasik thanks to all the latest fixes! would be nice, if you or @TomasVotruba could tag a new release with those changes. then I could go on with the migration :slightly_smiling_face:

TomasVotruba commented 2 months ago

https://github.com/rectorphp/type-perfect/releases/tag/0.1.6 shipped :tada: