Skip to content

Commit

Permalink
Differences between legacy and new API
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Feb 23, 2024
1 parent ca03288 commit c938d8c
Show file tree
Hide file tree
Showing 49 changed files with 1,806 additions and 244 deletions.
8 changes: 4 additions & 4 deletions src/Xml/Dom/Assert/assert_cdata.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace VeeWee\Xml\Dom\Assert;

use \DOM\CdataSection;
use \DOM\CDATASection;
use Psl\Type\Exception\AssertException;
use function Psl\Type\instance_of;

/**
* @psalm-assert \DOM\CdataSection $node
* @psalm-assert \DOM\CDATASection $node
* @throws AssertException
*/
function assert_cdata(mixed $node): \DOM\CdataSection
function assert_cdata(mixed $node): \DOM\CDATASection
{
return instance_of(\DOM\CdataSection::class)->assert($node);
return instance_of(\DOM\CDATASection::class)->assert($node);
}
8 changes: 4 additions & 4 deletions src/Xml/Dom/Builder/cdata.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
namespace VeeWee\Xml\Dom\Builder;

use Closure;
use \DOM\CdataSection;
use \DOM\CDATASection;
use \DOM\Node;
use function VeeWee\Xml\Dom\Assert\assert_cdata;
use function VeeWee\Xml\Dom\Locator\Node\detect_document;
use function VeeWee\Xml\Internal\configure;

