Add signatures for GD image*() returning strings.#265
Merged
ondrejmirtes merged 4 commits intophpstan:masterfrom Jul 2, 2020
javajawa:gd-functions-with-null-filenames
Merged
Add signatures for GD image*() returning strings.#265ondrejmirtes merged 4 commits intophpstan:masterfrom javajawa:gd-functions-with-null-filenames
ondrejmirtes merged 4 commits intophpstan:masterfrom
javajawa:gd-functions-with-null-filenames
Conversation
When the image* output functions, such as `imagepng()` are passed `null` as the filename/to parameter, the raw image data is returned from the function. This patch adds this signature for: - `imagebmp` - `imagegd` - `imagegd2` - `imagegif` - `imagejpeg` - `imagepng` - `imagewbmp` - `imagewebp` - `imagexbm`
Author
|
I do not know what to make of the tests failing specifically in php7.4, nor do I see the connection between the binaryOps test and the changes I've made. Suggestions most welcome. |
ondrejmirtes
requested changes
Jul 2, 2020
Member
ondrejmirtes
left a comment
There was a problem hiding this comment.
Yep, the failure is random and unrelated.
| 'imagegd' => ['bool', 'im'=>'resource', 'filename='=>'string|resource|null'], | ||
| 'imagegd2' => ['bool', 'im'=>'resource', 'filename='=>'string|resource|null', 'chunk_size='=>'int', 'type='=>'int'], | ||
| 'imagegd' => ['bool', 'im'=>'resource', 'filename='=>'string|resource'], | ||
| 'imagegd\'1' => ['string', 'im'=>'resource', 'filename='=>'null'], |
Member
There was a problem hiding this comment.
Can you test that ParametersAcceptorSelector will figure this out? Add a new data provider to NodeScopeResolverTest::testFileAsserts and see that the right imagegd() calls lead to bool or string with assertType(), thanks.
added 2 commits
July 2, 2020 15:48
Even when writing the output to the return value, the GD functions are allowed to fail and return `false`. The signatures and tests have been updated to reflect this. In addition, added a specific test for passing a `resource` to `imagegd`.
ondrejmirtes
requested changes
Jul 2, 2020
|
|
||
| assertType('bool', imagegd($image, 'php://memory')); | ||
| assertType('bool', imagegd($image, $memoryHandle)); | ||
| assertType('string|false', imagegd($image, null)); |
Member
There was a problem hiding this comment.
Please verify imagegd($image); too, thanks.
When the function is called as `imagepng($image)`, the output is returned, and thus the expected return type is `string|false`. The previous commits had the second parameter optional for both variants, resulting in PHPStan inferring a return of `string|bool`. Additionally, this parameter has been marked as optional for `imagexbm`, in line with the PHP documentation.
Member
|
Thank you! |
Author
Thank you for the help, hints, and frankly the entire project! |
ondrejmirtes
pushed a commit
that referenced
this pull request
Jul 16, 2020
The GD group of image output functions has the capability to not output to a file, but the raw data is not returned by the function. Instead, the function echos the data into the equivelant of `php://output`, and returns a boolean for success or failure. To quote the wording I previously misread on https://www.php.net/manual/en/function.imagepng.php: > The path or an open stream resource [...] to save the file to. > If not set or NULL, the raw image stream will be outputted directly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the image* output functions, such as
imagepng(), are passednullas the filename/to parameter, the raw image data is returned from the function.This patch adds this signature for:
imagebmpimagegdimagegd2imagegifimagejpegimagepngimagewbmpimagewebpimagexbm