-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Fix error when generating urn catalog for empty misc.xml #11686
Fix error when generating urn catalog for empty misc.xml #11686
Conversation
Codacy is not successful, because I used an |
@tdgroot thanks for the PR. I will start to process this now. Do not worry about the codacy check for the else that result seems a bit odd to me. |
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.
At least 1 change to be made for BC reasons. I will get back to you about the changes to the factory class.
*/ | ||
public function __construct( | ||
ReadFactory $readFactory, | ||
\Magento\Framework\Filesystem\File\WriteFactory $fileWriteFactory | ||
FileWriteFactory $fileWriteFactory, | ||
DomDocumentFactory $domDocumentFactory |
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.
This change will break BC try adding an optional dependency here as described in http://devdocs.magento.com/guides/v2.2/contributor-guide/backward-compatible-development/index.html#adding-a-constructor-parameter
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.
I was already wondering how BC was being handled! I'll make the constructor parameter optional for BC.
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.
It might also be a good idea to revert the change made to \Magento\Framework\Filesystem\File\WriteFactory $fileWriteFactory
as this is not specific to your change and I am not 100% sure how BC would work in this case.
*/ | ||
public function create() | ||
public function create($data = null) |
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.
I will need to double check if this will break BC also as according to http://devdocs.magento.com/guides/v2.2/contributor-guide/backward-compatible-development/index.html#adding-parameters-in-public-methods you cannot add new parameters to public methods. Though all BC breaks can be approved let me check internally here and get back to you on this one.
Ok @tdgroot here is what I am thinking so that we do not break BC and then this can be merged into 2.2.
After this has been done and merged we could consider making the more detailed change into the 2.3 release in which case we can make a few more changes with regards to BC. How does that sound to you? |
@dmanners thank you for your feedback. They seem fair points, I'll need to find some time coming week to propose the changes based on your feedback. I have one question, though. How did the changes in |
@tdgroot yes sorry that was my mistake I missed the fact it was optional. That will be fine. |
Hi @dmanners. I added BC to the code and tweaked some parts as well! |
* DomDocumentFactory constructor. | ||
* @param \Magento\Framework\ObjectManagerInterface $objectManager | ||
*/ | ||
public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager) |
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.
Do we need to make the changes to this file or are we always using the new Dom factory class? My worry here is that a change like this will break backwards compatibility.
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.
I see, this breaks BC. I can make the $objectManager
dependency optional?
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.
Technically this is a private class so we could choose to break BC in this case. Otherwise you could also make the object manager a static call. Another thing to note is that the factory should only be concerned with creating the object and not filling it. In this case initializeDocument
in the other factory and calling $dom->loadXML($data)
load in the other factory is not really the way to go in my mind.
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.
You're right. Factories should only instantiate objects. Wouldn't it be better to migrate all the domain specific code back to \Magento\Developer\Model\XmlCatalog\Format\PhpStorm
?
Sorry for all the corrections, refactorings, etc. I'm learning a lot from creating Magento 2 pull requests :).
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.
No worries. I see two options here.
- Migrate all the domain specific code back to the
\Magento\Developer\Model\XmlCatalog\Format\PhpStorm
. - Create our own classes for the two dom documents that have the public methods that we need. Then change the new factories to instantiate these new objects.
Not sure what you would prefer to do. If you do go with the idea of new classes then please have a look through http://devdocs.magento.com/guides/v2.2/coding-standards/technical-guidelines/technical-guidelines.html#2-class-design and of course let me know if you need some assistance.
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.
@tdgroot do you think you will have time to look into this?
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.
@dmanners I'm currently too busy to get working on this PR. Next week I hope to find some time.
Hi @tdgroot if you would like help with this pull request I would be happy to take over and see if we can get this sorted before the end of 2018. How does that sound? |
@dmanners Sure! Rounding up 2017 is getting really busy unfortunately.. |
…e phpstorm specific file
…rns the expected type of object
Fix error when generating urn catalog for empty misc.xml
Description
Fix error when generating urn catalog for existing empty
misc.xml
. I fixed this by creating another DomDocumentFactory, for PhpStorm specificmisc.xml
. This factory checks if the passed data is empty, and if so, create themisc.xml
xml structure that\Magento\Developer\Model\XmlCatalog\Format\PhpStorm
expects.I also changed
\Magento\Framework\DomDocument\DomDocumentFactory
to follow the Magento 2 guidelines and added a Test class for this factory to define the behavior.Fixed Issues (if relevant)
Manual testing scenarios
rm .idea/misc..xml
touch .idea/misc.xml
bin/magento dev:urn-catalog:generate .idea/misc.xml
Contribution checklist