/**
* @param list<callable(\DOM\CdataSection): \DOM\CdataSection> $configurators
* @param list<callable(\DOM\CDATASection): \DOM\CDATASection> $configurators
*
* @return Closure(\DOM\Node): \DOM\CdataSection
* @return Closure(\DOM\Node): \DOM\CDATASection
*/
function cdata(string $data, ...$configurators): Closure
{
return static function (\DOM\Node $node) use ($data, $configurators): \DOM\CdataSection {
return static function (\DOM\Node $node) use ($data, $configurators): \DOM\CDATASection {
$document = detect_document($node);

return assert_cdata(
Expand Down
3 changes: 2 additions & 1 deletion src/Xml/Dom/Builder/escaped_value.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
function escaped_value(string $value): Closure
{
return static function (\DOM\Element $node) use ($value): \DOM\Element {
$node->nodeValue = htmlspecialchars($value, ENT_XML1|ENT_QUOTES);
// TODO : Add entity subtitution through appendXML ?
$node->textContent = htmlspecialchars($value, ENT_XML1|ENT_QUOTES);

return $node;
};
Expand Down
3 changes: 2 additions & 1 deletion src/Xml/Dom/Builder/value.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
function value(string $value): Closure
{
return static function (\DOM\Element $node) use ($value): \DOM\Element {
$node->nodeValue = $value;
// TODO : Add entity subtitution through appendXML ?
$node->textContent = $value;

return $node;
};
Expand Down
9 changes: 9 additions & 0 deletions src/Xml/Dom/Collection/NodeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ public static function empty(): self
return new self();
}

/**
* @param \DOM\HTMLCollection $list
* @return NodeList<\DOM\Element>

Check failure on line 64 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

MixedReturnTypeCoercion

src/Xml/Dom/Collection/NodeList.php:64:16: MixedReturnTypeCoercion: The declared return type 'VeeWee\Xml\Dom\Collection\NodeList<DOM\Element>' for VeeWee\Xml\Dom\Collection\NodeList::fromDOMHTMLCollection is more specific than the inferred return type 'VeeWee\Xml\Dom\Collection\NodeList<TValue:Iterator as mixed>' (see https://psalm.dev/197)

Check failure on line 64 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

MixedReturnTypeCoercion

src/Xml/Dom/Collection/NodeList.php:64:16: MixedReturnTypeCoercion: The declared return type 'VeeWee\Xml\Dom\Collection\NodeList<DOM\Element>' for VeeWee\Xml\Dom\Collection\NodeList::fromDOMHTMLCollection is more specific than the inferred return type 'VeeWee\Xml\Dom\Collection\NodeList<TValue:Iterator as mixed>' (see https://psalm.dev/197)

Check failure on line 64 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

MixedReturnTypeCoercion

src/Xml/Dom/Collection/NodeList.php:64:16: MixedReturnTypeCoercion: The declared return type 'VeeWee\Xml\Dom\Collection\NodeList<DOM\Element>' for VeeWee\Xml\Dom\Collection\NodeList::fromDOMHTMLCollection is more specific than the inferred return type 'VeeWee\Xml\Dom\Collection\NodeList<TValue:Iterator as mixed>' (see https://psalm.dev/197)

Check failure on line 64 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

MixedReturnTypeCoercion

src/Xml/Dom/Collection/NodeList.php:64:16: MixedReturnTypeCoercion: The declared return type 'VeeWee\Xml\Dom\Collection\NodeList<DOM\Element>' for VeeWee\Xml\Dom\Collection\NodeList::fromDOMHTMLCollection is more specific than the inferred return type 'VeeWee\Xml\Dom\Collection\NodeList<TValue:Iterator as mixed>' (see https://psalm.dev/197)

Check failure on line 64 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

MixedReturnTypeCoercion

src/Xml/Dom/Collection/NodeList.php:64:16: MixedReturnTypeCoercion: The declared return type 'VeeWee\Xml\Dom\Collection\NodeList<DOM\Element>' for VeeWee\Xml\Dom\Collection\NodeList::fromDOMHTMLCollection is more specific than the inferred return type 'VeeWee\Xml\Dom\Collection\NodeList<TValue:Iterator as mixed>' (see https://psalm.dev/197)

Check failure on line 64 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

MixedReturnTypeCoercion

src/Xml/Dom/Collection/NodeList.php:64:16: MixedReturnTypeCoercion: The declared return type 'VeeWee\Xml\Dom\Collection\NodeList<DOM\Element>' for VeeWee\Xml\Dom\Collection\NodeList::fromDOMHTMLCollection is more specific than the inferred return type 'VeeWee\Xml\Dom\Collection\NodeList<TValue:Iterator as mixed>' (see https://psalm.dev/197)
*/
public static function fromDOMHTMLCollection(\DOM\HTMLCollection $list): self
{
return new self(...values($list->getIterator()));

Check failure on line 68 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

MixedReturnTypeCoercion

src/Xml/Dom/Collection/NodeList.php:68:16: MixedReturnTypeCoercion: The type 'VeeWee\Xml\Dom\Collection\NodeList<TValue:Iterator as mixed>' is more general than the declared return type 'VeeWee\Xml\Dom\Collection\NodeList<DOM\Element>' for VeeWee\Xml\Dom\Collection\NodeList::fromDOMHTMLCollection (see https://psalm.dev/197)

Check failure on line 68 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

MixedArgumentTypeCoercion

src/Xml/Dom/Collection/NodeList.php:68:28: MixedArgumentTypeCoercion: Argument 1 of VeeWee\Xml\Dom\Collection\NodeList::__construct expects DOM\Node, but parent type TValue:Iterator as mixed provided (see https://psalm.dev/194)

Check failure on line 68 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

MixedReturnTypeCoercion

src/Xml/Dom/Collection/NodeList.php:68:16: MixedReturnTypeCoercion: The type 'VeeWee\Xml\Dom\Collection\NodeList<TValue:Iterator as mixed>' is more general than the declared return type 'VeeWee\Xml\Dom\Collection\NodeList<DOM\Element>' for VeeWee\Xml\Dom\Collection\NodeList::fromDOMHTMLCollection (see https://psalm.dev/197)

Check failure on line 68 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

MixedArgumentTypeCoercion

src/Xml/Dom/Collection/NodeList.php:68:28: MixedArgumentTypeCoercion: Argument 1 of VeeWee\Xml\Dom\Collection\NodeList::__construct expects DOM\Node, but parent type TValue:Iterator as mixed provided (see https://psalm.dev/194)

Check failure on line 68 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

MixedReturnTypeCoercion

src/Xml/Dom/Collection/NodeList.php:68:16: MixedReturnTypeCoercion: The type 'VeeWee\Xml\Dom\Collection\NodeList<TValue:Iterator as mixed>' is more general than the declared return type 'VeeWee\Xml\Dom\Collection\NodeList<DOM\Element>' for VeeWee\Xml\Dom\Collection\NodeList::fromDOMHTMLCollection (see https://psalm.dev/197)

Check failure on line 68 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

MixedArgumentTypeCoercion

src/Xml/Dom/Collection/NodeList.php:68:28: MixedArgumentTypeCoercion: Argument 1 of VeeWee\Xml\Dom\Collection\NodeList::__construct expects DOM\Node, but parent type TValue:Iterator as mixed provided (see https://psalm.dev/194)

Check failure on line 68 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

MixedReturnTypeCoercion

src/Xml/Dom/Collection/NodeList.php:68:16: MixedReturnTypeCoercion: The type 'VeeWee\Xml\Dom\Collection\NodeList<TValue:Iterator as mixed>' is more general than the declared return type 'VeeWee\Xml\Dom\Collection\NodeList<DOM\Element>' for VeeWee\Xml\Dom\Collection\NodeList::fromDOMHTMLCollection (see https://psalm.dev/197)

Check failure on line 68 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

MixedArgumentTypeCoercion

src/Xml/Dom/Collection/NodeList.php:68:28: MixedArgumentTypeCoercion: Argument 1 of VeeWee\Xml\Dom\Collection\NodeList::__construct expects DOM\Node, but parent type TValue:Iterator as mixed provided (see https://psalm.dev/194)

Check failure on line 68 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

MixedReturnTypeCoercion

src/Xml/Dom/Collection/NodeList.php:68:16: MixedReturnTypeCoercion: The type 'VeeWee\Xml\Dom\Collection\NodeList<TValue:Iterator as mixed>' is more general than the declared return type 'VeeWee\Xml\Dom\Collection\NodeList<DOM\Element>' for VeeWee\Xml\Dom\Collection\NodeList::fromDOMHTMLCollection (see https://psalm.dev/197)

Check failure on line 68 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

MixedArgumentTypeCoercion

src/Xml/Dom/Collection/NodeList.php:68:28: MixedArgumentTypeCoercion: Argument 1 of VeeWee\Xml\Dom\Collection\NodeList::__construct expects DOM\Node, but parent type TValue:Iterator as mixed provided (see https://psalm.dev/194)

Check failure on line 68 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

MixedReturnTypeCoercion

src/Xml/Dom/Collection/NodeList.php:68:16: MixedReturnTypeCoercion: The type 'VeeWee\Xml\Dom\Collection\NodeList<TValue:Iterator as mixed>' is more general than the declared return type 'VeeWee\Xml\Dom\Collection\NodeList<DOM\Element>' for VeeWee\Xml\Dom\Collection\NodeList::fromDOMHTMLCollection (see https://psalm.dev/197)

Check failure on line 68 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

MixedArgumentTypeCoercion

src/Xml/Dom/Collection/NodeList.php:68:28: MixedArgumentTypeCoercion: Argument 1 of VeeWee\Xml\Dom\Collection\NodeList::__construct expects DOM\Node, but parent type TValue:Iterator as mixed provided (see https://psalm.dev/194)
}

/**
* @template X of \DOM\Node
* @param DOMNodeList<X> $list

Check failure on line 73 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

TooManyTemplateParams

src/Xml/Dom/Collection/NodeList.php:73:15: TooManyTemplateParams: DOM\NodeList<X:fn-veewee\xml\dom\collection\nodelist::fromdomnodelist as DOM\Node> has too many template params, expecting 0 (see https://psalm.dev/184)

Check failure on line 73 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

TooManyTemplateParams

src/Xml/Dom/Collection/NodeList.php:73:15: TooManyTemplateParams: DOM\NodeList<X:fn-veewee\xml\dom\collection\nodelist::fromdomnodelist as DOM\Node> has too many template params, expecting 0 (see https://psalm.dev/184)

Check failure on line 73 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

TooManyTemplateParams

src/Xml/Dom/Collection/NodeList.php:73:15: TooManyTemplateParams: DOM\NodeList<X:fn-veewee\xml\dom\collection\nodelist::fromdomnodelist as DOM\Node> has too many template params, expecting 0 (see https://psalm.dev/184)

Check failure on line 73 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

TooManyTemplateParams

src/Xml/Dom/Collection/NodeList.php:73:15: TooManyTemplateParams: DOM\NodeList<X:fn-veewee\xml\dom\collection\nodelist::fromdomnodelist as DOM\Node> has too many template params, expecting 0 (see https://psalm.dev/184)

Check failure on line 73 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

TooManyTemplateParams

src/Xml/Dom/Collection/NodeList.php:73:15: TooManyTemplateParams: DOM\NodeList<X:fn-veewee\xml\dom\collection\nodelist::fromdomnodelist as DOM\Node> has too many template params, expecting 0 (see https://psalm.dev/184)

Check failure on line 73 in src/Xml/Dom/Collection/NodeList.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

TooManyTemplateParams

src/Xml/Dom/Collection/NodeList.php:73:15: TooManyTemplateParams: DOM\NodeList<X:fn-veewee\xml\dom\collection\nodelist::fromdomnodelist as DOM\Node> has too many template params, expecting 0 (see https://psalm.dev/184)
Expand Down
21 changes: 0 additions & 21 deletions src/Xml/Dom/Configurator/loader.php

This file was deleted.

3 changes: 2 additions & 1 deletion src/Xml/Dom/Configurator/pretty_print.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
function pretty_print(): Closure
{
return static function (\DOM\XMLDocument $document): \DOM\XMLDocument {
$document->preserveWhiteSpace = false;
// TODO : not fully implemented yet in the new API
//$document->preserveWhiteSpace = false;
$document->formatOutput = true;

return $document;
Expand Down
3 changes: 2 additions & 1 deletion src/Xml/Dom/Configurator/trim_spaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
function trim_spaces(): Closure
{
return static function (\DOM\XMLDocument $document): \DOM\XMLDocument {
$document->preserveWhiteSpace = false;
// TODO : not fully implemented yet in the new API
//$document->preserveWhiteSpace = false;
$document->formatOutput = false;

return $document;
Expand Down
2 changes: 1 addition & 1 deletion src/Xml/Dom/Configurator/utf8.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
function utf8(): Closure
{
return static function (\DOM\XMLDocument $document): \DOM\XMLDocument {
$document->encoding = 'UTF-8';
$document->charset = 'UTF-8';

return $document;
};
Expand Down
35 changes: 17 additions & 18 deletions src/Xml/Dom/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
use VeeWee\Xml\ErrorHandling\Issue\IssueCollection;
use VeeWee\Xml\Exception\RuntimeException;
use function Psl\Vec\map;
use function VeeWee\Xml\Dom\Configurator\loader;
use function VeeWee\Xml\Dom\Loader\xml_file_loader;
use function VeeWee\Xml\Dom\Loader\xml_node_loader;
use function VeeWee\Xml\Dom\Loader\xml_string_loader;
use function VeeWee\Xml\Dom\Loader;
use function VeeWee\Xml\Dom\Locator\document_element;
use function VeeWee\Xml\Dom\Mapper\xml_string;
use function VeeWee\Xml\Internal\configure;
Expand Down Expand Up @@ -47,18 +44,28 @@ public static function configure(callable ... $configurators): self
}

/**
* @param callable(): XMLDocument $loader
* @param list<callable(XMLDocument): XMLDocument> $configurators
*
* @throws RuntimeException
*/
public static function fromXmlFile(string $file, callable ...$configurators): self
public static function fromLoader(callable $loader, callable ...$configurators): self
{
return new self(
configure(...$configurators)(XMLDocument::createFromFile($file))
// TODO : What with loader(xml_file_loader($file))
configure(...$configurators)($loader())
);
}

/**
* @param list<callable(XMLDocument): XMLDocument> $configurators
*
* @throws RuntimeException
*/
public static function fromXmlFile(string $file, callable ...$configurators): self
{
return self::fromLoader(Loader\xml_file_loader($file), ...$configurators);
}

/**
* @param non-empty-string $xml
* @param list<callable(XMLDocument): XMLDocument> $configurators
Expand All @@ -67,10 +74,7 @@ public static function fromXmlFile(string $file, callable ...$configurators): se
*/
public static function fromXmlString(string $xml, callable ...$configurators): self
{
return new self(
configure(...$configurators)(XMLDocument::createFromString($xml))
// TODO : What with loader(xml_string_loader($file))
);
return self::fromLoader(Loader\xml_string_loader($xml), ...$configurators);
}

/**
Expand All @@ -80,10 +84,7 @@ public static function fromXmlString(string $xml, callable ...$configurators): s
*/
public static function fromXmlNode(\DOM\Node $node, callable ...$configurators): self
{
return self::configure(
loader(xml_node_loader($node)),
...$configurators
);
return self::fromLoader(Loader\xml_node_loader($node), ...$configurators);
}

/**
Expand All @@ -93,9 +94,7 @@ public static function fromXmlNode(\DOM\Node $node, callable ...$configurators):
*/
public static function fromUnsafeDocument(XMLDocument $document, callable ...$configurators): self
{
return new self(
configure(...$configurators)($document)
);
return self::fromLoader(static fn () => $document, ...$configurators);
}

public function toUnsafeDocument(): XMLDocument
Expand Down
2 changes: 1 addition & 1 deletion src/Xml/Dom/Loader/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

interface Loader
{
public function __invoke(\DOM\XMLDocument $document): void;
public function __invoke(): XMLDocument;
}
25 changes: 0 additions & 25 deletions src/Xml/Dom/Loader/load.php

This file was deleted.

18 changes: 8 additions & 10 deletions src/Xml/Dom/Loader/xml_file_loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@
namespace VeeWee\Xml\Dom\Loader;

use Closure;
use \DOM\XMLDocument;
use DOM\XMLDocument;
use Webmozart\Assert\Assert;
use function VeeWee\Xml\ErrorHandling\disallow_issues;

/**
* @param int $options - bitmask of LIBXML_* constants https://www.php.net/manual/en/libxml.constants.php
* @return Closure(\DOM\XMLDocument): void
* @return Closure(): XMLDocument
*/
function xml_file_loader(string $file, int $options = 0): Closure
{
return static function (\DOM\XMLDocument $document) use ($file, $options): void {
load(
static function () use ($document, $file, $options): bool {
Assert::fileExists($file);
return $document->load($file, $options);
}
);
};
return static fn () => disallow_issues(static function () use ($file, $options): XMLDocument {
Assert::fileExists($file);

return XMLDocument::createFromFile($file, $options);
});
}
14 changes: 9 additions & 5 deletions src/Xml/Dom/Loader/xml_node_loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@

use Closure;
use \DOM\XMLDocument;

use \DOM\Node;
use function VeeWee\Xml\Dom\Manipulator\Node\append_external_node;
use function VeeWee\Xml\ErrorHandling\disallow_issues;

/**
* @return Closure(\DOM\XMLDocument): void
* @return Closure(): XMLDocument
*/
function xml_node_loader(\DOM\Node $importedNode): Closure
{
return static function (\DOM\XMLDocument $document) use ($importedNode): void {
load(static fn (): bool => (bool) append_external_node($document, $importedNode));
};
return static fn () => disallow_issues(static function () use ($importedNode): XMLDocument {
$document = XMLDocument::createEmpty();

append_external_node($document, $importedNode);

return $document;
});
}
9 changes: 5 additions & 4 deletions src/Xml/Dom/Loader/xml_string_loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@

use Closure;
use \DOM\XMLDocument;
use function VeeWee\Xml\ErrorHandling\disallow_issues;

/**
* @param non-empty-string $xml
* @param int $options - bitmask of LIBXML_* constants https://www.php.net/manual/en/libxml.constants.php
* @return Closure(\DOM\XMLDocument): void
* @return Closure(): XMLDocument
*/
function xml_string_loader(string $xml, int $options = 0): Closure
{
return static function (\DOM\XMLDocument $document) use ($xml, $options): void {
load(static fn (): bool => $document->loadXML($xml, $options));
};
return static fn () => disallow_issues(static function () use ($xml, $options): XMLDocument {
return XMLDocument::createFromString($xml, $options);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
*/
function locate_by_namespaced_tag_name(\DOM\Element $node, string $namespace, string $localTagName): NodeList
{
return NodeList::fromDOMNodeList($node->getElementsByTagNameNS($namespace, $localTagName));
return NodeList::fromDOMHTMLCollection($node->getElementsByTagNameNS($namespace, $localTagName));
}
2 changes: 1 addition & 1 deletion src/Xml/Dom/Locator/Element/locate_by_tag_name.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
*/
function locate_by_tag_name(\DOM\Element $node, string $tag): NodeList
{
return NodeList::fromDOMNodeList($node->getElementsByTagName($tag));
return NodeList::fromDOMHTMLCollection($node->getElementsByTagName($tag));
}
5 changes: 1 addition & 4 deletions src/Xml/Dom/Locator/Node/detect_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,5 @@
*/
function detect_document(\DOM\Node $node): \DOM\XMLDocument
{
$document = is_document($node) ? $node : $node->ownerDocument;
Assert::notNull($document, 'Expected to find an ownerDocument on provided \DOM\Node.');

return $document;
return is_document($node) ? $node : $node->ownerDocument;
}
5 changes: 4 additions & 1 deletion src/Xml/Dom/Locator/Node/value.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
*/
function value(\DOM\Node $node, TypeInterface $type)
{
return $type->coerce($node->nodeValue);
// TODO : nodeValue did entity substitution
// TODO : nodeValue returns null for elements
// TODO : How to best deal with this?
return $type->coerce($node->textContent ?? '');
}
5 changes: 2 additions & 3 deletions src/Xml/Dom/Manipulator/Element/rename.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace VeeWee\Xml\Dom\Manipulator\Element;

use \DOM\Attr;
use \DOM\Element;
use \DOM\NameSpaceNode;
use VeeWee\Xml\Exception\RuntimeException;
use function VeeWee\Xml\Dom\Builder\element;
Expand Down Expand Up @@ -44,7 +42,8 @@ static function (\DOM\NameSpaceNode $attribute) use ($target, $newElement): void
);

attributes_list($target)->forEach(
static function (\DOM\Attr $attribute) use ($newElement): void {
static function (\DOM\Attr $attribute) use ($target, $newElement): void {
$target->removeAttributeNode($attribute);
$newElement->setAttributeNode($attribute);
}
);
Expand Down
Loading

0 comments on commit c938d8c

Please sign in to comment.