Skip to content

Improve image related functions signature#3127

Merged
ondrejmirtes merged 1 commit intophpstan:1.11.xfrom
thg2k:pr/imagecreate
Jun 10, 2024
Merged

Improve image related functions signature#3127
ondrejmirtes merged 1 commit intophpstan:1.11.xfrom
thg2k:pr/imagecreate

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.

- 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
@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.

2 participants