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

Improve image related functions signature #3127

Merged
merged 1 commit into from
Jun 10, 2024

Conversation

thg2k
Copy link
Contributor

@thg2k thg2k commented Jun 5, 2024

  • The parameters involving red, green, blue, and alpha are now required to be in the respective allowed range (0-255 for colors and 0-127 for alpha).
  • Return values are specified in their possible ranges (0-max for color indexes, and 0-256 for imagecolorstotal()).
  • imagecreate() and imagecreatetruecolor() now returns a benevolent union, it can only return false if width x height exceeds INT_MAX, and the size parameters are required to be in the range 1-max.
  • imagesx() and imagesy() return value is in the range 1-max and can no longer return false.
  • Return type of imagecolorsforindex() now contains the array signature.

@thg2k
Copy link
Contributor Author

thg2k commented Jun 9, 2024

@ondrejmirtes What's the feeling about this? I saw the CI integration errors but not sure how I should handle them. Clearly, restricting the parameters type will break people's SA but it is also true that if those restrictions are not met PHP >= 8.0 throws ValueError exceptions... so I figured that's the whole point of SA.

If you are not happy with this I can submit only the return type restrictions, that should cause no problem.

@ondrejmirtes
Copy link
Member

Return type changes: can be in functionMap.php
Narrowed parameter types: need to be in functionMap_bleedingEdge.php.

Thanks.

Verified

This commit was signed with the committer’s verified signature.
JanTvrdik Jan Tvrdík
- The parameters involving red, green, blue, and alpha are now required to be
  in the respective allowed range (0-255 for colors and 0-127 for alpha) in
  bleeding edge mode.
- Return values are specified in their possible ranges (0-max for color
  indexes, and 0-256 for imagecolorstotal()).
- imagecreate() and imagecreatetruecolor() now returns a benevolent union,
  it can only return false if width x height exceeds INT_MAX, and the size
  parameters are required to be in the range 1-max in bleeding edge.
- imagesx() and imagesy() return value is in the range 1-max and can no longer
  return false.
- Return type of imagecolorsforindex() now contains the array signature.
@thg2k thg2k force-pushed the pr/imagecreate branch from ee7b0cd to 4261f2a Compare June 9, 2024 16:41
@thg2k
Copy link
Contributor Author

thg2k commented Jun 9, 2024

Return type changes: can be in functionMap.php Narrowed parameter types: need to be in functionMap_bleedingEdge.php.

Seems reasonable! I pushed the rebased change.

@ondrejmirtes ondrejmirtes merged commit 27cbdd4 into phpstan:1.11.x Jun 10, 2024
442 of 449 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

@thg2k thg2k deleted the pr/imagecreate branch June 10, 2024 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants