phpstan / phpstan-symfony

Symfony extension for PHPStan
MIT License
698 stars 89 forks source link

Request::getContent() return value without asResource is not always a string #376

Closed tuomasva closed 8 months ago

tuomasva commented 8 months ago
$a = $request->getContent();
is_string($a); // Call to function is_string() with string will always evaluate to true.

I see that this code from Symfony atleast 6.4/7.0 Request (https://github.com/symfony/http-foundation/blob/7.0/Request.php#L1390):

    ...

    if ($currentContentIsResource) {
        rewind($this->content);

        return stream_get_contents($this->content);
    }

    if (null === $this->content || false === $this->content) {
        $this->content = file_get_contents('php://input');
    }

    return $this->content;
}

can indeed return false on either stream_get_content() or file_get_contents() failing?

ondrejmirtes commented 8 months ago

This isn't a bug in PHPStan nor phpstan-symfony, but in Symfony PHPDocs. It says:

@psalm-return ($asResource is true ? resource : string) (https://github.com/symfony/http-foundation/blob/47d72323200934694def5d57083899d774a2b110/Request.php#L1388C8-L1388C63)

If it can really ever be false then this PHPDoc is wrong, and you should open a bug report for Symfony itself.

github-actions[bot] commented 7 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.