-
Notifications
You must be signed in to change notification settings - Fork 489
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
More precise getimagesize*
return type
#3183
Conversation
resources/functionMap.php
Outdated
@@ -3331,8 +3331,8 @@ | |||
'gethostbyname' => ['string', 'hostname'=>'string'], | |||
'gethostbynamel' => ['list<string>|false', 'hostname'=>'string'], | |||
'gethostname' => ['string|false'], | |||
'getimagesize' => ['array{0:int, 1: int, 2: int, 3: string, mime: string, channels?: int, bits?: int}|false', 'imagefile'=>'string', '&w_info='=>'array'], | |||
'getimagesizefromstring' => ['array{0:int, 1: int, 2: int, 3: string, mime: string, channels?: int, bits?: int}|false', 'data'=>'string', '&w_info='=>'array'], | |||
'getimagesize' => ['array{0: positive-int, 1: 0|positive-int, 2: int, 3: string, mime: string, channels?: int, bits?: int}|false', 'imagefile'=>'string', '&w_info='=>'array'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already handle imagesx
and imagesy
as non-zero return, therefore I turned it eventually into just positive-int
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new version of phpstan found this in our code.
https://phpstan.org/r/f0ef9a4e-00d2-4df9-a129-a79857f28273
But the documentation of PHP says:
Some formats may contain no image or may contain multiple images. In these cases, getimagesize() might not be able to properly determine the image size. getimagesize() will return zero for width and height in these cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see thanks. please open a PR which uses 0|positive-int
instead of positive-int
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. #3207
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mfruehauf thanks!
Also, note that if width is greater than 0, height will necessarily be greater than 0 too. (In your example, there is no need to check for both)
Thank you. |
index 0/1 is width/height of the image which cannot be negative