-
-
Notifications
You must be signed in to change notification settings - Fork 440
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
Cast store config image opacity to int (#3727) #3728
Cast store config image opacity to int (#3727) #3728
Conversation
Is it better to fix it at here magento-lts/app/code/core/Mage/Catalog/Helper/Image.php Lines 490 to 500 in 11eca9d
It may be reset by some custom code to |
I agree where this approach actually needs adjustment of some other lines as well c982305 |
Id prefer the original PR ... ... and may later change it to |
@@ -488,12 +488,12 @@ protected function getWatermarkSize() | |||
/** | |||
* Set watermark image opacity | |||
* | |||
* @param int $imageOpacity | |||
* @param int|string $imageOpacity |
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.
why adding string if we cast to int later?
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.
Because Mage::getStoreConfig would pass string there.
So either let's go back to original concept with cast before Mage::getStoreConfig (let's vote with ❤️) or new one with casting to int inside setWatermarkImageOpacity (let's vote with 🎉).
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.
There are several places where Mage::getStoreConfig is cast to int.
Why not add a helper method similiar to getStoreConfigFlag ... ?
public static function getStoreConfigAsInt(string $path, $store = null): int
{
return (int) self::getStoreConfig($path, $store);
}
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.
@kiatng @fballiano pls share your opinion :)
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.
why adding string if we cast to int later?
I think adding string would be correct, b/c string is "valid" too.
Without it code analyze may say "unnecessary casting too int" b/c from Docs only int is expected.
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.
Sorry for late reply, been very busy. getStoreConfigAsInt()
and getStoreConfigAsFloat()
is a good idea. I will support a PR for it. However, I have reservation on imposing strict type on existing functions such as public function setWatermarkImageOpacity(int $imageOpacity)
, it'll break BC.
I think adding string to @param int|string $imageOpacity
is correct.
[edit] May be it'll be even better to specify the type in system.xml
and return the right type with existing getStoreConfig()
or a new function getStoreConfigStrictType()
.
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.
Ill create a PR at the weekend. Thanks :)
edit: i like the idea with system.xml, but for tools like phpstan it guess its more clean to have methods with return types. (and is does not add more complexity to getStoreConfig()).
Think it can be closed. |
should have been fixed by #3736 |
Description (*)
This PR fixes PHP 8.1 exception
Argument #9 ($pct) must be of type int, string given in lib/Varien/Image/Adapter/Gd2.php:504
thrown when custom image opacity is set in admin configuration.Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
Questions or comments
Contribution checklist (*)