Skip to content
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

Add support for replacing class synopses based on stubs #7340

Merged
merged 5 commits into from
Aug 13, 2021

Conversation

kocsismate
Copy link
Member

No description provided.

build/gen_stub.php Show resolved Hide resolved
build/gen_stub.php Show resolved Hide resolved
@kocsismate
Copy link
Member Author

kocsismate commented Aug 4, 2021

I've just submitted php/doc-en#839 for reference as well

build/gen_stub.php Outdated Show resolved Hide resolved
build/gen_stub.php Outdated Show resolved Hide resolved
build/gen_stub.php Outdated Show resolved Hide resolved
$docComparator->loadXML($xml1);
$xml1 = $docComparator->saveXML();

$originalSynopsis->parentNode->replaceChild($newSynopsis, $originalSynopsis);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in here? This looks unrelated to the comparison.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, even though it makes the function have a side-effect, it's still absolutely required (I tried to clone $originalSynopsis before in order to prevent this, but it didn't work) :/

The reason why we need this code is that it attaches the $newSynopsis element to $doc by replacing $originalSynopsis.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, would using DOMDocument::importNode work? Maybe it's possible to directly import it to $docComparator even?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just tried this:

$docComparator = new DOMDocument();
$docComparator->preserveWhiteSpace = false;
$docComparator->formatOutput = true;
$docComparator->loadXML('<root></root>');

$originalSynopsis = $docComparator->importNode($originalSynopsis, true);
$docComparator->documentElement->appendChild($originalSynopsis);
$xml1 = $docComparator->saveXML($originalSynopsis);

$newSynopsis = $docComparator->importNode($newSynopsis, true);
$docComparator->documentElement->appendChild($newSynopsis);
$newSynopsis->setAttribute("xmlns", "http://docbook.org/ns/docbook");
$xml2 = $docComparator->saveXML($newSynopsis);
$xml2 = getReplacedSynopsisXml($xml2);

return $xml1 === $xml2;

But it still doesn't disregard whitespace changes - I guess because $originalSynopsis keeps the whitespaces. As far as I see that's why we have to first convert the 2 DOMElements to strings, and then load them to the comparator.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, let's stick with what you have then. Maybe rename the function to make it clear that it also modifies, something like replaceAndCompareXml()? Can't think of a great name...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaceAndCompareXml() is not that bad of a name - I don't have any better suggestion.

$docComparator->loadXML($xml1);
$xml1 = $docComparator->saveXML();

$originalSynopsis->parentNode->replaceChild($newSynopsis, $originalSynopsis);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, let's stick with what you have then. Maybe rename the function to make it clear that it also modifies, something like replaceAndCompareXml()? Can't think of a great name...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants