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 Imagick method types #2325

Merged
merged 3 commits into from
Apr 5, 2023
Merged

Improve Imagick method types #2325

merged 3 commits into from
Apr 5, 2023

Conversation

zonuexe
Copy link
Contributor

@zonuexe zonuexe commented Apr 4, 2023

Follows Imagick constants and detailed array types.

'Imagick::autoGammaImage' => ['bool', 'channel='=>'int'],
'Imagick::autoLevelImage' => ['bool', 'CHANNEL='=>'string'],
'Imagick::autoGammaImage' => ['bool', 'channel='=>'Imagick::CHANNEL_*'],
'Imagick::autoLevelImage' => ['bool', 'channel='=>'Imagick::CHANNEL_*'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Imagick::compareImageLayers' => ['Imagick', 'method'=>'int'],
'Imagick::compareImages' => ['array', 'compare'=>'imagick', 'metric'=>'int'],
'Imagick::compositeImage' => ['bool', 'composite_object'=>'imagick', 'composite'=>'int', 'x'=>'int', 'y'=>'int', 'channel='=>'int'],
'Imagick::compareImageChannels' => ['array{Imagick,float}', 'image'=>'imagick', 'channeltype'=>'Imagick::CHANNEL_*', 'metrictype'=>'Imagick::METRIC_*'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Imagick::getHDRIEnabled' => ['int'],
'Imagick::getHomeURL' => ['string'],
'Imagick::getImage' => ['Imagick'],
'Imagick::getImageAlphaChannel' => ['int'],
'Imagick::getImageAlphaChannel' => ['bool'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.php.net/manual/en/imagick.getimagealphachannel.php says:

imagick 3.6.0 Returns a bool now; previously, an int was returned.

'Imagick::getImageWidth' => ['int'],
'Imagick::getInterlaceScheme' => ['int'],
'Imagick::getImageWhitePoint' => ['array{x:float,y:float}'],
'Imagick::getImageWidth' => ['0|positive-int'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oddly, getImageWidth is declared as unsigned long width, but getImageHeight seems to be just long height.

'ImagickKernel::separate' => ['array'],
'ImagickKernel::seperate' => ['void'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo?

@@ -5156,12 +5156,11 @@
'ImagickDraw::translate' => ['bool', 'x'=>'float', 'y'=>'float'],
'ImagickKernel::addKernel' => ['void', 'ImagickKernel'=>'ImagickKernel'],
'ImagickKernel::addUnityKernel' => ['void'],
'ImagickKernel::fromBuiltin' => ['ImagickKernel', 'kernelType'=>'string', 'kernelString'=>'string'],
'ImagickKernel::fromBuiltin' => ['ImagickKernel', 'kernelType'=>'Imagick::KERNEL_*', 'kernelString'=>'string'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Imagick::adaptiveResizeImage' => ['bool', 'columns'=>'int', 'rows'=>'int', 'bestfit='=>'bool'],
'Imagick::adaptiveSharpenImage' => ['bool', 'radius'=>'float', 'sigma'=>'float', 'channel='=>'int'],
'Imagick::adaptiveSharpenImage' => ['bool', 'radius'=>'float', 'sigma'=>'float', 'channel='=>'Imagick::CHANNEL_*'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of narrowing down parameter types. It requires people to suddently start typehinting PHPStan-specific types in their PHPDocs instead of int. For the same reason I haven't merged #2163 and #2271 yet.

But I think it'd be fine to introduce these typehints in bleedingEdge/PHPStan 2.0.

I've added support for bleedingEdge-specific functionMap: 06b746d

My suggestion is:

  1. Submit a PR that only changes return types for everyone.
  2. Submit a next PR that changes parameter types in functionMap_bleedingEdge.php.

Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of narrowing down parameter types.

I agree with your policy because it makes sense. Thank you for your review!

@ondrejmirtes ondrejmirtes merged commit 82fa54b into phpstan:1.10.x Apr 5, 2023
1 check passed
@ondrejmirtes
Copy link
Member

Thank you!

@zonuexe zonuexe deleted the types/imagick branch April 5, 2023 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants