small optimization in if-condition#15002
small optimization in if-condition#15002magento-engcom-team merged 6 commits intomagento:2.2-developfrom
Conversation
| 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.
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