Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong return type for imagejpeg GD function #6257

Closed
MauricioFauth opened this issue Aug 7, 2021 · 2 comments · Fixed by #6260
Closed

Wrong return type for imagejpeg GD function #6257

MauricioFauth opened this issue Aug 7, 2021 · 2 comments · Fixed by #6260

Comments

@MauricioFauth
Copy link
Contributor

MauricioFauth commented Aug 7, 2021

The return type of the imagejpeg function is bool not false|string.

 imagejpeg(GdImage $image, resource|string|null $file = null, int $quality = -1): bool

https://psalm.dev/r/79c592fb26

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/79c592fb26
<?php declare(strict_types=1);

final class Image
{
    /**
     * @param resource $image
     * @param resource|string|null $file
     */
    public static function jpeg($image, $file = null, int $quality = -1): bool {
        return \imagejpeg($image, $file, $quality);
    }
}
Psalm output (using commit cccfe75):

ERROR: InvalidArgument - 10:27 - Argument 1 of imagejpeg expects GdImage, resource provided

ERROR: InvalidArgument - 10:35 - Argument 2 of imagejpeg expects null, null|resource|string provided

ERROR: InvalidReturnStatement - 10:16 - The inferred type 'false|string' does not match the declared return type 'bool' for Image::jpeg

ERROR: InvalidReturnType - 9:75 - The declared return type 'bool' for Image::jpeg is incorrect, got 'false|string'

@MauricioFauth
Copy link
Contributor Author

Looks like Psalm thinks the return type is string|false if $file is null.

'imagejpeg' => ['bool', 'image'=>'GdImage', 'file='=>'string|resource|null', 'quality='=>'int'],
'imagejpeg\'1' => ['string|false', 'image'=>'GdImage', 'file='=>'null', 'quality='=>'int'],

But according to the manual:

  • file
    The path or an open stream resource (which is automatically being closed after this function returns) to save the file to. If not set or null, the raw image stream will be outputted directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants