-
Notifications
You must be signed in to change notification settings - Fork 9.4k
small optimization in if-condition #15002
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
small optimization in if-condition #15002
Conversation
@@ -31,7 +31,7 @@ public function prepareProductAttributes(Product $product, array $productData, a | |||
$considerUseDefaultsAttribute = !isset($useDefaults[$attribute]) || $useDefaults[$attribute] === "1"; | |||
if ($value === '' && $considerUseDefaultsAttribute) { | |||
/** @var $product Product */ | |||
if ((bool)$product->getData($attribute) === (bool)$value) { | |||
if ((bool)$product->getData($attribute) === false) { |
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.
Hi @likemusic , thanks for contribution. In the current case, you can optimize if
condition better, and to avoid the second if
condition inside. That's will looks something like
if ($value === '' && $considerUseDefaultsAttribute && !(bool)$product->getData($attribute)) {
...
}
@VladimirZaets updated according you review. I made more DDD version at https://github.com/likemusic/magento2/blob/fix-prepare-product-attributes-ddd/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php Can I marge it to pull-request's branch? There is if statement moved to separate function. Maybe you can suggest a more appropriate name for the function? 'Protected' access modification used to have possibility override this function if necessary. Is that okay? |
By branches have many small commits. Maybe it's would be better to rebase they into one commit before merging to this pull-request's branch? |
Seems that according to Technical guidelines selected function should be |
Was the annotation for |
Hi @likemusic Also, the better name for this method, I think, something like Uses blank line before return statement is ok. Maybe it's would be better to rebase they into one commit before merging to this pull-request's branch?
In the current case, this is the |
@DaanKouters thanx for notice. It fixed. |
@VladimirZaets, I renamed method to isAttributeShouldNotBeUpdated () because it more accurately reflects what exactly the method does.
It's not clear to me. Why/how Helper class violates the Single responsibility principle?
Did you mean we should introduce new Service Contract interface and create class that implements it?
Why? I still have some misunderstanding about using private/protected access modifiers. I asked related question here. |
|
Hi @likemusic. Thank you for your contribution. |
I still can't understand If we not follow "composition over inheritance" why we keep method private but not protected? I think extensible code is more important and valuable feature then suppressing warnings from meqp-validator. Isn't it? |
Description
There is no needs to cast $value to bool in runtime because it have value === '' by if-condition above
Fixed Issues (if relevant)
Not relevant.
Manual testing scenarios
Not relevant.
Contribution checklist