-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Simplify code product alert email #16571
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
Simplify code product alert email #16571
Conversation
Hi @arnoudhgz. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
return self::XML_PATH_EMAIL_PRICE_TEMPLATE; | ||
} | ||
|
||
return self::XML_PATH_EMAIL_STOCK_TEMPLATE; |
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.
Please replace all such conditionals with ternary operator.
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.
@orlangur thank you for your feedback, I changed it...
Hi @arnoudhgz, thank you for collaboration. Please enable |
* | ||
* @return StoreInterface|Store | ||
*/ | ||
private function getStore($customerStoreId) |
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.
Please use type hints
for the method arguments.
* | ||
* @return string | ||
*/ | ||
private function getTemplateConfigPath() |
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.
Please use type hints
for the method arguments.
* | ||
* @return array | ||
*/ | ||
private function getProducts() |
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.
Please use type hints
for the method arguments.
* | ||
* @return Price|Stock | ||
*/ | ||
private function getBlock() |
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.
Please use type hints
for the method arguments.
@VladimirZaets I have added the strict types and included type hinting where possible. I saw some existing protected methods like |
@VladimirZaets I see that with the strict types give now errors in the unit tests. I will first fix this before you have to check again. |
@VladimirZaets I will fix the errors in the unit test first before you have to check again. |
Hi @arnoudhgz, maybe you need any help? |
@VladimirZaets Yes, I would like that. |
@arnoudhgz as I see, the |
@VladimirZaets I had this first as That is why I changed it to |
@arnaucoll I think the problem is in the unit test that returns DataObject. What test is failed? |
@VladimirZaets please see my updated comment with screenshot ^^ |
@arnoudhgz The problem is in the test. Can you please fix it? |
@VladimirZaets it seems solved now. There is only the timeout in Travis. |
@arnoudhgz Thanks for fixes |
Hi @arnoudhgz, can you please make refactoring and use private properties instead of constants. |
@VladimirZaets I can, but it seems wrong, I think the class Do you think I should maybe refactor this Observer also to make the code better (remove complexities)? |
@VladimirZaets are you really sure I should use private properties? These values are constants imho, they can't be changed with setters or inside other functions. According to the defnition of constants on the PHP website:
|
Hi @arnoudhgz. I discussed this question and we take decisions what we should do in the similar cases. |
@VladimirZaets thank you for the explanation, after I changed it to private static variables some test failed in Travis. It was about having to many variables on the class (the maximum is 15). So I changed the code to compare on strings (price or stock). |
Hi @arnoudhgz. I discussed this issue with my teammates and we take the decision that we can't add strict type and type checking to the already existing files due to backward-compatible reason. It's my fail, sorry. Can you please revert the changes related to strict types. Thanks |
@VladimirZaets I will change it back.... 👍 |
@VladimirZaets I removed the strict types checking + the return types and parameter typehinting for existing functions. |
The send method was complex and had some duplication in code. This is improved by using private methods for small parts of this method and making the if/else statements more logical (else isn't even used anymore). As result the PHPMD suppress warning annotations could be removed.
@VladimirZaets do I still need to update the code? Could you provide some feedback? |
Hi @arnoudhgz. Sorry for the delay, we took your PR for delivery |
Hi @arnoudhgz. Thank you for your contribution. |
The send method was complex and had some duplication in code. This is improved by using private methods for small parts of this method and making the if/else statements more logical (else isn't even used anymore).
As result the PHPMD suppress warning annotations could be removed.
For better string comparison the currently defined types (price and stock) are set as constants.
Contribution checklist