From 5fbf4d4742b90309fb4ee3aca198f98db91dcb7e Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Wed, 21 Feb 2024 16:06:57 +0100 Subject: [PATCH] Add spec compliance --- src/Xml/Dom/Assert/assert_attribute.php | 8 +-- src/Xml/Dom/Assert/assert_cdata.php | 8 +-- src/Xml/Dom/Assert/assert_document.php | 8 +-- src/Xml/Dom/Assert/assert_dom_node_list.php | 8 +-- src/Xml/Dom/Assert/assert_element.php | 8 +-- src/Xml/Dom/Builder/Builder.php | 4 +- src/Xml/Dom/Builder/attribute.php | 6 +- src/Xml/Dom/Builder/attributes.php | 8 +-- src/Xml/Dom/Builder/cdata.php | 10 +-- src/Xml/Dom/Builder/children.php | 8 +-- src/Xml/Dom/Builder/element.php | 10 +-- src/Xml/Dom/Builder/escaped_value.php | 6 +- src/Xml/Dom/Builder/namespaced_attribute.php | 6 +- src/Xml/Dom/Builder/namespaced_attributes.php | 8 +-- src/Xml/Dom/Builder/namespaced_element.php | 10 +-- src/Xml/Dom/Builder/nodes.php | 18 +++--- src/Xml/Dom/Builder/value.php | 6 +- src/Xml/Dom/Builder/xmlns_attribute.php | 6 +- src/Xml/Dom/Builder/xmlns_attributes.php | 8 +-- src/Xml/Dom/Collection/NodeList.php | 50 +++++++-------- src/Xml/Dom/Configurator/Configurator.php | 4 +- src/Xml/Dom/Configurator/canonicalize.php | 2 +- src/Xml/Dom/Configurator/comparable.php | 4 +- src/Xml/Dom/Configurator/document_uri.php | 6 +- src/Xml/Dom/Configurator/loader.php | 8 +-- src/Xml/Dom/Configurator/normalize.php | 6 +- .../Dom/Configurator/optimize_namespaces.php | 6 +- src/Xml/Dom/Configurator/pretty_print.php | 6 +- src/Xml/Dom/Configurator/traverse.php | 2 +- src/Xml/Dom/Configurator/trim_spaces.php | 6 +- src/Xml/Dom/Configurator/utf8.php | 6 +- src/Xml/Dom/Configurator/validator.php | 8 +-- src/Xml/Dom/Document.php | 64 +++++++++---------- src/Xml/Dom/Loader/Loader.php | 4 +- src/Xml/Dom/Loader/xml_file_loader.php | 6 +- src/Xml/Dom/Loader/xml_node_loader.php | 10 +-- src/Xml/Dom/Loader/xml_string_loader.php | 6 +- .../Dom/Locator/Attribute/attributes_list.php | 8 +-- .../Attribute/xmlns_attributes_list.php | 10 +-- src/Xml/Dom/Locator/Element/ancestors.php | 12 ++-- src/Xml/Dom/Locator/Element/children.php | 12 ++-- .../Element/locate_by_namespaced_tag_name.php | 6 +- .../Locator/Element/locate_by_tag_name.php | 6 +- .../Dom/Locator/Element/parent_element.php | 6 +- src/Xml/Dom/Locator/Element/siblings.php | 12 ++-- src/Xml/Dom/Locator/Node/children.php | 6 +- src/Xml/Dom/Locator/Node/detect_document.php | 8 +-- src/Xml/Dom/Locator/Node/value.php | 4 +- .../Dom/Locator/Xmlns/linked_namespaces.php | 10 +-- .../Xmlns/recursive_linked_namespaces.php | 10 +-- .../Locator/Xsd/locate_all_xsd_schemas.php | 4 +- .../Xsd/locate_namespaced_xsd_schemas.php | 4 +- .../Xsd/locate_no_namespaced_xsd_schemas.php | 4 +- src/Xml/Dom/Locator/document_element.php | 8 +-- .../elements_with_namespaced_tagname.php | 10 +-- src/Xml/Dom/Locator/elements_with_tagname.php | 10 +-- src/Xml/Dom/Locator/root_namespace.php | 6 +- src/Xml/Dom/Manipulator/Attribute/rename.php | 4 +- .../Document/optimize_namespaces.php | 10 +-- .../Element/copy_named_xmlns_attributes.php | 8 +-- src/Xml/Dom/Manipulator/Element/rename.php | 12 ++-- .../Manipulator/Node/append_external_node.php | 4 +- .../Manipulator/Node/import_node_deeply.php | 6 +- src/Xml/Dom/Manipulator/Node/remove.php | 6 +- .../Dom/Manipulator/Node/remove_namespace.php | 8 +-- src/Xml/Dom/Manipulator/Node/rename.php | 4 +- .../Node/replace_by_external_node.php | 6 +- .../Node/replace_by_external_nodes.php | 12 ++-- src/Xml/Dom/Manipulator/Xmlns/rename.php | 24 +++---- src/Xml/Dom/Manipulator/append.php | 8 +-- src/Xml/Dom/Mapper/Mapper.php | 4 +- src/Xml/Dom/Mapper/xml_string.php | 6 +- src/Xml/Dom/Mapper/xslt_template.php | 4 +- src/Xml/Dom/Predicate/is_attribute.php | 10 +-- src/Xml/Dom/Predicate/is_cdata.php | 10 +-- .../Predicate/is_default_xmlns_attribute.php | 6 +- src/Xml/Dom/Predicate/is_document.php | 10 +-- src/Xml/Dom/Predicate/is_document_element.php | 6 +- src/Xml/Dom/Predicate/is_element.php | 10 +-- src/Xml/Dom/Predicate/is_non_empty_text.php | 4 +- src/Xml/Dom/Predicate/is_text.php | 10 +-- src/Xml/Dom/Predicate/is_whitespace.php | 4 +- src/Xml/Dom/Predicate/is_xmlns_attribute.php | 10 +-- src/Xml/Dom/Traverser/Action.php | 4 +- src/Xml/Dom/Traverser/Action/Noop.php | 4 +- src/Xml/Dom/Traverser/Action/RemoveNode.php | 4 +- src/Xml/Dom/Traverser/Action/RenameNode.php | 4 +- src/Xml/Dom/Traverser/Action/ReplaceNode.php | 6 +- src/Xml/Dom/Traverser/Traverser.php | 8 +-- src/Xml/Dom/Traverser/Visitor.php | 6 +- .../Dom/Traverser/Visitor/AbstractVisitor.php | 6 +- .../Traverser/Visitor/RemoveNamespaces.php | 18 +++--- .../Dom/Traverser/Visitor/SortAttributes.php | 10 +-- src/Xml/Dom/Validator/Validator.php | 4 +- .../Dom/Validator/internal_xsd_validator.php | 8 +-- src/Xml/Dom/Validator/validator_chain.php | 10 +-- src/Xml/Dom/Validator/xsd_validator.php | 6 +- src/Xml/Dom/Xpath.php | 16 ++--- .../Dom/Xpath/Configurator/Configurator.php | 4 +- .../Dom/Xpath/Configurator/all_functions.php | 6 +- src/Xml/Dom/Xpath/Configurator/functions.php | 6 +- src/Xml/Dom/Xpath/Configurator/namespaces.php | 6 +- .../Dom/Xpath/Configurator/php_namespace.php | 6 +- src/Xml/Dom/Xpath/Locator/Locator.php | 4 +- src/Xml/Dom/Xpath/Locator/evaluate.php | 10 +-- src/Xml/Dom/Xpath/Locator/query.php | 12 ++-- src/Xml/Dom/Xpath/Locator/query_single.php | 14 ++-- .../Internal/Decoder/Builder/attribute.php | 4 +- .../Internal/Decoder/Builder/attributes.php | 8 +-- .../Internal/Decoder/Builder/element.php | 4 +- .../Decoder/Builder/group_child_elements.php | 6 +- .../Decoder/Builder/grouped_children.php | 10 +-- .../Internal/Decoder/Builder/name.php | 4 +- .../Internal/Decoder/Builder/namespaces.php | 8 +-- .../Internal/Encoder/Builder/children.php | 6 +- .../Internal/Encoder/Builder/element.php | 8 +-- .../Internal/Encoder/Builder/parent_node.php | 6 +- .../Internal/Encoder/Builder/root.php | 6 +- src/Xml/Encoding/document_encode.php | 2 +- src/Xml/Encoding/element_decode.php | 6 +- src/Xml/Encoding/element_encode.php | 2 +- src/Xml/Encoding/typed.php | 4 +- src/Xml/Encoding/xml_decode.php | 2 +- src/Xml/Encoding/xml_encode.php | 2 +- src/Xml/Reader/MatchingNode.php | 2 +- tests/Xml/Dom/Assert/AssertCDataTest.php | 4 +- tests/Xml/Dom/Assert/AssertDocumentTest.php | 4 +- tests/Xml/Dom/Assert/AssertElementTest.php | 4 +- tests/Xml/Dom/Builder/AttributesTest.php | 5 +- tests/Xml/Dom/Builder/CdataTest.php | 13 ++-- tests/Xml/Dom/Builder/ChildrenTest.php | 9 +-- tests/Xml/Dom/Builder/ElementTest.php | 9 +-- tests/Xml/Dom/Builder/EscapedValueTest.php | 5 +- .../Dom/Builder/NamespacedAttributeTest.php | 5 +- .../Xml/Dom/Builder/NamespacedElementTest.php | 23 +++---- tests/Xml/Dom/Builder/NodesTest.php | 7 +- tests/Xml/Dom/Builder/ValueTest.php | 5 +- tests/Xml/Dom/Builder/XmlnsAttributesTest.php | 5 +- tests/Xml/Dom/Collection/NodeListTest.php | 34 +++++----- .../Xml/Dom/Configurator/DocumentUriTest.php | 5 +- tests/Xml/Dom/Configurator/LoaderTest.php | 13 ++-- .../Xml/Dom/Configurator/PrettyPrintTest.php | 6 +- tests/Xml/Dom/Configurator/TraverseTest.php | 4 +- tests/Xml/Dom/Configurator/TrimSpacesTest.php | 6 +- tests/Xml/Dom/Configurator/Utf8Test.php | 6 +- tests/Xml/Dom/Configurator/ValidatorTest.php | 15 +++-- tests/Xml/Dom/DocumentTest.php | 21 +++--- tests/Xml/Dom/Loader/XmlFileLoaderTest.php | 10 +-- tests/Xml/Dom/Loader/XmlNodeLoaderTest.php | 15 ++--- tests/Xml/Dom/Loader/XmlStringLoaderTest.php | 8 +-- .../Locator/Attribute/AttributesListTest.php | 4 +- .../Attribute/XmlnsAttributesListTest.php | 4 +- .../Dom/Locator/Element/ParentElementTest.php | 2 +- .../Dom/Locator/Node/DetectDocumentTest.php | 6 +- .../Locator/Xmlns/LinkedNamespacesTest.php | 4 +- .../Xmlns/RecursiveLinkedNamespacesTest.php | 4 +- .../Dom/Locator/Xsd/LocateXsdSchemasTest.php | 14 ++-- .../Node/AppendExternalNodeTest.php | 30 ++++----- .../Manipulator/Node/ImportNodeDeeplyTest.php | 38 +++++------ tests/Xml/Dom/Manipulator/Node/RemoveTest.php | 2 +- tests/Xml/Dom/Manipulator/Node/RenameTest.php | 2 +- .../Node/ReplaceByExternalNodeTest.php | 35 +++++----- .../Node/ReplaceByExternalNodesTest.php | 59 ++++++++--------- tests/Xml/Dom/Mapper/XmlStringTest.php | 6 +- tests/Xml/Dom/Predicate/IsAttributeTest.php | 4 +- tests/Xml/Dom/Predicate/IsCDataTest.php | 4 +- .../Predicate/IsDefaultXmlnsAttributeTest.php | 6 +- .../Dom/Predicate/IsDocumentElementTest.php | 4 +- tests/Xml/Dom/Predicate/IsDocumentTest.php | 4 +- tests/Xml/Dom/Predicate/IsElementTest.php | 4 +- .../Xml/Dom/Predicate/IsNonEmptyTextTest.php | 4 +- tests/Xml/Dom/Predicate/IsTextTest.php | 4 +- tests/Xml/Dom/Predicate/IsWhitespaceTest.php | 4 +- .../Dom/Predicate/IsXmlnsAttributeTest.php | 6 +- tests/Xml/Dom/Traverser/TraverserTest.php | 14 ++-- .../Xml/Dom/Validator/ValidatorChainTest.php | 2 +- .../Xml/Dom/Xpath/Locator/QuerySingleTest.php | 6 +- 177 files changed, 749 insertions(+), 760 deletions(-) diff --git a/src/Xml/Dom/Assert/assert_attribute.php b/src/Xml/Dom/Assert/assert_attribute.php index 5742eeba..83234f10 100644 --- a/src/Xml/Dom/Assert/assert_attribute.php +++ b/src/Xml/Dom/Assert/assert_attribute.php @@ -4,15 +4,15 @@ namespace VeeWee\Xml\Dom\Assert; -use DOMAttr; +use \DOM\Attr; use Psl\Type\Exception\AssertException; use function Psl\Type\instance_of; /** - * @psalm-assert DOMElement $node + * @psalm-assert \DOM\Element $node * @throws AssertException */ -function assert_attribute(mixed $node): DOMAttr +function assert_attribute(mixed $node): \DOM\Attr { - return instance_of(DOMAttr::class)->assert($node); + return instance_of(\DOM\Attr::class)->assert($node); } diff --git a/src/Xml/Dom/Assert/assert_cdata.php b/src/Xml/Dom/Assert/assert_cdata.php index de96d001..21ca62af 100644 --- a/src/Xml/Dom/Assert/assert_cdata.php +++ b/src/Xml/Dom/Assert/assert_cdata.php @@ -4,15 +4,15 @@ namespace VeeWee\Xml\Dom\Assert; -use DOMCdataSection; +use \DOM\CdataSection; use Psl\Type\Exception\AssertException; use function Psl\Type\instance_of; /** - * @psalm-assert DOMCdataSection $node + * @psalm-assert \DOM\CdataSection $node * @throws AssertException */ -function assert_cdata(mixed $node): DOMCdataSection +function assert_cdata(mixed $node): \DOM\CdataSection { - return instance_of(DOMCdataSection::class)->assert($node); + return instance_of(\DOM\CdataSection::class)->assert($node); } diff --git a/src/Xml/Dom/Assert/assert_document.php b/src/Xml/Dom/Assert/assert_document.php index b3f09ef1..ad536872 100644 --- a/src/Xml/Dom/Assert/assert_document.php +++ b/src/Xml/Dom/Assert/assert_document.php @@ -4,15 +4,15 @@ namespace VeeWee\Xml\Dom\Assert; -use DOMDocument; +use \DOM\XMLDocument; use Psl\Type\Exception\AssertException; use function Psl\Type\instance_of; /** - * @psalm-assert DOMDocument $node + * @psalm-assert \DOM\XMLDocument $node * @throws AssertException */ -function assert_document(mixed $node): DOMDocument +function assert_document(mixed $node): \DOM\XMLDocument { - return instance_of(DOMDocument::class)->assert($node); + return instance_of(\DOM\XMLDocument::class)->assert($node); } diff --git a/src/Xml/Dom/Assert/assert_dom_node_list.php b/src/Xml/Dom/Assert/assert_dom_node_list.php index 6287064c..91ecfe65 100644 --- a/src/Xml/Dom/Assert/assert_dom_node_list.php +++ b/src/Xml/Dom/Assert/assert_dom_node_list.php @@ -4,15 +4,15 @@ namespace VeeWee\Xml\Dom\Assert; -use DOMNodeList; +use \DOM\NodeList; use Psl\Type\Exception\AssertException; use function Psl\Type\instance_of; /** - * @psalm-assert DOMNodeList $node + * @psalm-assert \DOM\NodeList $node * @throws AssertException */ -function assert_dom_node_list(mixed $node): DOMNodeList +function assert_dom_node_list(mixed $node): \DOM\NodeList { - return instance_of(DOMNodeList::class)->assert($node); + return instance_of(\DOM\NodeList::class)->assert($node); } diff --git a/src/Xml/Dom/Assert/assert_element.php b/src/Xml/Dom/Assert/assert_element.php index 2aec5bad..50e2a5b2 100644 --- a/src/Xml/Dom/Assert/assert_element.php +++ b/src/Xml/Dom/Assert/assert_element.php @@ -4,15 +4,15 @@ namespace VeeWee\Xml\Dom\Assert; -use DOMElement; +use \DOM\Element; use Psl\Type\Exception\AssertException; use function Psl\Type\instance_of; /** - * @psalm-assert DOMElement $node + * @psalm-assert \DOM\Element $node * @throws AssertException */ -function assert_element(mixed $node): DOMElement +function assert_element(mixed $node): \DOM\Element { - return instance_of(DOMElement::class)->assert($node); + return instance_of(\DOM\Element::class)->assert($node); } diff --git a/src/Xml/Dom/Builder/Builder.php b/src/Xml/Dom/Builder/Builder.php index 904b1614..06801d13 100644 --- a/src/Xml/Dom/Builder/Builder.php +++ b/src/Xml/Dom/Builder/Builder.php @@ -4,9 +4,9 @@ namespace VeeWee\Xml\Dom\Builder; -use DOMNode; +use \DOM\Node; interface Builder { - public function __invoke(DOMNode $node): DOMNode; + public function __invoke(\DOM\Node $node): \DOM\Node; } diff --git a/src/Xml/Dom/Builder/attribute.php b/src/Xml/Dom/Builder/attribute.php index dee76a31..d7c1a028 100644 --- a/src/Xml/Dom/Builder/attribute.php +++ b/src/Xml/Dom/Builder/attribute.php @@ -5,14 +5,14 @@ namespace VeeWee\Xml\Dom\Builder; use Closure; -use DOMElement; +use \DOM\Element; /** - * @return Closure(DOMElement): DOMElement + * @return Closure(\DOM\Element): \DOM\Element */ function attribute(string $name, string $value): Closure { - return static function (DOMElement $node) use ($name, $value): DOMElement { + return static function (\DOM\Element $node) use ($name, $value): \DOM\Element { $node->setAttribute($name, $value); return $node; diff --git a/src/Xml/Dom/Builder/attributes.php b/src/Xml/Dom/Builder/attributes.php index aaf9dadc..e52f1532 100644 --- a/src/Xml/Dom/Builder/attributes.php +++ b/src/Xml/Dom/Builder/attributes.php @@ -5,19 +5,19 @@ namespace VeeWee\Xml\Dom\Builder; use Closure; -use DOMElement; +use \DOM\Element; use function Psl\Iter\reduce_with_keys; /** * @param array $attributes - * @return Closure(DOMElement): DOMElement + * @return Closure(\DOM\Element): \DOM\Element */ function attributes(array $attributes): Closure { - return static function (DOMElement $node) use ($attributes): DOMElement { + return static function (\DOM\Element $node) use ($attributes): \DOM\Element { return reduce_with_keys( $attributes, - static fn (DOMElement $node, string $name, string $value) + static fn (\DOM\Element $node, string $name, string $value) => attribute($name, $value)($node), $node ); diff --git a/src/Xml/Dom/Builder/cdata.php b/src/Xml/Dom/Builder/cdata.php index c875906d..bcfd39bc 100644 --- a/src/Xml/Dom/Builder/cdata.php +++ b/src/Xml/Dom/Builder/cdata.php @@ -5,20 +5,20 @@ namespace VeeWee\Xml\Dom\Builder; use Closure; -use DOMCdataSection; -use DOMNode; +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 $configurators + * @param list $configurators * - * @return Closure(DOMNode): DOMCdataSection + * @return Closure(\DOM\Node): \DOM\CdataSection */ function cdata(string $data, ...$configurators): Closure { - return static function (DOMNode $node) use ($data, $configurators): DOMCdataSection { + return static function (\DOM\Node $node) use ($data, $configurators): \DOM\CdataSection { $document = detect_document($node); return assert_cdata( diff --git a/src/Xml/Dom/Builder/children.php b/src/Xml/Dom/Builder/children.php index 335eaea5..8d351318 100644 --- a/src/Xml/Dom/Builder/children.php +++ b/src/Xml/Dom/Builder/children.php @@ -5,18 +5,18 @@ namespace VeeWee\Xml\Dom\Builder; use Closure; -use DOMNode; +use \DOM\Node; /** - * @template T of DOMNode + * @template T of \DOM\Node * - * @param list $builders + * @param list $builders * * @return Closure(T): T */ function children(callable ...$builders): Closure { - return static function (DOMNode $node) use ($builders): DOMNode { + return static function (\DOM\Node $node) use ($builders): \DOM\Node { foreach ($builders as $builder) { $node->appendChild($builder($node)); } diff --git a/src/Xml/Dom/Builder/element.php b/src/Xml/Dom/Builder/element.php index 32fedad8..0c8e98d1 100644 --- a/src/Xml/Dom/Builder/element.php +++ b/src/Xml/Dom/Builder/element.php @@ -5,20 +5,20 @@ namespace VeeWee\Xml\Dom\Builder; use Closure; -use DOMElement; -use DOMNode; +use \DOM\Element; +use \DOM\Node; use function VeeWee\Xml\Dom\Assert\assert_element; use function VeeWee\Xml\Dom\Locator\Node\detect_document; use function VeeWee\Xml\Internal\configure; /** - * @param list $configurators + * @param list $configurators * - * @return Closure(DOMNode): DOMElement + * @return Closure(\DOM\Node): \DOM\Element */ function element(string $name, callable ...$configurators): Closure { - return static function (DOMNode $node) use ($name, $configurators): DOMElement { + return static function (\DOM\Node $node) use ($name, $configurators): \DOM\Element { $document = detect_document($node); return assert_element( diff --git a/src/Xml/Dom/Builder/escaped_value.php b/src/Xml/Dom/Builder/escaped_value.php index d2f91ac6..2d63b835 100644 --- a/src/Xml/Dom/Builder/escaped_value.php +++ b/src/Xml/Dom/Builder/escaped_value.php @@ -5,14 +5,14 @@ namespace VeeWee\Xml\Dom\Builder; use Closure; -use DOMElement; +use \DOM\Element; /** - * @return Closure(DOMElement): DOMElement + * @return Closure(\DOM\Element): \DOM\Element */ function escaped_value(string $value): Closure { - return static function (DOMElement $node) use ($value): DOMElement { + return static function (\DOM\Element $node) use ($value): \DOM\Element { $node->nodeValue = htmlspecialchars($value, ENT_XML1|ENT_QUOTES); return $node; diff --git a/src/Xml/Dom/Builder/namespaced_attribute.php b/src/Xml/Dom/Builder/namespaced_attribute.php index bb2b65d5..b4d6c6ac 100644 --- a/src/Xml/Dom/Builder/namespaced_attribute.php +++ b/src/Xml/Dom/Builder/namespaced_attribute.php @@ -5,15 +5,15 @@ namespace VeeWee\Xml\Dom\Builder; use Closure; -use DOMElement; +use \DOM\Element; use function VeeWee\Xml\Assertion\assert_strict_prefixed_name; /** - * @return Closure(DOMElement): DOMElement + * @return Closure(\DOM\Element): \DOM\Element */ function namespaced_attribute(string $namespace, string $qualifiedName, string $value): Closure { - return static function (DOMElement $node) use ($namespace, $qualifiedName, $value): DOMElement { + return static function (\DOM\Element $node) use ($namespace, $qualifiedName, $value): \DOM\Element { assert_strict_prefixed_name($qualifiedName); $node->setAttributeNS($namespace, $qualifiedName, $value); diff --git a/src/Xml/Dom/Builder/namespaced_attributes.php b/src/Xml/Dom/Builder/namespaced_attributes.php index d607154f..27b3364a 100644 --- a/src/Xml/Dom/Builder/namespaced_attributes.php +++ b/src/Xml/Dom/Builder/namespaced_attributes.php @@ -5,19 +5,19 @@ namespace VeeWee\Xml\Dom\Builder; use Closure; -use DOMElement; +use \DOM\Element; use function Psl\Iter\reduce_with_keys; /** * @param array $attributes - * @return Closure(DOMElement): DOMElement + * @return Closure(\DOM\Element): \DOM\Element */ function namespaced_attributes(string $namespace, array $attributes): Closure { - return static function (DOMElement $node) use ($namespace, $attributes): DOMElement { + return static function (\DOM\Element $node) use ($namespace, $attributes): \DOM\Element { return reduce_with_keys( $attributes, - static fn (DOMElement $node, string $name, string $value) + static fn (\DOM\Element $node, string $name, string $value) => namespaced_attribute($namespace, $name, $value)($node), $node ); diff --git a/src/Xml/Dom/Builder/namespaced_element.php b/src/Xml/Dom/Builder/namespaced_element.php index 15dc351e..ed22f65f 100644 --- a/src/Xml/Dom/Builder/namespaced_element.php +++ b/src/Xml/Dom/Builder/namespaced_element.php @@ -5,20 +5,20 @@ namespace VeeWee\Xml\Dom\Builder; use Closure; -use DOMElement; -use DOMNode; +use \DOM\Element; +use \DOM\Node; use function VeeWee\Xml\Dom\Assert\assert_element; use function VeeWee\Xml\Dom\Locator\Node\detect_document; use function VeeWee\Xml\Internal\configure; /** - * @param list $configurators + * @param list $configurators * - * @return Closure(DOMNode): DOMElement + * @return Closure(\DOM\Node): \DOM\Element */ function namespaced_element(string $namespace, string $qualifiedName, callable ...$configurators): Closure { - return static function (DOMNode $node) use ($namespace, $qualifiedName, $configurators): DOMElement { + return static function (\DOM\Node $node) use ($namespace, $qualifiedName, $configurators): \DOM\Element { $document = detect_document($node); return assert_element( diff --git a/src/Xml/Dom/Builder/nodes.php b/src/Xml/Dom/Builder/nodes.php index 49ff522d..bdc4097d 100644 --- a/src/Xml/Dom/Builder/nodes.php +++ b/src/Xml/Dom/Builder/nodes.php @@ -5,30 +5,30 @@ namespace VeeWee\Xml\Dom\Builder; use Closure; -use DOMDocument; -use DOMNode; +use \DOM\XMLDocument; +use \DOM\Node; use function is_array; use function Psl\Iter\reduce; use function VeeWee\Xml\Dom\Locator\Node\detect_document; /** - * @param list|DOMNode)> $builders + * @param list|\DOM\Node)> $builders * - * @return Closure(DOMDocument): list + * @return Closure(\DOM\XMLDocument): list<\DOM\Node> */ function nodes(callable ... $builders): Closure { return /** - * @return list + * @return list<\DOM\Node> */ - static fn (DOMNode $node): array + static fn (\DOM\Node $node): array => reduce( $builders, /** - * @param list $builds - * @param callable(DOMDocument): (DOMNode|list) $builder - * @return list + * @param list<\DOM\Node> $builds + * @param callable(\DOM\XMLDocument): (\DOM\Node|list<\DOM\Node>) $builder + * @return list<\DOM\Node> */ static function (array $builds, callable $builder) use ($node): array { $result = $builder(detect_document($node)); diff --git a/src/Xml/Dom/Builder/value.php b/src/Xml/Dom/Builder/value.php index 28482d69..48c3eb59 100644 --- a/src/Xml/Dom/Builder/value.php +++ b/src/Xml/Dom/Builder/value.php @@ -5,14 +5,14 @@ namespace VeeWee\Xml\Dom\Builder; use Closure; -use DOMElement; +use \DOM\Element; /** - * @return Closure(DOMElement): DOMElement + * @return Closure(\DOM\Element): \DOM\Element */ function value(string $value): Closure { - return static function (DOMElement $node) use ($value): DOMElement { + return static function (\DOM\Element $node) use ($value): \DOM\Element { $node->nodeValue = $value; return $node; diff --git a/src/Xml/Dom/Builder/xmlns_attribute.php b/src/Xml/Dom/Builder/xmlns_attribute.php index e7ae6bd2..6371364d 100644 --- a/src/Xml/Dom/Builder/xmlns_attribute.php +++ b/src/Xml/Dom/Builder/xmlns_attribute.php @@ -5,16 +5,16 @@ namespace VeeWee\Xml\Dom\Builder; use Closure; -use DOMElement; +use \DOM\Element; use VeeWee\Xml\Xmlns\Xmlns; use function VeeWee\Xml\Assertion\assert_strict_prefixed_name; /** - * @return Closure(DOMElement): DOMElement + * @return Closure(\DOM\Element): \DOM\Element */ function xmlns_attribute(string $prefix, string $namespaceURI): Closure { - return static function (DOMElement $node) use ($prefix, $namespaceURI): DOMElement { + return static function (\DOM\Element $node) use ($prefix, $namespaceURI): \DOM\Element { $prefixed = 'xmlns:'.$prefix; assert_strict_prefixed_name($prefixed); diff --git a/src/Xml/Dom/Builder/xmlns_attributes.php b/src/Xml/Dom/Builder/xmlns_attributes.php index cbf6f4d4..4634b2c7 100644 --- a/src/Xml/Dom/Builder/xmlns_attributes.php +++ b/src/Xml/Dom/Builder/xmlns_attributes.php @@ -5,19 +5,19 @@ namespace VeeWee\Xml\Dom\Builder; use Closure; -use DOMElement; +use \DOM\Element; use function Psl\Iter\reduce_with_keys; /** * @param array $attributes - A map of namespace prefix with namespace URI - * @return Closure(DOMElement): DOMElement + * @return Closure(\DOM\Element): \DOM\Element */ function xmlns_attributes(array $attributes): Closure { - return static function (DOMElement $node) use ($attributes): DOMElement { + return static function (\DOM\Element $node) use ($attributes): \DOM\Element { return reduce_with_keys( $attributes, - static fn (DOMElement $node, string $name, string $value) + static fn (\DOM\Element $node, string $name, string $value) => xmlns_attribute($name, $value)($node), $node ); diff --git a/src/Xml/Dom/Collection/NodeList.php b/src/Xml/Dom/Collection/NodeList.php index e9cfd657..8ead96ad 100644 --- a/src/Xml/Dom/Collection/NodeList.php +++ b/src/Xml/Dom/Collection/NodeList.php @@ -5,10 +5,10 @@ namespace VeeWee\Xml\Dom\Collection; use Countable; -use DOMElement; -use DOMNode; -use DOMNodeList; -use DOMXPath; +use \DOM\Element; +use \DOM\Node; +use \DOM\NodeList as DOMNodeList; +use DOMXpath as DOMXpath; use Generator; use InvalidArgumentException; use IteratorAggregate; @@ -29,7 +29,7 @@ use function VeeWee\Xml\Dom\Locator\Element\siblings; /** - * @template T of DOMNode + * @template T of \DOM\Node * @implements IteratorAggregate */ final class NodeList implements Countable, IteratorAggregate @@ -49,7 +49,7 @@ public function __construct(...$nodes) } /** - * @template X of DOMNode + * @template X of \DOM\Node * @return self * * @psalm-suppress InvalidReturnType, InvalidReturnStatement - It is empty alright! @@ -60,7 +60,7 @@ public static function empty(): self } /** - * @template X of DOMNode + * @template X of \DOM\Node * @param DOMNodeList $list * @return NodeList */ @@ -70,7 +70,7 @@ public static function fromDOMNodeList(DOMNodeList $list): self } /** - * @template X of DOMNode + * @template X of \DOM\Node * @param class-string $type * @return NodeList * @throws InvalidArgumentException @@ -136,7 +136,7 @@ public function forEach(callable $mapper): void } /** - * @template X of DOMNode + * @template X of \DOM\Node * @param callable(T): iterable $mapper * * @return NodeList @@ -184,32 +184,32 @@ public function reduce(callable $reducer, mixed $initial): mixed } /** - * @param list $configurators + * @param list $configurators * @throws RuntimeException - * @return NodeList + * @return NodeList<\DOM\Node> */ public function query(string $xpath, callable ... $configurators): self { return $this->detect( /** * @param T $node - * @return NodeList + * @return NodeList<\DOM\Node> */ - static fn (DOMNode $node): NodeList + static fn (\DOM\Node $node): NodeList => Xpath::fromUnsafeNode($node, ...$configurators)->query($xpath, $node) ); } /** * @template X - * @param list $configurators + * @param list $configurators * @param TypeInterface $type * @return list */ public function evaluate(string $expression, TypeInterface $type, callable ... $configurators): array { return $this->map( - static fn (DOMNode $node): mixed + static fn (\DOM\Node $node): mixed => Xpath::fromUnsafeNode($node, ...$configurators)->evaluate($expression, $type, $node) ); } @@ -263,46 +263,46 @@ public function expectLast(string $message = '') } /** - * @return NodeList + * @return NodeList<\DOM\Element> */ public function siblings(): self { return $this->detect( /** - * @return iterable + * @return iterable<\DOM\Element> */ - static fn (DOMNode $node): NodeList => siblings($node) + static fn (\DOM\Node $node): NodeList => siblings($node) ); } /** - * @return NodeList + * @return NodeList<\DOM\Element> */ public function ancestors(): self { return $this->detect( /** - * @return iterable + * @return iterable<\DOM\Element> */ - static fn (DOMNode $node): NodeList => ancestors($node) + static fn (\DOM\Node $node): NodeList => ancestors($node) ); } /** - * @return NodeList + * @return NodeList<\DOM\Element> */ public function children(): self { return $this->detect( /** - * @return iterable + * @return iterable<\DOM\Element> */ - static fn (DOMNode $node): NodeList => children($node) + static fn (\DOM\Node $node): NodeList => children($node) ); } /** - * @template X of DOMNode + * @template X of \DOM\Node * @param class-string $type * @return NodeList * @throws InvalidArgumentException diff --git a/src/Xml/Dom/Configurator/Configurator.php b/src/Xml/Dom/Configurator/Configurator.php index 6c734ad6..253f2a2e 100644 --- a/src/Xml/Dom/Configurator/Configurator.php +++ b/src/Xml/Dom/Configurator/Configurator.php @@ -4,9 +4,9 @@ namespace VeeWee\Xml\Dom\Configurator; -use DOMDocument; +use \DOM\XMLDocument; interface Configurator { - public function __invoke(DOMDocument $document): DOMDocument; + public function __invoke(\DOM\XMLDocument $document): \DOM\XMLDocument; } diff --git a/src/Xml/Dom/Configurator/canonicalize.php b/src/Xml/Dom/Configurator/canonicalize.php index 4ccb45e6..7acda151 100644 --- a/src/Xml/Dom/Configurator/canonicalize.php +++ b/src/Xml/Dom/Configurator/canonicalize.php @@ -5,7 +5,7 @@ namespace VeeWee\Xml\Dom\Configurator; use Closure; -use DOMDocument; +use \DOM\XMLDocument as DOMDocument; use VeeWee\Xml\Dom\Document; use function Psl\Type\non_empty_string; use function VeeWee\Xml\Dom\Loader\xml_string_loader; diff --git a/src/Xml/Dom/Configurator/comparable.php b/src/Xml/Dom/Configurator/comparable.php index c15bf473..07e40447 100644 --- a/src/Xml/Dom/Configurator/comparable.php +++ b/src/Xml/Dom/Configurator/comparable.php @@ -5,12 +5,12 @@ namespace VeeWee\Xml\Dom\Configurator; use Closure; -use DOMDocument; +use \DOM\XMLDocument; use VeeWee\Xml\Dom\Traverser\Visitor\SortAttributes; use function VeeWee\Xml\Internal\configure; /** - * @return Closure(DOMDocument): DOMDocument + * @return Closure(\DOM\XMLDocument): \DOM\XMLDocument */ function comparable(): Closure { diff --git a/src/Xml/Dom/Configurator/document_uri.php b/src/Xml/Dom/Configurator/document_uri.php index 27a20b3b..75108665 100644 --- a/src/Xml/Dom/Configurator/document_uri.php +++ b/src/Xml/Dom/Configurator/document_uri.php @@ -5,15 +5,15 @@ namespace VeeWee\Xml\Dom\Configurator; use Closure; -use DOMDocument; +use \DOM\XMLDocument; /** * @param non-empty-string $documentUri - * @return Closure(DOMDocument): DOMDocument + * @return Closure(\DOM\XMLDocument): \DOM\XMLDocument */ function document_uri(string $documentUri): Closure { - return static function (DOMDocument $document) use ($documentUri) : DOMDocument { + return static function (\DOM\XMLDocument $document) use ($documentUri) : \DOM\XMLDocument { $document->documentURI = $documentUri; return $document; diff --git a/src/Xml/Dom/Configurator/loader.php b/src/Xml/Dom/Configurator/loader.php index ba469da1..fe5bb569 100644 --- a/src/Xml/Dom/Configurator/loader.php +++ b/src/Xml/Dom/Configurator/loader.php @@ -5,16 +5,16 @@ namespace VeeWee\Xml\Dom\Configurator; use Closure; -use DOMDocument; +use \DOM\XMLDocument; /** - * @param callable(DOMDocument): void $loader + * @param callable(\DOM\XMLDocument): void $loader * - * @return Closure(DOMDocument): DOMDocument + * @return Closure(\DOM\XMLDocument): \DOM\XMLDocument */ function loader(callable $loader): Closure { - return static function (DOMDocument $document) use ($loader): DOMDocument { + return static function (\DOM\XMLDocument $document) use ($loader): \DOM\XMLDocument { $loader($document); return $document; }; diff --git a/src/Xml/Dom/Configurator/normalize.php b/src/Xml/Dom/Configurator/normalize.php index 502a9852..0dc0df81 100644 --- a/src/Xml/Dom/Configurator/normalize.php +++ b/src/Xml/Dom/Configurator/normalize.php @@ -5,14 +5,14 @@ namespace VeeWee\Xml\Dom\Configurator; use Closure; -use DOMDocument; +use \DOM\XMLDocument; /** - * @return Closure(DOMDocument): DOMDocument + * @return Closure(\DOM\XMLDocument): \DOM\XMLDocument */ function normalize(): Closure { - return static function (DOMDocument $document): DOMDocument { + return static function (\DOM\XMLDocument $document): \DOM\XMLDocument { $document->normalizeDocument(); return $document; diff --git a/src/Xml/Dom/Configurator/optimize_namespaces.php b/src/Xml/Dom/Configurator/optimize_namespaces.php index 49f2a884..312fc278 100644 --- a/src/Xml/Dom/Configurator/optimize_namespaces.php +++ b/src/Xml/Dom/Configurator/optimize_namespaces.php @@ -5,15 +5,15 @@ namespace VeeWee\Xml\Dom\Configurator; use Closure; -use DOMDocument; +use \DOM\XMLDocument; use function VeeWee\Xml\Dom\Manipulator\Document\optimize_namespaces as optimize_namespaces_manipulator; /** - * @return Closure(DOMDocument): DOMDocument + * @return Closure(\DOM\XMLDocument): \DOM\XMLDocument */ function optimize_namespaces(string $prefix = 'ns'): Closure { - return static function (DOMDocument $document) use ($prefix) : DOMDocument { + return static function (\DOM\XMLDocument $document) use ($prefix) : \DOM\XMLDocument { optimize_namespaces_manipulator($document, $prefix); return $document; diff --git a/src/Xml/Dom/Configurator/pretty_print.php b/src/Xml/Dom/Configurator/pretty_print.php index 9fd845f7..a6977006 100644 --- a/src/Xml/Dom/Configurator/pretty_print.php +++ b/src/Xml/Dom/Configurator/pretty_print.php @@ -5,14 +5,14 @@ namespace VeeWee\Xml\Dom\Configurator; use Closure; -use DOMDocument; +use \DOM\XMLDocument; /** - * @return Closure(DOMDocument): DOMDocument + * @return Closure(\DOM\XMLDocument): \DOM\XMLDocument */ function pretty_print(): Closure { - return static function (DOMDocument $document): DOMDocument { + return static function (\DOM\XMLDocument $document): \DOM\XMLDocument { $document->preserveWhiteSpace = false; $document->formatOutput = true; diff --git a/src/Xml/Dom/Configurator/traverse.php b/src/Xml/Dom/Configurator/traverse.php index 2416eac8..032a433c 100644 --- a/src/Xml/Dom/Configurator/traverse.php +++ b/src/Xml/Dom/Configurator/traverse.php @@ -5,7 +5,7 @@ namespace VeeWee\Xml\Dom\Configurator; use Closure; -use DOMDocument; +use \DOM\XMLDocument as DOMDocument; use VeeWee\Xml\Dom\Document; use VeeWee\Xml\Dom\Traverser\Visitor; diff --git a/src/Xml/Dom/Configurator/trim_spaces.php b/src/Xml/Dom/Configurator/trim_spaces.php index 48cfc9a5..60097497 100644 --- a/src/Xml/Dom/Configurator/trim_spaces.php +++ b/src/Xml/Dom/Configurator/trim_spaces.php @@ -5,14 +5,14 @@ namespace VeeWee\Xml\Dom\Configurator; use Closure; -use DOMDocument; +use \DOM\XMLDocument; /** - * @return Closure(DOMDocument): DOMDocument + * @return Closure(\DOM\XMLDocument): \DOM\XMLDocument */ function trim_spaces(): Closure { - return static function (DOMDocument $document): DOMDocument { + return static function (\DOM\XMLDocument $document): \DOM\XMLDocument { $document->preserveWhiteSpace = false; $document->formatOutput = false; diff --git a/src/Xml/Dom/Configurator/utf8.php b/src/Xml/Dom/Configurator/utf8.php index 627feef3..688aaf22 100644 --- a/src/Xml/Dom/Configurator/utf8.php +++ b/src/Xml/Dom/Configurator/utf8.php @@ -5,14 +5,14 @@ namespace VeeWee\Xml\Dom\Configurator; use Closure; -use DOMDocument; +use \DOM\XMLDocument; /** - * @return Closure(DOMDocument): DOMDocument + * @return Closure(\DOM\XMLDocument): \DOM\XMLDocument */ function utf8(): Closure { - return static function (DOMDocument $document): DOMDocument { + return static function (\DOM\XMLDocument $document): \DOM\XMLDocument { $document->encoding = 'UTF-8'; return $document; diff --git a/src/Xml/Dom/Configurator/validator.php b/src/Xml/Dom/Configurator/validator.php index b263ef89..af1b70e4 100644 --- a/src/Xml/Dom/Configurator/validator.php +++ b/src/Xml/Dom/Configurator/validator.php @@ -5,16 +5,16 @@ namespace VeeWee\Xml\Dom\Configurator; use Closure; -use DOMDocument; +use \DOM\XMLDocument; use VeeWee\Xml\ErrorHandling\Issue\Issue; use VeeWee\Xml\ErrorHandling\Issue\IssueCollection; use VeeWee\Xml\ErrorHandling\Issue\Level; use VeeWee\Xml\Exception\RuntimeException; /** - * @param callable(DOMDocument): IssueCollection $validator + * @param callable(\DOM\XMLDocument): IssueCollection $validator * - * @return Closure(DOMDocument): DOMDocument + * @return Closure(\DOM\XMLDocument): \DOM\XMLDocument */ function validator(callable $validator, ?Level $minimumLevel = null): Closure { @@ -24,7 +24,7 @@ function validator(callable $validator, ?Level $minimumLevel = null): Closure /** * @throws RuntimeException */ - static function (DOMDocument $document) use ($validator, $minimumLevel): DOMDocument { + static function (\DOM\XMLDocument $document) use ($validator, $minimumLevel): \DOM\XMLDocument { $issues = $validator($document) ->filter(static fn (Issue $issue): bool => $issue->level()->value() >= $minimumLevel->value()); diff --git a/src/Xml/Dom/Document.php b/src/Xml/Dom/Document.php index 448d39fc..c2922c91 100644 --- a/src/Xml/Dom/Document.php +++ b/src/Xml/Dom/Document.php @@ -5,10 +5,10 @@ namespace VeeWee\Xml\Dom; use Closure; -use DOMDocument; -use DOMElement; -use DOMNode; -use DOMXPath; +use \DOM\XMLDocument; +use \DOM\Element; +use \DOM\Node; +use \DOM\XPath; use VeeWee\Xml\Dom\Traverser\Traverser; use VeeWee\Xml\Dom\Traverser\Visitor; use VeeWee\Xml\ErrorHandling\Issue\IssueCollection; @@ -25,60 +25,60 @@ final class Document { private function __construct( - private DOMDocument $document + private XMLDocument $document ) { } public static function empty(): self { - return new self(new DOMDocument()); + return new self(XMLDocument::createEmpty()); } /** - * @param list $configurators + * @param list $configurators * * @throws RuntimeException */ public static function configure(callable ... $configurators): self { - $document = configure(...$configurators)(new DOMDocument()); + $document = configure(...$configurators)(XMLDocument::createEmpty()); return new self($document); } /** - * @param list $configurators + * @param list $configurators * * @throws RuntimeException */ public static function fromXmlFile(string $file, callable ...$configurators): self { - return self::configure( - loader(xml_file_loader($file)), - ...$configurators + return new self( + configure(...$configurators)(XMLDocument::createFromFile($file)) + // TODO : What with loader(xml_file_loader($file)) ); } /** * @param non-empty-string $xml - * @param list $configurators + * @param list $configurators * * @throws RuntimeException */ public static function fromXmlString(string $xml, callable ...$configurators): self { - return self::configure( - loader(xml_string_loader($xml)), - ...$configurators + return new self( + configure(...$configurators)(XMLDocument::createFromString($xml)) + // TODO : What with loader(xml_string_loader($file)) ); } /** - * @param list $configurators + * @param list $configurators * * @throws RuntimeException */ - public static function fromXmlNode(DOMNode $node, callable ...$configurators): self + public static function fromXmlNode(\DOM\Node $node, callable ...$configurators): self { return self::configure( loader(xml_node_loader($node)), @@ -87,25 +87,25 @@ public static function fromXmlNode(DOMNode $node, callable ...$configurators): s } /** - * @param list $configurators + * @param list $configurators * * @throws RuntimeException */ - public static function fromUnsafeDocument(DOMDocument $document, callable ...$configurators): self + public static function fromUnsafeDocument(XMLDocument $document, callable ...$configurators): self { return new self( configure(...$configurators)($document) ); } - public function toUnsafeDocument(): DOMDocument + public function toUnsafeDocument(): XMLDocument { return $this->document; } /** * @template T - * @param callable(DOMDocument): T $locator + * @param callable(XMLDocument): T $locator * * @return T */ @@ -114,13 +114,13 @@ public function locate(callable $locator) return $locator($this->document); } - public function locateDocumentElement(): DOMElement + public function locateDocumentElement(): \DOM\Element { return $this->locate(Locator\document_element()); } /** - * @param callable(DOMDocument): mixed $manipulator + * @param callable(XMLDocument): mixed $manipulator * * @return $this */ @@ -132,9 +132,9 @@ public function manipulate(callable $manipulator): self } /** - * @param list|DOMNode)> $builders + * @param list|\DOM\Node)> $builders * - * @return list + * @return list<\DOM\Node> */ public function build(callable ... $builders): array { @@ -145,7 +145,7 @@ public function build(callable ... $builders): array } /** - * @param callable(DOMDocument): IssueCollection $validator + * @param callable(XMLDocument): IssueCollection $validator */ public function validate(callable $validator): IssueCollection { @@ -153,7 +153,7 @@ public function validate(callable $validator): IssueCollection } /** - * @param list $configurators + * @param list $configurators */ public function xpath(callable ...$configurators): Xpath { @@ -162,7 +162,7 @@ public function xpath(callable ...$configurators): Xpath /** * @template T - * @param callable(DOMDocument): T $mapper + * @param callable(XMLDocument): T $mapper * * @return T */ @@ -172,7 +172,7 @@ public function map(callable $mapper) } /** - * @param list $configurators + * @param list $configurators * * @throws RuntimeException */ @@ -184,7 +184,7 @@ public function reconfigure(callable ... $configurators): self /** * @no-named-arguments */ - public function traverse(Visitor ... $visitors): DOMNode + public function traverse(Visitor ... $visitors): \DOM\Node { $traverser = new Traverser(...$visitors); return $traverser->traverse($this->map(document_element())); @@ -209,7 +209,7 @@ public function stringifyDocumentElement(): string /** * @return non-empty-string */ - public function stringifyNode(DOMNode $node): string + public function stringifyNode(\DOM\Node $node): string { return xml_string()($node); } diff --git a/src/Xml/Dom/Loader/Loader.php b/src/Xml/Dom/Loader/Loader.php index 84813182..98b1e5e1 100644 --- a/src/Xml/Dom/Loader/Loader.php +++ b/src/Xml/Dom/Loader/Loader.php @@ -4,9 +4,9 @@ namespace VeeWee\Xml\Dom\Loader; -use DOMDocument; +use \DOM\XMLDocument; interface Loader { - public function __invoke(DOMDocument $document): void; + public function __invoke(\DOM\XMLDocument $document): void; } diff --git a/src/Xml/Dom/Loader/xml_file_loader.php b/src/Xml/Dom/Loader/xml_file_loader.php index ce76dabb..a7126ca9 100644 --- a/src/Xml/Dom/Loader/xml_file_loader.php +++ b/src/Xml/Dom/Loader/xml_file_loader.php @@ -5,16 +5,16 @@ namespace VeeWee\Xml\Dom\Loader; use Closure; -use DOMDocument; +use \DOM\XMLDocument; use Webmozart\Assert\Assert; /** * @param int $options - bitmask of LIBXML_* constants https://www.php.net/manual/en/libxml.constants.php - * @return Closure(DOMDocument): void + * @return Closure(\DOM\XMLDocument): void */ function xml_file_loader(string $file, int $options = 0): Closure { - return static function (DOMDocument $document) use ($file, $options): void { + return static function (\DOM\XMLDocument $document) use ($file, $options): void { load( static function () use ($document, $file, $options): bool { Assert::fileExists($file); diff --git a/src/Xml/Dom/Loader/xml_node_loader.php b/src/Xml/Dom/Loader/xml_node_loader.php index 01c254aa..7a5f1ef1 100644 --- a/src/Xml/Dom/Loader/xml_node_loader.php +++ b/src/Xml/Dom/Loader/xml_node_loader.php @@ -5,17 +5,17 @@ namespace VeeWee\Xml\Dom\Loader; use Closure; -use DOMDocument; +use \DOM\XMLDocument; -use DOMNode; +use \DOM\Node; use function VeeWee\Xml\Dom\Manipulator\Node\append_external_node; /** - * @return Closure(DOMDocument): void + * @return Closure(\DOM\XMLDocument): void */ -function xml_node_loader(DOMNode $importedNode): Closure +function xml_node_loader(\DOM\Node $importedNode): Closure { - return static function (DOMDocument $document) use ($importedNode): void { + return static function (\DOM\XMLDocument $document) use ($importedNode): void { load(static fn (): bool => (bool) append_external_node($document, $importedNode)); }; } diff --git a/src/Xml/Dom/Loader/xml_string_loader.php b/src/Xml/Dom/Loader/xml_string_loader.php index f80f183a..8191be2a 100644 --- a/src/Xml/Dom/Loader/xml_string_loader.php +++ b/src/Xml/Dom/Loader/xml_string_loader.php @@ -5,16 +5,16 @@ namespace VeeWee\Xml\Dom\Loader; use Closure; -use DOMDocument; +use \DOM\XMLDocument; /** * @param non-empty-string $xml * @param int $options - bitmask of LIBXML_* constants https://www.php.net/manual/en/libxml.constants.php - * @return Closure(DOMDocument): void + * @return Closure(\DOM\XMLDocument): void */ function xml_string_loader(string $xml, int $options = 0): Closure { - return static function (DOMDocument $document) use ($xml, $options): void { + return static function (\DOM\XMLDocument $document) use ($xml, $options): void { load(static fn (): bool => $document->loadXML($xml, $options)); }; } diff --git a/src/Xml/Dom/Locator/Attribute/attributes_list.php b/src/Xml/Dom/Locator/Attribute/attributes_list.php index 85384117..a8221ad3 100644 --- a/src/Xml/Dom/Locator/Attribute/attributes_list.php +++ b/src/Xml/Dom/Locator/Attribute/attributes_list.php @@ -4,16 +4,16 @@ namespace VeeWee\Xml\Dom\Locator\Attribute; -use DOMAttr; -use DOMNode; +use \DOM\Attr; +use \DOM\Node; use VeeWee\Xml\Dom\Collection\NodeList; use function Psl\Vec\values; use function VeeWee\Xml\Dom\Predicate\is_element; /** - * @return NodeList + * @return NodeList<\DOM\Attr> */ -function attributes_list(DOMNode $node): NodeList +function attributes_list(\DOM\Node $node): NodeList { if (!is_element($node)) { return NodeList::empty(); diff --git a/src/Xml/Dom/Locator/Attribute/xmlns_attributes_list.php b/src/Xml/Dom/Locator/Attribute/xmlns_attributes_list.php index 9a5f51ce..e82545ba 100644 --- a/src/Xml/Dom/Locator/Attribute/xmlns_attributes_list.php +++ b/src/Xml/Dom/Locator/Attribute/xmlns_attributes_list.php @@ -4,23 +4,23 @@ namespace VeeWee\Xml\Dom\Locator\Attribute; -use DOMNameSpaceNode; -use DOMNode; +use \DOM\NameSpaceNode; +use \DOM\Node; use VeeWee\Xml\Dom\Collection\NodeList; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\Dom\Locator\Xmlns\linked_namespaces; use function VeeWee\Xml\Dom\Predicate\is_element; /** - * @return NodeList + * @return NodeList<\DOM\NameSpaceNode> * @throws RuntimeException */ -function xmlns_attributes_list(DOMNode $node): NodeList +function xmlns_attributes_list(\DOM\Node $node): NodeList { if (! is_element($node)) { return NodeList::empty(); } return linked_namespaces($node) - ->filter(static fn (DOMNameSpaceNode $namespace): bool => $node->hasAttribute($namespace->nodeName)); + ->filter(static fn (\DOM\NameSpaceNode $namespace): bool => $node->hasAttribute($namespace->nodeName)); } diff --git a/src/Xml/Dom/Locator/Element/ancestors.php b/src/Xml/Dom/Locator/Element/ancestors.php index 6510c5b5..3787aa5e 100644 --- a/src/Xml/Dom/Locator/Element/ancestors.php +++ b/src/Xml/Dom/Locator/Element/ancestors.php @@ -4,23 +4,23 @@ namespace VeeWee\Xml\Dom\Locator\Element; -use DOMElement; -use DOMNode; +use \DOM\Element; +use \DOM\Node; use Generator; use VeeWee\Xml\Dom\Collection\NodeList; use function VeeWee\Xml\Dom\Predicate\is_element; /** - * @return NodeList + * @return NodeList<\DOM\Element> */ -function ancestors(DOMNode $node): NodeList +function ancestors(\DOM\Node $node): NodeList { return new NodeList( ...( /** - * @return Generator + * @return Generator */ - static function (DOMNode $next) { + static function (\DOM\Node $next) { while (($parent = $next->parentNode) !== null) { if (is_element($parent)) { yield $parent; diff --git a/src/Xml/Dom/Locator/Element/children.php b/src/Xml/Dom/Locator/Element/children.php index 592824d0..8b7a9fbb 100644 --- a/src/Xml/Dom/Locator/Element/children.php +++ b/src/Xml/Dom/Locator/Element/children.php @@ -4,21 +4,21 @@ namespace VeeWee\Xml\Dom\Locator\Element; -use DOMElement; -use DOMNode; +use \DOM\Element; +use \DOM\Node; use VeeWee\Xml\Dom\Collection\NodeList; use function Psl\Vec\filter; use function VeeWee\Xml\Dom\Predicate\is_element; /** - * @return NodeList + * @return NodeList<\DOM\Element> */ -function children(DOMNode $node): NodeList +function children(\DOM\Node $node): NodeList { - /** @var list $children */ + /** @var list<\DOM\Element> $children */ $children = filter( $node->childNodes, - static fn (DOMNode $node): bool => is_element($node) + static fn (\DOM\Node $node): bool => is_element($node) ); return new NodeList(...$children); diff --git a/src/Xml/Dom/Locator/Element/locate_by_namespaced_tag_name.php b/src/Xml/Dom/Locator/Element/locate_by_namespaced_tag_name.php index a70caaa3..5124bb5f 100644 --- a/src/Xml/Dom/Locator/Element/locate_by_namespaced_tag_name.php +++ b/src/Xml/Dom/Locator/Element/locate_by_namespaced_tag_name.php @@ -4,13 +4,13 @@ namespace VeeWee\Xml\Dom\Locator\Element; -use DOMElement; +use \DOM\Element; use VeeWee\Xml\Dom\Collection\NodeList; /** - * @return NodeList + * @return NodeList<\DOM\Element> */ -function locate_by_namespaced_tag_name(DOMElement $node, string $namespace, string $localTagName): NodeList +function locate_by_namespaced_tag_name(\DOM\Element $node, string $namespace, string $localTagName): NodeList { return NodeList::fromDOMNodeList($node->getElementsByTagNameNS($namespace, $localTagName)); } diff --git a/src/Xml/Dom/Locator/Element/locate_by_tag_name.php b/src/Xml/Dom/Locator/Element/locate_by_tag_name.php index e091a610..b134ca20 100644 --- a/src/Xml/Dom/Locator/Element/locate_by_tag_name.php +++ b/src/Xml/Dom/Locator/Element/locate_by_tag_name.php @@ -4,13 +4,13 @@ namespace VeeWee\Xml\Dom\Locator\Element; -use DOMElement; +use \DOM\Element; use VeeWee\Xml\Dom\Collection\NodeList; /** - * @return NodeList + * @return NodeList<\DOM\Element> */ -function locate_by_tag_name(DOMElement $node, string $tag): NodeList +function locate_by_tag_name(\DOM\Element $node, string $tag): NodeList { return NodeList::fromDOMNodeList($node->getElementsByTagName($tag)); } diff --git a/src/Xml/Dom/Locator/Element/parent_element.php b/src/Xml/Dom/Locator/Element/parent_element.php index 95c4cf47..4e6ebcd5 100644 --- a/src/Xml/Dom/Locator/Element/parent_element.php +++ b/src/Xml/Dom/Locator/Element/parent_element.php @@ -4,15 +4,15 @@ namespace VeeWee\Xml\Dom\Locator\Element; -use DOMElement; -use DOMNode; +use \DOM\Element; +use \DOM\Node; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\Dom\Predicate\is_element; /** * @throws RuntimeException */ -function parent_element(DOMNode $child): DOMElement +function parent_element(\DOM\Node $child): \DOM\Element { $parent = $child->parentNode; if (!$parent|| !is_element($parent)) { diff --git a/src/Xml/Dom/Locator/Element/siblings.php b/src/Xml/Dom/Locator/Element/siblings.php index fc6d8098..9cba8c07 100644 --- a/src/Xml/Dom/Locator/Element/siblings.php +++ b/src/Xml/Dom/Locator/Element/siblings.php @@ -4,21 +4,21 @@ namespace VeeWee\Xml\Dom\Locator\Element; -use DOMElement; -use DOMNode; +use \DOM\Element; +use \DOM\Node; use VeeWee\Xml\Dom\Collection\NodeList; use function Psl\Vec\filter; use function VeeWee\Xml\Dom\Predicate\is_element; /** - * @return NodeList + * @return NodeList<\DOM\Element> */ -function siblings(DOMNode $node): NodeList +function siblings(\DOM\Node $node): NodeList { - /** @var NodeList $siblings */ + /** @var NodeList<\DOM\Element> $siblings */ $siblings = new NodeList(...filter( $node->parentNode?->childNodes?->getIterator() ?? [], - static fn (DOMNode $sibling): bool => is_element($sibling) && $sibling !== $node + static fn (\DOM\Node $sibling): bool => is_element($sibling) && $sibling !== $node )); return $siblings; diff --git a/src/Xml/Dom/Locator/Node/children.php b/src/Xml/Dom/Locator/Node/children.php index 88cb9b66..d0d3430a 100644 --- a/src/Xml/Dom/Locator/Node/children.php +++ b/src/Xml/Dom/Locator/Node/children.php @@ -4,13 +4,13 @@ namespace VeeWee\Xml\Dom\Locator\Node; -use DOMNode; +use \DOM\Node; use VeeWee\Xml\Dom\Collection\NodeList; /** - * @return NodeList + * @return NodeList<\DOM\Node> */ -function children(DOMNode $node): NodeList +function children(\DOM\Node $node): NodeList { return NodeList::fromDOMNodeList($node->childNodes); } diff --git a/src/Xml/Dom/Locator/Node/detect_document.php b/src/Xml/Dom/Locator/Node/detect_document.php index fdf005bc..65112509 100644 --- a/src/Xml/Dom/Locator/Node/detect_document.php +++ b/src/Xml/Dom/Locator/Node/detect_document.php @@ -4,8 +4,8 @@ namespace VeeWee\Xml\Dom\Locator\Node; -use DOMDocument; -use DOMNode; +use \DOM\XMLDocument; +use \DOM\Node; use InvalidArgumentException; use Webmozart\Assert\Assert; use function VeeWee\Xml\Dom\Predicate\is_document; @@ -14,10 +14,10 @@ * @throws InvalidArgumentException * @psalm-suppress RedundantCondition - node->ownerDocument can also be null... */ -function detect_document(DOMNode $node): DOMDocument +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 DOMNode.'); + Assert::notNull($document, 'Expected to find an ownerDocument on provided \DOM\Node.'); return $document; } diff --git a/src/Xml/Dom/Locator/Node/value.php b/src/Xml/Dom/Locator/Node/value.php index 6cc981bf..dc51ad80 100644 --- a/src/Xml/Dom/Locator/Node/value.php +++ b/src/Xml/Dom/Locator/Node/value.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Dom\Locator\Node; -use DOMNode; +use \DOM\Node; use Psl\Type\Exception\CoercionException; use Psl\Type\TypeInterface; @@ -17,7 +17,7 @@ * * @throws CoercionException */ -function value(DOMNode $node, TypeInterface $type) +function value(\DOM\Node $node, TypeInterface $type) { return $type->coerce($node->nodeValue); } diff --git a/src/Xml/Dom/Locator/Xmlns/linked_namespaces.php b/src/Xml/Dom/Locator/Xmlns/linked_namespaces.php index a5fdb794..8b7ef713 100644 --- a/src/Xml/Dom/Locator/Xmlns/linked_namespaces.php +++ b/src/Xml/Dom/Locator/Xmlns/linked_namespaces.php @@ -4,22 +4,22 @@ namespace VeeWee\Xml\Dom\Locator\Xmlns; -use DOMNameSpaceNode; -use DOMNode; +use \DOM\NameSpaceNode; +use \DOM\Node; use InvalidArgumentException; use VeeWee\Xml\Dom\Collection\NodeList; use VeeWee\Xml\Dom\Xpath; use VeeWee\Xml\Exception\RuntimeException; /** - * @return NodeList + * @return NodeList<\DOM\NameSpaceNode> * * @throws RuntimeException * @throws InvalidArgumentException */ -function linked_namespaces(DOMNode $node): NodeList +function linked_namespaces(\DOM\Node $node): NodeList { $xpath = Xpath::fromUnsafeNode($node); - return $xpath->query('./namespace::*', $node)->expectAllOfType(DOMNameSpaceNode::class); + return $xpath->query('./namespace::*', $node)->expectAllOfType(\DOM\NameSpaceNode::class); } diff --git a/src/Xml/Dom/Locator/Xmlns/recursive_linked_namespaces.php b/src/Xml/Dom/Locator/Xmlns/recursive_linked_namespaces.php index 509ce240..2f3c766b 100644 --- a/src/Xml/Dom/Locator/Xmlns/recursive_linked_namespaces.php +++ b/src/Xml/Dom/Locator/Xmlns/recursive_linked_namespaces.php @@ -4,22 +4,22 @@ namespace VeeWee\Xml\Dom\Locator\Xmlns; -use DOMNameSpaceNode; -use DOMNode; +use \DOM\NameSpaceNode; +use \DOM\Node; use InvalidArgumentException; use VeeWee\Xml\Dom\Collection\NodeList; use VeeWee\Xml\Dom\Xpath; use VeeWee\Xml\Exception\RuntimeException; /** - * @return NodeList + * @return NodeList<\DOM\NameSpaceNode> * * @throws RuntimeException * @throws InvalidArgumentException */ -function recursive_linked_namespaces(DOMNode $node): NodeList +function recursive_linked_namespaces(\DOM\Node $node): NodeList { $xpath = Xpath::fromUnsafeNode($node); - return $xpath->query('.//namespace::*', $node)->expectAllOfType(DOMNameSpaceNode::class); + return $xpath->query('.//namespace::*', $node)->expectAllOfType(\DOM\NameSpaceNode::class); } diff --git a/src/Xml/Dom/Locator/Xsd/locate_all_xsd_schemas.php b/src/Xml/Dom/Locator/Xsd/locate_all_xsd_schemas.php index 8e41820a..e632e625 100644 --- a/src/Xml/Dom/Locator/Xsd/locate_all_xsd_schemas.php +++ b/src/Xml/Dom/Locator/Xsd/locate_all_xsd_schemas.php @@ -4,14 +4,14 @@ namespace VeeWee\Xml\Dom\Locator\Xsd; -use DOMDocument; +use \DOM\XMLDocument; use Psl\Regex\Exception\RuntimeException; use VeeWee\Xml\Xsd\Schema\SchemaCollection; /** * @throws RuntimeException */ -function locate_all_xsd_schemas(DOMDocument $document): SchemaCollection +function locate_all_xsd_schemas(\DOM\XMLDocument $document): SchemaCollection { return new SchemaCollection( ...iterator_to_array(locate_namespaced_xsd_schemas($document)), diff --git a/src/Xml/Dom/Locator/Xsd/locate_namespaced_xsd_schemas.php b/src/Xml/Dom/Locator/Xsd/locate_namespaced_xsd_schemas.php index 1eb4b095..47d45e4f 100644 --- a/src/Xml/Dom/Locator/Xsd/locate_namespaced_xsd_schemas.php +++ b/src/Xml/Dom/Locator/Xsd/locate_namespaced_xsd_schemas.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Dom\Locator\Xsd; -use DOMDocument; +use \DOM\XMLDocument; use Psl\Regex\Exception\RuntimeException; use VeeWee\Xml\Xmlns\Xmlns; use VeeWee\Xml\Xsd\Schema\Schema; @@ -14,7 +14,7 @@ /** * @throws RuntimeException */ -function locate_namespaced_xsd_schemas(DOMDocument $document): SchemaCollection +function locate_namespaced_xsd_schemas(\DOM\XMLDocument $document): SchemaCollection { $schemaNs = Xmlns::xsi()->value(); $attributes = $document->documentElement->attributes; diff --git a/src/Xml/Dom/Locator/Xsd/locate_no_namespaced_xsd_schemas.php b/src/Xml/Dom/Locator/Xsd/locate_no_namespaced_xsd_schemas.php index e7d0ab0e..2a9600f0 100644 --- a/src/Xml/Dom/Locator/Xsd/locate_no_namespaced_xsd_schemas.php +++ b/src/Xml/Dom/Locator/Xsd/locate_no_namespaced_xsd_schemas.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Dom\Locator\Xsd; -use DOMDocument; +use \DOM\XMLDocument; use Psl\Regex\Exception\RuntimeException; use VeeWee\Xml\Xmlns\Xmlns; use VeeWee\Xml\Xsd\Schema\Schema; @@ -15,7 +15,7 @@ /** * @throws RuntimeException */ -function locate_no_namespaced_xsd_schemas(DOMDocument $document): SchemaCollection +function locate_no_namespaced_xsd_schemas(\DOM\XMLDocument $document): SchemaCollection { $schemaNs = Xmlns::xsi()->value(); $attributes = $document->documentElement->attributes; diff --git a/src/Xml/Dom/Locator/document_element.php b/src/Xml/Dom/Locator/document_element.php index 4df07f81..821b9976 100644 --- a/src/Xml/Dom/Locator/document_element.php +++ b/src/Xml/Dom/Locator/document_element.php @@ -5,13 +5,13 @@ namespace VeeWee\Xml\Dom\Locator; use Closure; -use DOMDocument; -use DOMElement; +use \DOM\XMLDocument; +use \DOM\Element; /** - * @return Closure(DOMDocument): DOMElement + * @return Closure(\DOM\XMLDocument): \DOM\Element */ function document_element(): Closure { - return static fn (DOMDocument $document): DOMElement => $document->documentElement; + return static fn (\DOM\XMLDocument $document): \DOM\Element => $document->documentElement; } diff --git a/src/Xml/Dom/Locator/elements_with_namespaced_tagname.php b/src/Xml/Dom/Locator/elements_with_namespaced_tagname.php index c996e815..951f9a7b 100644 --- a/src/Xml/Dom/Locator/elements_with_namespaced_tagname.php +++ b/src/Xml/Dom/Locator/elements_with_namespaced_tagname.php @@ -5,20 +5,20 @@ namespace VeeWee\Xml\Dom\Locator; use Closure; -use DOMDocument; -use DOMElement; +use \DOM\XMLDocument; +use \DOM\Element; use VeeWee\Xml\Dom\Collection\NodeList; use function VeeWee\Xml\Dom\Locator\Element\locate_by_namespaced_tag_name; /** - * @return Closure(DOMDocument): NodeList + * @return Closure(\DOM\XMLDocument): NodeList<\DOM\Element> */ function elements_with_namespaced_tagname(string $namespace, string $localTagName): Closure { return /** - * @return NodeList + * @return NodeList<\DOM\Element> */ - static fn (DOMDocument $document): NodeList + static fn (\DOM\XMLDocument $document): NodeList => locate_by_namespaced_tag_name($document->documentElement, $namespace, $localTagName); } diff --git a/src/Xml/Dom/Locator/elements_with_tagname.php b/src/Xml/Dom/Locator/elements_with_tagname.php index f16bab3e..c2773fbb 100644 --- a/src/Xml/Dom/Locator/elements_with_tagname.php +++ b/src/Xml/Dom/Locator/elements_with_tagname.php @@ -5,20 +5,20 @@ namespace VeeWee\Xml\Dom\Locator; use Closure; -use DOMDocument; -use DOMElement; +use \DOM\XMLDocument; +use \DOM\Element; use VeeWee\Xml\Dom\Collection\NodeList; use function VeeWee\Xml\Dom\Locator\Element\locate_by_tag_name; /** - * @return Closure(DOMDocument): NodeList + * @return Closure(\DOM\XMLDocument): NodeList<\DOM\Element> */ function elements_with_tagname(string $tagName): Closure { return /** - * @return NodeList + * @return NodeList<\DOM\Element> */ - static fn (DOMDocument $document): NodeList + static fn (\DOM\XMLDocument $document): NodeList => locate_by_tag_name($document->documentElement, $tagName); } diff --git a/src/Xml/Dom/Locator/root_namespace.php b/src/Xml/Dom/Locator/root_namespace.php index 63b8ccf2..d182f0ad 100644 --- a/src/Xml/Dom/Locator/root_namespace.php +++ b/src/Xml/Dom/Locator/root_namespace.php @@ -5,12 +5,12 @@ namespace VeeWee\Xml\Dom\Locator; use Closure; -use DOMDocument; +use \DOM\XMLDocument; /** - * @return Closure(DOMDocument): ?string + * @return Closure(\DOM\XMLDocument): ?string */ function root_namespace_uri(): Closure { - return static fn (DOMDocument $document): ?string => $document->documentElement->namespaceURI; + return static fn (\DOM\XMLDocument $document): ?string => $document->documentElement->namespaceURI; } diff --git a/src/Xml/Dom/Manipulator/Attribute/rename.php b/src/Xml/Dom/Manipulator/Attribute/rename.php index 5cc2eb76..9fa2cc11 100644 --- a/src/Xml/Dom/Manipulator/Attribute/rename.php +++ b/src/Xml/Dom/Manipulator/Attribute/rename.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Dom\Manipulator\Attribute; -use DOMAttr; +use \DOM\Attr; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\Dom\Builder\attribute; use function VeeWee\Xml\Dom\Builder\namespaced_attribute; @@ -15,7 +15,7 @@ /** * @throws RuntimeException */ -function rename(DOMAttr $target, string $newQName, ?string $newNamespaceURI = null): DOMAttr +function rename(\DOM\Attr $target, string $newQName, ?string $newNamespaceURI = null): \DOM\Attr { $element = parent_element($target); $namespace = $newNamespaceURI ?? $target->namespaceURI; diff --git a/src/Xml/Dom/Manipulator/Document/optimize_namespaces.php b/src/Xml/Dom/Manipulator/Document/optimize_namespaces.php index 1dcbe873..4710e3fb 100644 --- a/src/Xml/Dom/Manipulator/Document/optimize_namespaces.php +++ b/src/Xml/Dom/Manipulator/Document/optimize_namespaces.php @@ -4,8 +4,8 @@ namespace VeeWee\Xml\Dom\Manipulator\Document; -use DOMDocument; -use DOMNameSpaceNode; +use \DOM\XMLDocument; +use \DOM\NameSpaceNode; use VeeWee\Xml\Exception\RuntimeException; use VeeWee\Xml\Xmlns\Xmlns; use function Psl\Dict\unique; @@ -17,16 +17,16 @@ /** * @throws RuntimeException */ -function optimize_namespaces(DOMDocument $document, string $prefix = 'ns'): void +function optimize_namespaces(\DOM\XMLDocument $document, string $prefix = 'ns'): void { $namespaceURIs = recursive_linked_namespaces($document) - ->filter(static fn (DOMNameSpaceNode $node): bool => $node->namespaceURI !== Xmlns::xml()->value()) + ->filter(static fn (\DOM\NameSpaceNode $node): bool => $node->namespaceURI !== Xmlns::xml()->value()) ->reduce( /** * @param list $grouped * @return list */ - static fn (array $grouped, DOMNameSpaceNode $node): array + static fn (array $grouped, \DOM\NameSpaceNode $node): array => values(unique([...$grouped, $node->namespaceURI])), [] ); diff --git a/src/Xml/Dom/Manipulator/Element/copy_named_xmlns_attributes.php b/src/Xml/Dom/Manipulator/Element/copy_named_xmlns_attributes.php index 0b251a1d..43921231 100644 --- a/src/Xml/Dom/Manipulator/Element/copy_named_xmlns_attributes.php +++ b/src/Xml/Dom/Manipulator/Element/copy_named_xmlns_attributes.php @@ -4,8 +4,8 @@ namespace VeeWee\Xml\Dom\Manipulator\Element; -use DOMElement; -use DOMNameSpaceNode; +use \DOM\Element; +use \DOM\NameSpaceNode; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\Dom\Builder\xmlns_attribute; use function VeeWee\Xml\Dom\Locator\Xmlns\linked_namespaces; @@ -13,9 +13,9 @@ /** * @throws RuntimeException */ -function copy_named_xmlns_attributes(DOMElement $target, DOMElement $source): void +function copy_named_xmlns_attributes(\DOM\Element $target, \DOM\Element $source): void { - linked_namespaces($source)->forEach(static function (DOMNameSpaceNode $xmlns) use ($target) { + linked_namespaces($source)->forEach(static function (\DOM\NameSpaceNode $xmlns) use ($target) { if ($xmlns->prefix && !$target->hasAttribute($xmlns->nodeName)) { xmlns_attribute($xmlns->prefix, $xmlns->namespaceURI)($target); } diff --git a/src/Xml/Dom/Manipulator/Element/rename.php b/src/Xml/Dom/Manipulator/Element/rename.php index cab0076f..ae6e8aa1 100644 --- a/src/Xml/Dom/Manipulator/Element/rename.php +++ b/src/Xml/Dom/Manipulator/Element/rename.php @@ -4,9 +4,9 @@ namespace VeeWee\Xml\Dom\Manipulator\Element; -use DOMAttr; -use DOMElement; -use DOMNameSpaceNode; +use \DOM\Attr; +use \DOM\Element; +use \DOM\NameSpaceNode; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\Dom\Builder\element; use function VeeWee\Xml\Dom\Builder\namespaced_element; @@ -21,7 +21,7 @@ /** * @throws RuntimeException */ -function rename(DOMElement $target, string $newQName, ?string $newNamespaceURI = null): DOMElement +function rename(\DOM\Element $target, string $newQName, ?string $newNamespaceURI = null): \DOM\Element { $isRootElement = $target === $target->ownerDocument->documentElement; $parent = $isRootElement ? $target->ownerDocument : parent_element($target); @@ -35,7 +35,7 @@ function rename(DOMElement $target, string $newQName, ?string $newNamespaceURI = append(...children($target))($newElement); xmlns_attributes_list($target)->forEach( - static function (DOMNameSpaceNode $attribute) use ($target, $newElement): void { + static function (\DOM\NameSpaceNode $attribute) use ($target, $newElement): void { if (is_default_xmlns_attribute($attribute) || $target->prefix === $attribute->prefix) { return; } @@ -44,7 +44,7 @@ static function (DOMNameSpaceNode $attribute) use ($target, $newElement): void { ); attributes_list($target)->forEach( - static function (DOMAttr $attribute) use ($newElement): void { + static function (\DOM\Attr $attribute) use ($newElement): void { $newElement->setAttributeNode($attribute); } ); diff --git a/src/Xml/Dom/Manipulator/Node/append_external_node.php b/src/Xml/Dom/Manipulator/Node/append_external_node.php index aa39beb1..87ef41ea 100644 --- a/src/Xml/Dom/Manipulator/Node/append_external_node.php +++ b/src/Xml/Dom/Manipulator/Node/append_external_node.php @@ -4,13 +4,13 @@ namespace VeeWee\Xml\Dom\Manipulator\Node; -use DOMNode; +use \DOM\Node; use VeeWee\Xml\Exception\RuntimeException; /** * @throws RuntimeException */ -function append_external_node(DOMNode $target, DOMNode $source): DOMNode +function append_external_node(\DOM\Node $target, \DOM\Node $source): \DOM\Node { $copy = import_node_deeply($target, $source); $target->appendChild($copy); diff --git a/src/Xml/Dom/Manipulator/Node/import_node_deeply.php b/src/Xml/Dom/Manipulator/Node/import_node_deeply.php index 7f4d2295..e923e145 100644 --- a/src/Xml/Dom/Manipulator/Node/import_node_deeply.php +++ b/src/Xml/Dom/Manipulator/Node/import_node_deeply.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Dom\Manipulator\Node; -use DOMNode; +use \DOM\Node; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\Dom\Locator\Node\detect_document; use function VeeWee\Xml\ErrorHandling\disallow_issues; @@ -13,10 +13,10 @@ /** * @throws RuntimeException */ -function import_node_deeply(DOMNode $target, DOMNode $source): DOMNode +function import_node_deeply(\DOM\Node $target, \DOM\Node $source): \DOM\Node { return disallow_issues( - static function () use ($target, $source): DOMNode { + static function () use ($target, $source): \DOM\Node { $document = detect_document($target); return disallow_libxml_false_returns( diff --git a/src/Xml/Dom/Manipulator/Node/remove.php b/src/Xml/Dom/Manipulator/Node/remove.php index 4844ad1b..f3994113 100644 --- a/src/Xml/Dom/Manipulator/Node/remove.php +++ b/src/Xml/Dom/Manipulator/Node/remove.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Dom\Manipulator\Node; -use DOMNode; +use \DOM\Node; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\Dom\Locator\Element\parent_element; use function VeeWee\Xml\Dom\Predicate\is_attribute; @@ -14,13 +14,13 @@ /** * @throws RuntimeException */ -function remove(DOMNode $target): DOMNode +function remove(\DOM\Node $target): \DOM\Node { return disallow_issues( /** * @throws RuntimeException */ - static function () use ($target): DOMNode { + static function () use ($target): \DOM\Node { $parent = parent_element($target); if (is_attribute($target)) { diff --git a/src/Xml/Dom/Manipulator/Node/remove_namespace.php b/src/Xml/Dom/Manipulator/Node/remove_namespace.php index aec60bf2..169a8d1e 100644 --- a/src/Xml/Dom/Manipulator/Node/remove_namespace.php +++ b/src/Xml/Dom/Manipulator/Node/remove_namespace.php @@ -4,8 +4,8 @@ namespace VeeWee\Xml\Dom\Manipulator\Node; -use DOMElement; -use DOMNameSpaceNode; +use \DOM\Element; +use \DOM\NameSpaceNode; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\ErrorHandling\disallow_issues; use function VeeWee\Xml\ErrorHandling\disallow_libxml_false_returns; @@ -13,13 +13,13 @@ /** * @throws RuntimeException */ -function remove_namespace(DOMNameSpaceNode $target, DOMElement $parent): DOMNameSpaceNode +function remove_namespace(\DOM\NameSpaceNode $target, \DOM\Element $parent): \DOM\NameSpaceNode { return disallow_issues( /** * @throws RuntimeException */ - static function () use ($target, $parent): DOMNameSpaceNode { + static function () use ($target, $parent): \DOM\NameSpaceNode { disallow_libxml_false_returns( $parent->removeAttributeNS($target->namespaceURI, $target->prefix), 'Could not remove xmlns attribute from dom element' diff --git a/src/Xml/Dom/Manipulator/Node/rename.php b/src/Xml/Dom/Manipulator/Node/rename.php index 99c9ad14..12651752 100644 --- a/src/Xml/Dom/Manipulator/Node/rename.php +++ b/src/Xml/Dom/Manipulator/Node/rename.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Dom\Manipulator\Node; -use DOMNode; +use \DOM\Node; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\Dom\Manipulator\Attribute\rename as rename_attribute; use function VeeWee\Xml\Dom\Manipulator\Element\rename as rename_element; @@ -16,7 +16,7 @@ * * @throws RuntimeException */ -function rename(DOMNode $target, string $newQName, ?string $newNamespaceURI = null): DOMNode +function rename(\DOM\Node $target, string $newQName, ?string $newNamespaceURI = null): \DOM\Node { if (is_attribute($target)) { return rename_attribute($target, $newQName, $newNamespaceURI); diff --git a/src/Xml/Dom/Manipulator/Node/replace_by_external_node.php b/src/Xml/Dom/Manipulator/Node/replace_by_external_node.php index 66321bc2..012ebfa0 100644 --- a/src/Xml/Dom/Manipulator/Node/replace_by_external_node.php +++ b/src/Xml/Dom/Manipulator/Node/replace_by_external_node.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Dom\Manipulator\Node; -use DOMNode; +use \DOM\Node; use VeeWee\Xml\Exception\RuntimeException; use Webmozart\Assert\Assert; use function get_class; @@ -14,10 +14,10 @@ /** * @throws RuntimeException */ -function replace_by_external_node(DOMNode $target, DOMNode $source): DOMNode +function replace_by_external_node(\DOM\Node $target, \DOM\Node $source): \DOM\Node { return disallow_issues( - static function () use ($target, $source) : DOMNode { + static function () use ($target, $source) : \DOM\Node { $parentNode = $target->parentNode; Assert::notNull($parentNode, 'Could not replace a node without parent node. ('.get_class($target).')'); $copy = import_node_deeply($target, $source); diff --git a/src/Xml/Dom/Manipulator/Node/replace_by_external_nodes.php b/src/Xml/Dom/Manipulator/Node/replace_by_external_nodes.php index 850cd0e8..e9a92a79 100644 --- a/src/Xml/Dom/Manipulator/Node/replace_by_external_nodes.php +++ b/src/Xml/Dom/Manipulator/Node/replace_by_external_nodes.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Dom\Manipulator\Node; -use DOMNode; +use \DOM\Node; use VeeWee\Xml\Exception\RuntimeException; use Webmozart\Assert\Assert; use function get_class; @@ -13,21 +13,21 @@ /** * @throws RuntimeException - * @param iterable $sources - * @return array + * @param iterable $sources + * @return array */ -function replace_by_external_nodes(DOMNode $target, iterable $sources): array +function replace_by_external_nodes(\DOM\Node $target, iterable $sources): array { return disallow_issues( /** - * @return array + * @return array */ static function () use ($target, $sources) : array { $parentNode = $target->parentNode; Assert::notNull($parentNode, 'Could not replace a node without parent node. ('.get_class($target).')'); $copies = map( $sources, - static fn (DOMNode $source): DOMNode => import_node_deeply($target, $source) + static fn (\DOM\Node $source): \DOM\Node => import_node_deeply($target, $source) ); foreach ($copies as $copy) { diff --git a/src/Xml/Dom/Manipulator/Xmlns/rename.php b/src/Xml/Dom/Manipulator/Xmlns/rename.php index 21f7b9fc..086a455e 100644 --- a/src/Xml/Dom/Manipulator/Xmlns/rename.php +++ b/src/Xml/Dom/Manipulator/Xmlns/rename.php @@ -4,10 +4,10 @@ namespace VeeWee\Xml\Dom\Manipulator\Xmlns; -use DOMDocument; -use DOMElement; -use DOMNameSpaceNode; -use DOMNode; +use \DOM\XMLDocument; +use \DOM\Element; +use \DOM\NameSpaceNode; +use \DOM\Node; use VeeWee\Xml\Dom\Collection\NodeList; use VeeWee\Xml\Dom\Xpath; use VeeWee\Xml\Exception\RuntimeException; @@ -25,7 +25,7 @@ /** * @throws RuntimeException */ -function rename(DOMDocument $document, string $namespaceURI, string $newPrefix): void +function rename(\DOM\XMLDocument $document, string $namespaceURI, string $newPrefix): void { // Check for prefix collisions $existingUri = $document->lookupNamespaceURI($newPrefix); @@ -41,7 +41,7 @@ function rename(DOMDocument $document, string $namespaceURI, string $newPrefix): } $xpath = Xpath::fromUnsafeNode($document); - $predicate = static fn (DOMNode $node): bool + $predicate = static fn (\DOM\Node $node): bool => $node->namespaceURI === $namespaceURI && $node->prefix !== $newPrefix; // Fetch all nodes (attributes and elements) linked to the given namespace and the nodes that declare namespaces. @@ -51,8 +51,8 @@ function rename(DOMDocument $document, string $namespaceURI, string $newPrefix): // otherwise XMLNS namespace will be removed again after dealing with the elements that declare the xmlns. $linkedNodes = $xpath->query( sprintf('//*[namespace-uri()=\'%1$s\' or @*[namespace-uri()=\'%1$s\'] or namespace::*]', $namespaceURI) - )->expectAllOfType(DOMElement::class)->reduce( - static fn (NodeList $list, DOMElement $element): NodeList + )->expectAllOfType(\DOM\Element::class)->reduce( + static fn (NodeList $list, \DOM\Element $element): NodeList => new NodeList( ...[$element], ...$list, @@ -68,9 +68,9 @@ function rename(DOMDocument $document, string $namespaceURI, string $newPrefix): // Go through the linked nodes and remove all matching xmlns attributes // Finally rename the node in order to use the new prefix. $linkedNodes->forEach( - static function (DOMNode $node) use ($namespaceURI, $newPrefix, $predicate, $root): void { + static function (\DOM\Node $node) use ($namespaceURI, $newPrefix, $predicate, $root): void { // Wrapped in a closure so that psalm knows it all... - $newQname = static fn (DOMNode $node): string => $newPrefix.':'.non_empty_string()->assert($node->localName); + $newQname = static fn (\DOM\Node $node): string => $newPrefix.':'.non_empty_string()->assert($node->localName); if (is_attribute($node)) { rename_node($node, $newQname($node), $namespaceURI); @@ -86,7 +86,7 @@ static function (DOMNode $node) use ($namespaceURI, $newPrefix, $predicate, $roo // Remove old xmlns declarations: $namespaceNodes = xmlns_attributes_list($node) ->filter( - static fn (DOMNameSpaceNode $xmlns): bool + static fn (\DOM\NameSpaceNode $xmlns): bool => $xmlns->namespaceURI === $namespaceURI && $xmlns->prefix !== $newPrefix ); @@ -95,7 +95,7 @@ static function (DOMNode $node) use ($namespaceURI, $newPrefix, $predicate, $roo // We need to make sure to rename it to the new namespace // Otherwise the namespace will be lost! if ($node === $root && $predicate($node)) { - // The root node renaming can result in a new DOMNode. + // The root node renaming can result in a new \DOM\Node. // Make sure to use this new node to avoid issues with e.g. duplicate namespace declarations. $node = rename_node($node, $newQname($node), $namespaceURI); invariant(is_element($node), 'Expected the root node to be a DOM element'); diff --git a/src/Xml/Dom/Manipulator/append.php b/src/Xml/Dom/Manipulator/append.php index c5bd011f..922af7c3 100644 --- a/src/Xml/Dom/Manipulator/append.php +++ b/src/Xml/Dom/Manipulator/append.php @@ -5,18 +5,18 @@ namespace VeeWee\Xml\Dom\Manipulator; use Closure; -use DOMNode; +use \DOM\Node; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\ErrorHandling\disallow_issues; /** * @no-named-arguments * @throws RuntimeException - * @return Closure(DOMNode): DOMNode + * @return Closure(\DOM\Node): \DOM\Node */ -function append(DOMNode ... $nodes): Closure +function append(\DOM\Node ... $nodes): Closure { - return static fn (DOMNode $target): DOMNode => disallow_issues( + return static fn (\DOM\Node $target): \DOM\Node => disallow_issues( static function () use ($target, $nodes) { foreach ($nodes as $node) { $target->appendChild($node); diff --git a/src/Xml/Dom/Mapper/Mapper.php b/src/Xml/Dom/Mapper/Mapper.php index ca3f1483..3677784a 100644 --- a/src/Xml/Dom/Mapper/Mapper.php +++ b/src/Xml/Dom/Mapper/Mapper.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Dom\Mapper; -use DOMDocument; +use \DOM\XMLDocument; /** * @template R @@ -14,5 +14,5 @@ interface Mapper /** * @return R */ - public function __invoke(DOMDocument $document): mixed; + public function __invoke(\DOM\XMLDocument $document): mixed; } diff --git a/src/Xml/Dom/Mapper/xml_string.php b/src/Xml/Dom/Mapper/xml_string.php index 529ae908..d41a66e9 100644 --- a/src/Xml/Dom/Mapper/xml_string.php +++ b/src/Xml/Dom/Mapper/xml_string.php @@ -5,7 +5,7 @@ namespace VeeWee\Xml\Dom\Mapper; use Closure; -use DOMNode; +use \DOM\Node; use function Psl\Type\non_empty_string; use function VeeWee\Xml\Dom\Locator\Node\detect_document; use function VeeWee\Xml\Dom\Predicate\is_document; @@ -13,11 +13,11 @@ use function VeeWee\Xml\ErrorHandling\disallow_libxml_false_returns; /** - * @return Closure(DOMNode): non-empty-string + * @return Closure(\DOM\Node): non-empty-string */ function xml_string(): Closure { - return static fn (DOMNode $node): string => disallow_issues( + return static fn (\DOM\Node $node): string => disallow_issues( static function () use ($node): string { $document = detect_document($node); $node = is_document($node) ? null : $node; diff --git a/src/Xml/Dom/Mapper/xslt_template.php b/src/Xml/Dom/Mapper/xslt_template.php index 89b510ab..9862e390 100644 --- a/src/Xml/Dom/Mapper/xslt_template.php +++ b/src/Xml/Dom/Mapper/xslt_template.php @@ -5,8 +5,8 @@ namespace VeeWee\Xml\Dom\Mapper; use Closure; -use DOMDocument; -use VeeWee\Xml\Dom\Document; +use DOMDocument as DOMDocument; +use VeeWee\XmlDOMDocument; use VeeWee\Xml\Xslt\Processor; use XSLTProcessor; diff --git a/src/Xml/Dom/Predicate/is_attribute.php b/src/Xml/Dom/Predicate/is_attribute.php index ca189336..8eaf5d33 100644 --- a/src/Xml/Dom/Predicate/is_attribute.php +++ b/src/Xml/Dom/Predicate/is_attribute.php @@ -4,13 +4,13 @@ namespace VeeWee\Xml\Dom\Predicate; -use DOMAttr; -use DOMNode; +use \DOM\Attr; +use \DOM\Node; /** - * @psalm-assert-if-true DOMAttr $node + * @psalm-assert-if-true \DOM\Attr $node */ -function is_attribute(DOMNode $node): bool +function is_attribute(\DOM\Node $node): bool { - return $node instanceof DOMAttr; + return $node instanceof \DOM\Attr; } diff --git a/src/Xml/Dom/Predicate/is_cdata.php b/src/Xml/Dom/Predicate/is_cdata.php index ee4884dd..60b7ac29 100644 --- a/src/Xml/Dom/Predicate/is_cdata.php +++ b/src/Xml/Dom/Predicate/is_cdata.php @@ -4,13 +4,13 @@ namespace VeeWee\Xml\Dom\Predicate; -use DOMCdataSection; -use DOMNode; +use \DOM\CdataSection; +use \DOM\Node; /** - * @psalm-assert-if-true DOMCdataSection $node + * @psalm-assert-if-true \DOM\CdataSection $node */ -function is_cdata(DOMNode $node): bool +function is_cdata(\DOM\Node $node): bool { - return $node instanceof DOMCdataSection; + return $node instanceof \DOM\CdataSection; } diff --git a/src/Xml/Dom/Predicate/is_default_xmlns_attribute.php b/src/Xml/Dom/Predicate/is_default_xmlns_attribute.php index 836ebd60..7aac7fe9 100644 --- a/src/Xml/Dom/Predicate/is_default_xmlns_attribute.php +++ b/src/Xml/Dom/Predicate/is_default_xmlns_attribute.php @@ -4,10 +4,10 @@ namespace VeeWee\Xml\Dom\Predicate; -use DOMNameSpaceNode; -use DOMNode; +use \DOM\NameSpaceNode; +use \DOM\Node; -function is_default_xmlns_attribute(DOMNode|DOMNameSpaceNode $node): bool +function is_default_xmlns_attribute(\DOM\Node|\DOM\NameSpaceNode $node): bool { return is_xmlns_attribute($node) && $node->prefix === ''; } diff --git a/src/Xml/Dom/Predicate/is_document.php b/src/Xml/Dom/Predicate/is_document.php index f7ccd7f7..42eb9919 100644 --- a/src/Xml/Dom/Predicate/is_document.php +++ b/src/Xml/Dom/Predicate/is_document.php @@ -4,13 +4,13 @@ namespace VeeWee\Xml\Dom\Predicate; -use DOMDocument; -use DOMNode; +use \DOM\XMLDocument; +use \DOM\Node; /** - * @psalm-assert-if-true DOMDocument $node + * @psalm-assert-if-true \DOM\XMLDocument $node */ -function is_document(DOMNode $node): bool +function is_document(\DOM\Node $node): bool { - return $node instanceof DOMDocument; + return $node instanceof \DOM\XMLDocument; } diff --git a/src/Xml/Dom/Predicate/is_document_element.php b/src/Xml/Dom/Predicate/is_document_element.php index b1b363b8..1b5b22cf 100644 --- a/src/Xml/Dom/Predicate/is_document_element.php +++ b/src/Xml/Dom/Predicate/is_document_element.php @@ -4,11 +4,11 @@ namespace VeeWee\Xml\Dom\Predicate; -use DOMNameSpaceNode; -use DOMNode; +use \DOM\NameSpaceNode; +use \DOM\Node; use function VeeWee\Xml\Dom\Locator\Node\detect_document; -function is_document_element(DOMNode|DOMNameSpaceNode $node): bool +function is_document_element(\DOM\Node|\DOM\NameSpaceNode $node): bool { return is_element($node) && detect_document($node)->documentElement === $node; } diff --git a/src/Xml/Dom/Predicate/is_element.php b/src/Xml/Dom/Predicate/is_element.php index a68aacc2..e0c6af07 100644 --- a/src/Xml/Dom/Predicate/is_element.php +++ b/src/Xml/Dom/Predicate/is_element.php @@ -4,13 +4,13 @@ namespace VeeWee\Xml\Dom\Predicate; -use DOMElement; -use DOMNode; +use \DOM\Element; +use \DOM\Node; /** - * @psalm-assert-if-true DOMElement $node + * @psalm-assert-if-true \DOM\Element $node */ -function is_element(DOMNode $node): bool +function is_element(\DOM\Node $node): bool { - return $node instanceof DOMElement; + return $node instanceof \DOM\Element; } diff --git a/src/Xml/Dom/Predicate/is_non_empty_text.php b/src/Xml/Dom/Predicate/is_non_empty_text.php index 0609d7bf..8dd327ad 100644 --- a/src/Xml/Dom/Predicate/is_non_empty_text.php +++ b/src/Xml/Dom/Predicate/is_non_empty_text.php @@ -4,9 +4,9 @@ namespace VeeWee\Xml\Dom\Predicate; -use DOMNode; +use \DOM\Node; -function is_non_empty_text(DOMNode $node): bool +function is_non_empty_text(\DOM\Node $node): bool { return is_text($node) && trim($node->nodeValue ?? '') !== ''; } diff --git a/src/Xml/Dom/Predicate/is_text.php b/src/Xml/Dom/Predicate/is_text.php index a1b5c0b1..865d9f87 100644 --- a/src/Xml/Dom/Predicate/is_text.php +++ b/src/Xml/Dom/Predicate/is_text.php @@ -4,13 +4,13 @@ namespace VeeWee\Xml\Dom\Predicate; -use DOMNode; -use DOMText; +use \DOM\Node; +use \DOM\Text; /** - * @psalm-assert-if-true DOMText $node + * @psalm-assert-if-true \DOM\Text $node */ -function is_text(DOMNode $node): bool +function is_text(\DOM\Node $node): bool { - return $node instanceof DOMText; + return $node instanceof \DOM\Text; } diff --git a/src/Xml/Dom/Predicate/is_whitespace.php b/src/Xml/Dom/Predicate/is_whitespace.php index 2f35b2ff..69fa6b76 100644 --- a/src/Xml/Dom/Predicate/is_whitespace.php +++ b/src/Xml/Dom/Predicate/is_whitespace.php @@ -4,9 +4,9 @@ namespace VeeWee\Xml\Dom\Predicate; -use DOMNode; +use \DOM\Node; -function is_whitespace(DOMNode $node): bool +function is_whitespace(\DOM\Node $node): bool { return is_text($node) && trim($node->nodeValue ?? '') === ''; } diff --git a/src/Xml/Dom/Predicate/is_xmlns_attribute.php b/src/Xml/Dom/Predicate/is_xmlns_attribute.php index 5be81b85..422ad07f 100644 --- a/src/Xml/Dom/Predicate/is_xmlns_attribute.php +++ b/src/Xml/Dom/Predicate/is_xmlns_attribute.php @@ -4,13 +4,13 @@ namespace VeeWee\Xml\Dom\Predicate; -use DOMNameSpaceNode; -use DOMNode; +use \DOM\NameSpaceNode; +use \DOM\Node; /** - * @psalm-assert-if-true DOMNameSpaceNode $node + * @psalm-assert-if-true \DOM\NameSpaceNode $node */ -function is_xmlns_attribute(DOMNode|DOMNameSpaceNode $node): bool +function is_xmlns_attribute(\DOM\Node|\DOM\NameSpaceNode $node): bool { - return $node instanceof DOMNameSpaceNode; + return $node instanceof \DOM\NameSpaceNode; } diff --git a/src/Xml/Dom/Traverser/Action.php b/src/Xml/Dom/Traverser/Action.php index 98fd39fb..198e01de 100644 --- a/src/Xml/Dom/Traverser/Action.php +++ b/src/Xml/Dom/Traverser/Action.php @@ -4,9 +4,9 @@ namespace VeeWee\Xml\Dom\Traverser; -use DOMNode; +use \DOM\Node; interface Action { - public function __invoke(DOMNode $currentNode): void; + public function __invoke(\DOM\Node $currentNode): void; } diff --git a/src/Xml/Dom/Traverser/Action/Noop.php b/src/Xml/Dom/Traverser/Action/Noop.php index 2443ddb9..c31b0b25 100644 --- a/src/Xml/Dom/Traverser/Action/Noop.php +++ b/src/Xml/Dom/Traverser/Action/Noop.php @@ -4,12 +4,12 @@ namespace VeeWee\Xml\Dom\Traverser\Action; -use DOMNode; +use \DOM\Node; use VeeWee\Xml\Dom\Traverser\Action; final class Noop implements Action { - public function __invoke(DOMNode $currentNode): void + public function __invoke(\DOM\Node $currentNode): void { } } diff --git a/src/Xml/Dom/Traverser/Action/RemoveNode.php b/src/Xml/Dom/Traverser/Action/RemoveNode.php index d7b0d5e1..11d0c919 100644 --- a/src/Xml/Dom/Traverser/Action/RemoveNode.php +++ b/src/Xml/Dom/Traverser/Action/RemoveNode.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Dom\Traverser\Action; -use DOMNode; +use \DOM\Node; use VeeWee\Xml\Dom\Traverser\Action; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\Dom\Manipulator\Node\remove; @@ -14,7 +14,7 @@ final class RemoveNode implements Action /** * @throws RuntimeException */ - public function __invoke(DOMNode $currentNode): void + public function __invoke(\DOM\Node $currentNode): void { remove($currentNode); } diff --git a/src/Xml/Dom/Traverser/Action/RenameNode.php b/src/Xml/Dom/Traverser/Action/RenameNode.php index 0484c1cf..919685da 100644 --- a/src/Xml/Dom/Traverser/Action/RenameNode.php +++ b/src/Xml/Dom/Traverser/Action/RenameNode.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Dom\Traverser\Action; -use DOMNode; +use \DOM\Node; use VeeWee\Xml\Dom\Traverser\Action; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\Dom\Manipulator\Node\rename; @@ -19,7 +19,7 @@ public function __construct( /** * @throws RuntimeException */ - public function __invoke(DOMNode $currentNode): void + public function __invoke(\DOM\Node $currentNode): void { rename($currentNode, $this->newQName); } diff --git a/src/Xml/Dom/Traverser/Action/ReplaceNode.php b/src/Xml/Dom/Traverser/Action/ReplaceNode.php index fd8eed7a..a78dbded 100644 --- a/src/Xml/Dom/Traverser/Action/ReplaceNode.php +++ b/src/Xml/Dom/Traverser/Action/ReplaceNode.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Dom\Traverser\Action; -use DOMNode; +use \DOM\Node; use VeeWee\Xml\Dom\Traverser\Action; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\Dom\Manipulator\Node\replace_by_external_node; @@ -12,14 +12,14 @@ final class ReplaceNode implements Action { public function __construct( - private DOMNode $newNode + private \DOM\Node $newNode ) { } /** * @throws RuntimeException */ - public function __invoke(DOMNode $currentNode): void + public function __invoke(\DOM\Node $currentNode): void { replace_by_external_node($currentNode, $this->newNode); } diff --git a/src/Xml/Dom/Traverser/Traverser.php b/src/Xml/Dom/Traverser/Traverser.php index 46a8a2a3..bd34f453 100644 --- a/src/Xml/Dom/Traverser/Traverser.php +++ b/src/Xml/Dom/Traverser/Traverser.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Dom\Traverser; -use DOMNode; +use \DOM\Node; use function VeeWee\Xml\Dom\Locator\Attribute\attributes_list; use function VeeWee\Xml\Dom\Locator\Node\children; @@ -23,7 +23,7 @@ public function __construct(Visitor ... $visitors) $this->visitors = $visitors; } - public function traverse(DOMNode $node): DOMNode + public function traverse(\DOM\Node $node): \DOM\Node { $this->enterNode($node); @@ -40,14 +40,14 @@ public function traverse(DOMNode $node): DOMNode return $node; } - private function enterNode(DOMNode $node): void + private function enterNode(\DOM\Node $node): void { foreach ($this->visitors as $visitor) { $visitor->onNodeEnter($node)($node); } } - private function leaveNode(DOMNode $node): void + private function leaveNode(\DOM\Node $node): void { foreach ($this->visitors as $visitor) { $visitor->onNodeLeave($node)($node); diff --git a/src/Xml/Dom/Traverser/Visitor.php b/src/Xml/Dom/Traverser/Visitor.php index 02eb42e9..bd87e500 100644 --- a/src/Xml/Dom/Traverser/Visitor.php +++ b/src/Xml/Dom/Traverser/Visitor.php @@ -4,10 +4,10 @@ namespace VeeWee\Xml\Dom\Traverser; -use DOMNode; +use \DOM\Node; interface Visitor { - public function onNodeEnter(DOMNode $node): Action; - public function onNodeLeave(DOMNode $node): Action; + public function onNodeEnter(\DOM\Node $node): Action; + public function onNodeLeave(\DOM\Node $node): Action; } diff --git a/src/Xml/Dom/Traverser/Visitor/AbstractVisitor.php b/src/Xml/Dom/Traverser/Visitor/AbstractVisitor.php index a43488cd..cd15f089 100644 --- a/src/Xml/Dom/Traverser/Visitor/AbstractVisitor.php +++ b/src/Xml/Dom/Traverser/Visitor/AbstractVisitor.php @@ -4,18 +4,18 @@ namespace VeeWee\Xml\Dom\Traverser\Visitor; -use DOMNode; +use \DOM\Node; use VeeWee\Xml\Dom\Traverser\Action; use VeeWee\Xml\Dom\Traverser\Visitor; abstract class AbstractVisitor implements Visitor { - public function onNodeEnter(DOMNode $node): Action + public function onNodeEnter(\DOM\Node $node): Action { return new Action\Noop(); } - public function onNodeLeave(DOMNode $node): Action + public function onNodeLeave(\DOM\Node $node): Action { return new Action\Noop(); } diff --git a/src/Xml/Dom/Traverser/Visitor/RemoveNamespaces.php b/src/Xml/Dom/Traverser/Visitor/RemoveNamespaces.php index e9cad276..4551ad07 100644 --- a/src/Xml/Dom/Traverser/Visitor/RemoveNamespaces.php +++ b/src/Xml/Dom/Traverser/Visitor/RemoveNamespaces.php @@ -3,8 +3,8 @@ namespace VeeWee\Xml\Dom\Traverser\Visitor; -use DOMNameSpaceNode; -use DOMNode; +use \DOM\NameSpaceNode; +use \DOM\Node; use VeeWee\Xml\Dom\Traverser\Action; use VeeWee\Xml\Exception\RuntimeException; use function Psl\Iter\contains; @@ -14,12 +14,12 @@ final class RemoveNamespaces extends AbstractVisitor { /** - * @var null | callable(DOMNameSpaceNode): bool + * @var null | callable(\DOM\NameSpaceNode): bool */ private $filter; /** - * @param null | callable(DOMNameSpaceNode): bool $filter + * @param null | callable(\DOM\NameSpaceNode): bool $filter */ public function __construct( ?callable $filter = null @@ -35,14 +35,14 @@ public static function all(): self public static function prefixed(): self { return new self( - static fn (DOMNameSpaceNode $node): bool => $node->prefix !== '' + static fn (\DOM\NameSpaceNode $node): bool => $node->prefix !== '' ); } public static function unprefixed(): self { return new self( - static fn (DOMNameSpaceNode $node): bool => $node->prefix === '' + static fn (\DOM\NameSpaceNode $node): bool => $node->prefix === '' ); } @@ -52,7 +52,7 @@ public static function unprefixed(): self public static function byPrefixNames(array $prefixes): self { return new self( - static fn (DOMNameSpaceNode $node): bool => contains($prefixes, $node->prefix) + static fn (\DOM\NameSpaceNode $node): bool => contains($prefixes, $node->prefix) ); } @@ -62,14 +62,14 @@ public static function byPrefixNames(array $prefixes): self public static function byNamespaceURIs(array $URIs): self { return new self( - static fn (DOMNameSpaceNode $node): bool => contains($URIs, $node->namespaceURI) + static fn (\DOM\NameSpaceNode $node): bool => contains($URIs, $node->namespaceURI) ); } /** * @throws RuntimeException */ - public function onNodeLeave(DOMNode $node): Action + public function onNodeLeave(\DOM\Node $node): Action { if (!is_element($node)) { return new Action\Noop(); diff --git a/src/Xml/Dom/Traverser/Visitor/SortAttributes.php b/src/Xml/Dom/Traverser/Visitor/SortAttributes.php index 15aeb61a..20b02ce3 100644 --- a/src/Xml/Dom/Traverser/Visitor/SortAttributes.php +++ b/src/Xml/Dom/Traverser/Visitor/SortAttributes.php @@ -4,8 +4,8 @@ namespace VeeWee\Xml\Dom\Traverser\Visitor; -use DOMAttr; -use DOMNode; +use \DOM\Attr; +use \DOM\Node; use VeeWee\Xml\Dom\Traverser\Action; use function VeeWee\Xml\Dom\Locator\Attribute\attributes_list; use function VeeWee\Xml\Dom\Manipulator\append; @@ -13,16 +13,16 @@ final class SortAttributes extends AbstractVisitor { - public function onNodeEnter(DOMNode $node): Action + public function onNodeEnter(\DOM\Node $node): Action { if (!is_element($node)) { return new Action\Noop(); } attributes_list($node) - ->sort(static fn (DOMAttr $a, DOMAttr $b): int => $a->nodeName <=> $b->nodeName) + ->sort(static fn (\DOM\Attr $a, \DOM\Attr $b): int => $a->nodeName <=> $b->nodeName) ->forEach( - static function (DOMAttr $attr) use ($node): void { + static function (\DOM\Attr $attr) use ($node): void { append($attr)($node); } ); diff --git a/src/Xml/Dom/Validator/Validator.php b/src/Xml/Dom/Validator/Validator.php index 8f62bfb1..121f376c 100644 --- a/src/Xml/Dom/Validator/Validator.php +++ b/src/Xml/Dom/Validator/Validator.php @@ -4,10 +4,10 @@ namespace VeeWee\Xml\Dom\Validator; -use DOMDocument; +use \DOM\XMLDocument; use VeeWee\Xml\ErrorHandling\Issue\IssueCollection; interface Validator { - public function __invoke(DOMDocument $document): IssueCollection; + public function __invoke(\DOM\XMLDocument $document): IssueCollection; } diff --git a/src/Xml/Dom/Validator/internal_xsd_validator.php b/src/Xml/Dom/Validator/internal_xsd_validator.php index 29fe45df..1dac61f9 100644 --- a/src/Xml/Dom/Validator/internal_xsd_validator.php +++ b/src/Xml/Dom/Validator/internal_xsd_validator.php @@ -5,7 +5,7 @@ namespace VeeWee\Xml\Dom\Validator; use Closure; -use DOMDocument; +use \DOM\XMLDocument; use VeeWee\Xml\ErrorHandling\Issue\IssueCollection; use VeeWee\Xml\Xsd\Schema\Schema; use VeeWee\Xml\Xsd\Schema\SchemaCollection; @@ -14,17 +14,17 @@ /** * @param list $schemaManipulators - * @return Closure(DOMDocument): IssueCollection + * @return Closure(\DOM\XMLDocument): IssueCollection */ function internal_xsd_validator(callable ... $schemaManipulators): Closure { - return static function (DOMDocument $document) use ($schemaManipulators) : IssueCollection { + return static function (\DOM\XMLDocument $document) use ($schemaManipulators) : IssueCollection { $schemas = configure(...$schemaManipulators)(locate_all_xsd_schemas($document)); return validator_chain( ...$schemas->map( /** - * @return Closure(DOMDocument): IssueCollection + * @return Closure(\DOM\XMLDocument): IssueCollection */ static fn (Schema $schema): Closure => xsd_validator($schema->location()) ) diff --git a/src/Xml/Dom/Validator/validator_chain.php b/src/Xml/Dom/Validator/validator_chain.php index 8c26f0b2..dbf3c927 100644 --- a/src/Xml/Dom/Validator/validator_chain.php +++ b/src/Xml/Dom/Validator/validator_chain.php @@ -5,21 +5,21 @@ namespace VeeWee\Xml\Dom\Validator; use Closure; -use DOMDocument; +use \DOM\XMLDocument; use VeeWee\Xml\ErrorHandling\Issue\IssueCollection; use function Psl\Iter\reduce; /** - * @param list $validators - * @return Closure(DOMDocument): IssueCollection + * @param list $validators + * @return Closure(\DOM\XMLDocument): IssueCollection */ function validator_chain(callable ... $validators): Closure { - return static fn (DOMDocument $document): IssueCollection => + return static fn (\DOM\XMLDocument $document): IssueCollection => reduce( $validators, /** - * @param callable(DOMDocument): IssueCollection $validator + * @param callable(\DOM\XMLDocument): IssueCollection $validator */ static fn (IssueCollection $issues, callable $validator): IssueCollection => new IssueCollection( diff --git a/src/Xml/Dom/Validator/xsd_validator.php b/src/Xml/Dom/Validator/xsd_validator.php index 8c06d27f..6d4e97a5 100644 --- a/src/Xml/Dom/Validator/xsd_validator.php +++ b/src/Xml/Dom/Validator/xsd_validator.php @@ -5,16 +5,16 @@ namespace VeeWee\Xml\Dom\Validator; use Closure; -use DOMDocument; +use \DOM\XMLDocument; use VeeWee\Xml\ErrorHandling\Issue\IssueCollection; use function VeeWee\Xml\ErrorHandling\detect_issues; /** - * @return Closure(DOMDocument): IssueCollection + * @return Closure(\DOM\XMLDocument): IssueCollection */ function xsd_validator(string $xsd): Closure { - return static function (DOMDocument $document) use ($xsd): IssueCollection { + return static function (\DOM\XMLDocument $document) use ($xsd): IssueCollection { [$_, $issues] = detect_issues(static fn () => $document->schemaValidate($xsd)); return $issues; diff --git a/src/Xml/Dom/Xpath.php b/src/Xml/Dom/Xpath.php index ff3907a7..ab1baee2 100644 --- a/src/Xml/Dom/Xpath.php +++ b/src/Xml/Dom/Xpath.php @@ -4,8 +4,8 @@ namespace VeeWee\Xml\Dom; -use DOMNode; -use DOMXPath; +use \DOM\Node; +use \DOM\XPath as DOMXPath; use InvalidArgumentException; use Psl\Type\TypeInterface; use VeeWee\Xml\Dom\Collection\NodeList; @@ -38,7 +38,7 @@ public static function fromDocument(Document $document, callable ... $configurat * @throws RuntimeException * @throws InvalidArgumentException */ - public static function fromUnsafeNode(DOMNode $node, callable ... $configurators): self + public static function fromUnsafeNode(\DOM\Node $node, callable ... $configurators): self { return self::fromDocument( Document::fromUnsafeDocument( @@ -50,7 +50,7 @@ public static function fromUnsafeNode(DOMNode $node, callable ... $configurators /** * @template T - * @param callable(DOMXpath): T $locator + * @param callable(DOMXPath): T $locator * * @return T * @throws RuntimeException @@ -62,9 +62,9 @@ public function locate(callable $locator) /** * @throws RuntimeException - * @return NodeList + * @return NodeList<\DOM\Node> */ - public function query(string $expression, DOMNode $contextNode = null): NodeList + public function query(string $expression, \DOM\Node $contextNode = null): NodeList { return $this->locate(query($expression, $contextNode)); } @@ -73,7 +73,7 @@ public function query(string $expression, DOMNode $contextNode = null): NodeList * @throws RuntimeException * @throws InvalidArgumentException */ - public function querySingle(string $expression, DOMNode $contextNode = null): DOMNode + public function querySingle(string $expression, \DOM\Node $contextNode = null): \DOM\Node { return $this->locate(query_single($expression, $contextNode)); } @@ -86,7 +86,7 @@ public function querySingle(string $expression, DOMNode $contextNode = null): DO * @return T * @throws RuntimeException */ - public function evaluate(string $expression, TypeInterface $type, DOMNode $contextNode = null) + public function evaluate(string $expression, TypeInterface $type, \DOM\Node $contextNode = null) { return $this->locate(evaluate($expression, $type, $contextNode)); } diff --git a/src/Xml/Dom/Xpath/Configurator/Configurator.php b/src/Xml/Dom/Xpath/Configurator/Configurator.php index 15f43425..23d3c2f4 100644 --- a/src/Xml/Dom/Xpath/Configurator/Configurator.php +++ b/src/Xml/Dom/Xpath/Configurator/Configurator.php @@ -4,9 +4,9 @@ namespace VeeWee\Xml\Dom\Xpath\Configurator; -use DOMXPath; +use \DOM\XPath; interface Configurator { - public function __invoke(DOMXPath $xpath): DOMXPath; + public function __invoke(\DOM\XPath $xpath): \DOM\XPath; } diff --git a/src/Xml/Dom/Xpath/Configurator/all_functions.php b/src/Xml/Dom/Xpath/Configurator/all_functions.php index 0dbf2a8b..4ab487ef 100644 --- a/src/Xml/Dom/Xpath/Configurator/all_functions.php +++ b/src/Xml/Dom/Xpath/Configurator/all_functions.php @@ -5,14 +5,14 @@ namespace VeeWee\Xml\Dom\Xpath\Configurator; use Closure; -use DOMXPath; +use \DOM\XPath; /** - * @return Closure(DOMXPath): DOMXPath + * @return Closure(\DOM\XPath): \DOM\XPath */ function all_functions(): Closure { - return static function (DOMXPath $xpath): DOMXPath { + return static function (\DOM\XPath $xpath): \DOM\XPath { php_namespace()($xpath); $xpath->registerPhpFunctions(); diff --git a/src/Xml/Dom/Xpath/Configurator/functions.php b/src/Xml/Dom/Xpath/Configurator/functions.php index 3a1e02fd..ad43c69b 100644 --- a/src/Xml/Dom/Xpath/Configurator/functions.php +++ b/src/Xml/Dom/Xpath/Configurator/functions.php @@ -5,16 +5,16 @@ namespace VeeWee\Xml\Dom\Xpath\Configurator; use Closure; -use DOMXPath; +use \DOM\XPath; /** * @param non-empty-list $functions * - * @return Closure(DOMXPath): DOMXPath + * @return Closure(\DOM\XPath): \DOM\XPath */ function functions(array $functions): Closure { - return static function (DOMXPath $xpath) use ($functions) : DOMXPath { + return static function (\DOM\XPath $xpath) use ($functions) : \DOM\XPath { php_namespace()($xpath); $xpath->registerPhpFunctions($functions); diff --git a/src/Xml/Dom/Xpath/Configurator/namespaces.php b/src/Xml/Dom/Xpath/Configurator/namespaces.php index 869169de..e5d9a224 100644 --- a/src/Xml/Dom/Xpath/Configurator/namespaces.php +++ b/src/Xml/Dom/Xpath/Configurator/namespaces.php @@ -5,16 +5,16 @@ namespace VeeWee\Xml\Dom\Xpath\Configurator; use Closure; -use DOMXPath; +use \DOM\XPath; /** * @param array $namespaces * - * @return Closure(DOMXPath): DOMXPath + * @return Closure(\DOM\XPath): \DOM\XPath */ function namespaces(array $namespaces): Closure { - return static function (DOMXPath $xpath) use ($namespaces) : DOMXPath { + return static function (\DOM\XPath $xpath) use ($namespaces) : \DOM\XPath { foreach ($namespaces as $prefix => $namespaceURI) { $xpath->registerNamespace($prefix, $namespaceURI); } diff --git a/src/Xml/Dom/Xpath/Configurator/php_namespace.php b/src/Xml/Dom/Xpath/Configurator/php_namespace.php index 2c46818d..91eedd81 100644 --- a/src/Xml/Dom/Xpath/Configurator/php_namespace.php +++ b/src/Xml/Dom/Xpath/Configurator/php_namespace.php @@ -5,15 +5,15 @@ namespace VeeWee\Xml\Dom\Xpath\Configurator; use Closure; -use DOMXPath; +use \DOM\XPath; use VeeWee\Xml\Xmlns\Xmlns; /** - * @return Closure(DOMXPath): DOMXPath + * @return Closure(\DOM\XPath): \DOM\XPath */ function php_namespace(): Closure { - return static function (DOMXPath $xpath): DOMXPath { + return static function (\DOM\XPath $xpath): \DOM\XPath { namespaces(['php' => Xmlns::phpXpath()->value()])($xpath); return $xpath; diff --git a/src/Xml/Dom/Xpath/Locator/Locator.php b/src/Xml/Dom/Xpath/Locator/Locator.php index b17c9094..c59dacc3 100644 --- a/src/Xml/Dom/Xpath/Locator/Locator.php +++ b/src/Xml/Dom/Xpath/Locator/Locator.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Dom\Xpath\Locator; -use DOMXPath; +use \DOM\XPath; /** * @template T @@ -14,5 +14,5 @@ interface Locator /** * @return T */ - public function __invoke(DOMXPath $xpath): mixed; + public function __invoke(\DOM\XPath $xpath): mixed; } diff --git a/src/Xml/Dom/Xpath/Locator/evaluate.php b/src/Xml/Dom/Xpath/Locator/evaluate.php index 4ba61bef..9f9e6a3a 100644 --- a/src/Xml/Dom/Xpath/Locator/evaluate.php +++ b/src/Xml/Dom/Xpath/Locator/evaluate.php @@ -4,8 +4,8 @@ namespace VeeWee\Xml\Dom\Xpath\Locator; use Closure; -use DOMNode; -use DOMXPath; +use \DOM\Node; +use \DOM\XPath; use Psl\Type\TypeInterface; use function VeeWee\Xml\ErrorHandling\disallow_issues; use function VeeWee\Xml\ErrorHandling\disallow_libxml_false_returns; @@ -15,15 +15,15 @@ * * @param TypeInterface $type * - * @return Closure(DOMXPath): T + * @return Closure(\DOM\XPath): T */ -function evaluate(string $query, TypeInterface $type, DOMNode $node = null): Closure +function evaluate(string $query, TypeInterface $type, \DOM\Node $node = null): Closure { return /** * @return T */ - static function (DOMXPath $xpath) use ($query, $node, $type) { + static function (\DOM\XPath $xpath) use ($query, $node, $type) { $node = $node ?? $xpath->document->documentElement; return disallow_issues( diff --git a/src/Xml/Dom/Xpath/Locator/query.php b/src/Xml/Dom/Xpath/Locator/query.php index 35d1ac20..a60562e7 100644 --- a/src/Xml/Dom/Xpath/Locator/query.php +++ b/src/Xml/Dom/Xpath/Locator/query.php @@ -4,20 +4,20 @@ namespace VeeWee\Xml\Dom\Xpath\Locator; use Closure; -use DOMNode; -use DOMNodeList; -use DOMXPath; +use \DOM\Node; +use \DOM\NodeList as DOMNodeList; +use \DOM\XPath; use VeeWee\Xml\Dom\Collection\NodeList; use function VeeWee\Xml\Dom\Assert\assert_dom_node_list; use function VeeWee\Xml\ErrorHandling\disallow_issues; use function VeeWee\Xml\ErrorHandling\disallow_libxml_false_returns; /** - * @return Closure(DOMXPath): NodeList + * @return Closure(\DOM\XPath): NodeList<\DOM\Node> */ -function query(string $query, DOMNode $node = null): Closure +function query(string $query, \DOM\Node $node = null): Closure { - return static function (DOMXPath $xpath) use ($query, $node): NodeList { + return static function (\DOM\XPath $xpath) use ($query, $node): NodeList { $node = $node ?? $xpath->document->documentElement; $list = disallow_issues( diff --git a/src/Xml/Dom/Xpath/Locator/query_single.php b/src/Xml/Dom/Xpath/Locator/query_single.php index 4e8213b6..649c86ac 100644 --- a/src/Xml/Dom/Xpath/Locator/query_single.php +++ b/src/Xml/Dom/Xpath/Locator/query_single.php @@ -4,9 +4,9 @@ namespace VeeWee\Xml\Dom\Xpath\Locator; use Closure; -use DOMNode; -use DOMNodeList; -use DOMXPath; +use \DOM\Node; +use \DOM\NodeList; +use \DOM\XPath; use InvalidArgumentException; use VeeWee\Xml\Exception\RuntimeException; use Webmozart\Assert\Assert; @@ -16,19 +16,19 @@ use function VeeWee\Xml\ErrorHandling\disallow_libxml_false_returns; /** - * @return Closure(DOMXPath): DOMNode + * @return Closure(\DOM\XPath): \DOM\Node */ -function query_single(string $query, DOMNode $node = null): Closure +function query_single(string $query, \DOM\Node $node = null): Closure { return /** * @throws InvalidArgumentException * @throws RuntimeException */ - static function (DOMXPath $xpath) use ($query, $node): DOMNode { + static function (\DOM\XPath $xpath) use ($query, $node): \DOM\Node { $node = $node ?? $xpath->document->documentElement; $list = disallow_issues( - static fn (): DOMNodeList => assert_dom_node_list( + static fn (): \DOM\NodeList => assert_dom_node_list( disallow_libxml_false_returns( $xpath->query($query, $node), 'Failed querying XPath query: '.$query diff --git a/src/Xml/Encoding/Internal/Decoder/Builder/attribute.php b/src/Xml/Encoding/Internal/Decoder/Builder/attribute.php index 7e87c215..6fa766c5 100644 --- a/src/Xml/Encoding/Internal/Decoder/Builder/attribute.php +++ b/src/Xml/Encoding/Internal/Decoder/Builder/attribute.php @@ -4,12 +4,12 @@ namespace VeeWee\Xml\Encoding\Internal\Decoder\Builder; -use DOMAttr; +use \DOM\Attr; /** * @psalm-internal VeeWee\Xml\Encoding */ -function attribute(DOMAttr $attribute): array +function attribute(\DOM\Attr $attribute): array { return [ name($attribute) => $attribute->nodeValue, diff --git a/src/Xml/Encoding/Internal/Decoder/Builder/attributes.php b/src/Xml/Encoding/Internal/Decoder/Builder/attributes.php index 8dbd55e6..0eaa804d 100644 --- a/src/Xml/Encoding/Internal/Decoder/Builder/attributes.php +++ b/src/Xml/Encoding/Internal/Decoder/Builder/attributes.php @@ -4,8 +4,8 @@ namespace VeeWee\Xml\Encoding\Internal\Decoder\Builder; -use DOMAttr; -use DOMElement; +use \DOM\Attr; +use \DOM\Element; use function Psl\Dict\filter; use function Psl\Dict\merge; use function Psl\Iter\reduce; @@ -13,12 +13,12 @@ /** * @psalm-internal VeeWee\Xml\Encoding */ -function attributes(DOMElement $element): array +function attributes(\DOM\Element $element): array { return filter([ '@attributes' => reduce( $element->attributes, - static fn (array $attributes, DOMAttr $attr): array + static fn (array $attributes, \DOM\Attr $attr): array => merge($attributes, attribute($attr)), [] ) diff --git a/src/Xml/Encoding/Internal/Decoder/Builder/element.php b/src/Xml/Encoding/Internal/Decoder/Builder/element.php index 76f57e0e..d9bf9913 100644 --- a/src/Xml/Encoding/Internal/Decoder/Builder/element.php +++ b/src/Xml/Encoding/Internal/Decoder/Builder/element.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Encoding\Internal\Decoder\Builder; -use DOMElement; +use \DOM\Element; use VeeWee\Xml\Exception\RuntimeException; use function Psl\Dict\filter; use function Psl\Dict\merge; @@ -14,7 +14,7 @@ * @return array * @throws RuntimeException */ -function element(DOMElement $element): array +function element(\DOM\Element $element): array { $name = name($element); $children = grouped_children($element); diff --git a/src/Xml/Encoding/Internal/Decoder/Builder/group_child_elements.php b/src/Xml/Encoding/Internal/Decoder/Builder/group_child_elements.php index 61d55117..e1567f54 100644 --- a/src/Xml/Encoding/Internal/Decoder/Builder/group_child_elements.php +++ b/src/Xml/Encoding/Internal/Decoder/Builder/group_child_elements.php @@ -4,15 +4,15 @@ namespace VeeWee\Xml\Encoding\Internal\Decoder\Builder; -use DOMElement; +use \DOM\Element; use function VeeWee\Xml\Dom\Locator\Element\children; /** - * @psalm-type GroupedElements=array> + * @psalm-type GroupedElements=array> * @psalm-internal VeeWee\Xml\Encoding * @return GroupedElements */ -function group_child_elements(DOMElement $element): array +function group_child_elements(\DOM\Element $element): array { /** @var GroupedElements $grouped */ $grouped = []; diff --git a/src/Xml/Encoding/Internal/Decoder/Builder/grouped_children.php b/src/Xml/Encoding/Internal/Decoder/Builder/grouped_children.php index b885ee78..03c2be2d 100644 --- a/src/Xml/Encoding/Internal/Decoder/Builder/grouped_children.php +++ b/src/Xml/Encoding/Internal/Decoder/Builder/grouped_children.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Encoding\Internal\Decoder\Builder; -use DOMElement; +use \DOM\Element; use function Psl\Dict\map; use function Psl\Dict\merge; use function Psl\Iter\reduce_with_keys; @@ -13,21 +13,21 @@ * @psalm-internal VeeWee\Xml\Encoding * */ -function grouped_children(DOMElement $element): array +function grouped_children(\DOM\Element $element): array { return reduce_with_keys( group_child_elements($element), /** * @param array $children - * @param DOMElement|list $child + * @param \DOM\Element|list<\DOM\Element> $child * @return array */ - static fn (array $children, string $name, DOMElement|array $child): array + static fn (array $children, string $name, \DOM\Element|array $child): array => merge( $children, [ $name => is_array($child) - ? [...map($child, static fn (DOMElement $child): array|string + ? [...map($child, static fn (\DOM\Element $child): array|string => unwrap_element(element($child)))] : unwrap_element(element($child)) ] diff --git a/src/Xml/Encoding/Internal/Decoder/Builder/name.php b/src/Xml/Encoding/Internal/Decoder/Builder/name.php index bc8154ee..9c13b1bc 100644 --- a/src/Xml/Encoding/Internal/Decoder/Builder/name.php +++ b/src/Xml/Encoding/Internal/Decoder/Builder/name.php @@ -4,12 +4,12 @@ namespace VeeWee\Xml\Encoding\Internal\Decoder\Builder; -use DOMNode; +use \DOM\Node; /** * @psalm-internal VeeWee\Xml\Encoding */ -function name(DOMNode $node): string +function name(\DOM\Node $node): string { return $node->nodeName; } diff --git a/src/Xml/Encoding/Internal/Decoder/Builder/namespaces.php b/src/Xml/Encoding/Internal/Decoder/Builder/namespaces.php index deca6820..54dd1c86 100644 --- a/src/Xml/Encoding/Internal/Decoder/Builder/namespaces.php +++ b/src/Xml/Encoding/Internal/Decoder/Builder/namespaces.php @@ -4,8 +4,8 @@ namespace VeeWee\Xml\Encoding\Internal\Decoder\Builder; -use DOMElement; -use DOMNameSpaceNode; +use \DOM\Element; +use \DOM\NameSpaceNode; use VeeWee\Xml\Exception\RuntimeException; use function Psl\Dict\filter; use function Psl\Dict\merge; @@ -16,11 +16,11 @@ * @psalm-suppress RedundantCast * @throws RuntimeException */ -function namespaces(DOMElement $element): array +function namespaces(\DOM\Element $element): array { return filter([ '@namespaces' => xmlns_attributes_list($element)->reduce( - static fn (array $namespaces, DOMNameSpaceNode $node) + static fn (array $namespaces, \DOM\NameSpaceNode $node) => $node->namespaceURI ? merge($namespaces, [(string) $node->prefix => $node->namespaceURI]) : $namespaces, diff --git a/src/Xml/Encoding/Internal/Encoder/Builder/children.php b/src/Xml/Encoding/Internal/Encoder/Builder/children.php index 56cb864a..9664b066 100644 --- a/src/Xml/Encoding/Internal/Encoder/Builder/children.php +++ b/src/Xml/Encoding/Internal/Encoder/Builder/children.php @@ -5,7 +5,7 @@ namespace VeeWee\Xml\Encoding\Internal\Encoder\Builder; use Closure; -use DOMElement; +use \DOM\Element; use function Psl\Dict\map; use function VeeWee\Xml\Dom\Builder\children as buildChildren; use function VeeWee\Xml\Dom\Builder\element as elementBuilder; @@ -16,7 +16,7 @@ * * @psalm-suppress LessSpecificReturnStatement, MoreSpecificReturnType * - * @return Closure(DOMElement): DOMElement + * @return Closure(\DOM\Element): \DOM\Element */ function children(string $name, array $children): Closure { @@ -24,7 +24,7 @@ function children(string $name, array $children): Closure ...map( $children, /** - * @return Closure(DOMElement): DOMElement + * @return Closure(\DOM\Element): \DOM\Element */ static fn (array|string $data): Closure => is_array($data) ? element($name, $data) diff --git a/src/Xml/Encoding/Internal/Encoder/Builder/element.php b/src/Xml/Encoding/Internal/Encoder/Builder/element.php index e7c62776..f09da838 100644 --- a/src/Xml/Encoding/Internal/Encoder/Builder/element.php +++ b/src/Xml/Encoding/Internal/Encoder/Builder/element.php @@ -5,7 +5,7 @@ namespace VeeWee\Xml\Encoding\Internal\Encoder\Builder; use Closure; -use DOMElement; +use \DOM\Element; use Psl\Exception\InvariantViolationException; use Psl\Type\Exception\AssertException; use function Psl\Dict\filter_keys; @@ -28,7 +28,7 @@ * @psalm-internal VeeWee\Xml\Encoding * @psalm-suppress LessSpecificReturnStatement, MoreSpecificReturnType * - * @return Closure(DOMElement): DOMElement + * @return Closure(\DOM\Element): \DOM\Element * * @throws AssertException * @throws InvariantViolationException @@ -49,7 +49,7 @@ function element(string $name, array $data): Closure $currentNamespace = $namespaces[''] ?? null; $namedNamespaces = filter_keys($namespaces ?? []); - /** @var list $children */ + /** @var list $children */ $children = filter_nulls([ $attributes !== null ? attributes($attributes) : null, $namedNamespaces ? xmlns_attributes($namedNamespaces) : null, @@ -59,7 +59,7 @@ function element(string $name, array $data): Closure $element, /** * @param string|array $value - * @return Closure(DOMElement): DOMElement + * @return Closure(\DOM\Element): \DOM\Element */ static fn (string $name, string|array $value): Closure => parent_node($name, $value) diff --git a/src/Xml/Encoding/Internal/Encoder/Builder/parent_node.php b/src/Xml/Encoding/Internal/Encoder/Builder/parent_node.php index 8127a252..d44a568c 100644 --- a/src/Xml/Encoding/Internal/Encoder/Builder/parent_node.php +++ b/src/Xml/Encoding/Internal/Encoder/Builder/parent_node.php @@ -5,8 +5,8 @@ namespace VeeWee\Xml\Encoding\Internal\Encoder\Builder; use Closure; -use DOMElement; -use DOMNode; +use \DOM\Element; +use \DOM\Node; use Psl\Exception\InvariantViolationException; use Psl\Type\Exception\AssertException; use function VeeWee\Xml\Dom\Builder\children as buildChildren; @@ -17,7 +17,7 @@ * @psalm-internal VeeWee\Xml\Encoding * @psalm-suppress LessSpecificReturnStatement, MoreSpecificReturnType * - * @return Closure(DOMNode): DOMElement + * @return Closure(\DOM\Node): \DOM\Element * * @throws AssertException * @throws InvariantViolationException diff --git a/src/Xml/Encoding/Internal/Encoder/Builder/root.php b/src/Xml/Encoding/Internal/Encoder/Builder/root.php index aaed37f9..14fd9961 100644 --- a/src/Xml/Encoding/Internal/Encoder/Builder/root.php +++ b/src/Xml/Encoding/Internal/Encoder/Builder/root.php @@ -5,8 +5,8 @@ namespace VeeWee\Xml\Encoding\Internal\Encoder\Builder; use Closure; -use DOMDocument; -use DOMNode; +use \DOM\XMLDocument; +use \DOM\Node; use Psl\Exception\InvariantViolationException; use VeeWee\Xml\Encoding\Exception\EncodingException; use function Psl\Dict\map_with_key; @@ -14,7 +14,7 @@ /** * @psalm-internal VeeWee\Xml\Encoding - * @return Closure(DOMDocument): list + * @return Closure(\DOM\XMLDocument): list<\DOM\Node> * * @throws EncodingException * @throws InvariantViolationException diff --git a/src/Xml/Encoding/document_encode.php b/src/Xml/Encoding/document_encode.php index 2d114aae..ca633f92 100644 --- a/src/Xml/Encoding/document_encode.php +++ b/src/Xml/Encoding/document_encode.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Encoding; -use DOMDocument; +use \DOM\XMLDocument as DOMDocument; use VeeWee\Xml\Dom\Document; use VeeWee\Xml\Encoding\Exception\EncodingException; use function VeeWee\Xml\Encoding\Internal\Encoder\Builder\normalize_data; diff --git a/src/Xml/Encoding/element_decode.php b/src/Xml/Encoding/element_decode.php index 490f7688..f9052583 100644 --- a/src/Xml/Encoding/element_decode.php +++ b/src/Xml/Encoding/element_decode.php @@ -4,8 +4,8 @@ namespace VeeWee\Xml\Encoding; -use DOMDocument; -use DOMElement; +use \DOM\XMLDocument as DOMDocument; +use \DOM\Element; use VeeWee\Xml\Dom\Document; use VeeWee\Xml\Encoding\Exception\EncodingException; use function VeeWee\Xml\Dom\Locator\document_element; @@ -17,7 +17,7 @@ * * @throws EncodingException */ -function element_decode(DOMElement $element, callable ... $configurators): array +function element_decode(\DOM\Element $element, callable ... $configurators): array { return wrap_exception( static function () use ($element, $configurators): array { diff --git a/src/Xml/Encoding/element_encode.php b/src/Xml/Encoding/element_encode.php index 8a6dea7c..072a2895 100644 --- a/src/Xml/Encoding/element_encode.php +++ b/src/Xml/Encoding/element_encode.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Encoding; -use DOMDocument; +use \DOM\XMLDocument as DOMDocument; use VeeWee\Xml\Encoding\Exception\EncodingException; use function VeeWee\Xml\Dom\Locator\document_element; use function VeeWee\Xml\Dom\Mapper\xml_string; diff --git a/src/Xml/Encoding/typed.php b/src/Xml/Encoding/typed.php index a07e8590..aee61996 100644 --- a/src/Xml/Encoding/typed.php +++ b/src/Xml/Encoding/typed.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Encoding; -use DOMDocument; +use \DOM\XMLDocument; use Psl\Type\Exception\CoercionException; use Psl\Type\TypeInterface; use VeeWee\Xml\Encoding\Exception\EncodingException; @@ -14,7 +14,7 @@ * * @psalm-param non-empty-string $xml * @psalm-param TypeInterface $type - * @param list $configurators + * @param list $configurators * * @return T * diff --git a/src/Xml/Encoding/xml_decode.php b/src/Xml/Encoding/xml_decode.php index 7a3a6c9e..a3d67025 100644 --- a/src/Xml/Encoding/xml_decode.php +++ b/src/Xml/Encoding/xml_decode.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Encoding; -use DOMDocument; +use \DOM\XMLDocument as DOMDocument; use VeeWee\Xml\Dom\Document; use VeeWee\Xml\Encoding\Exception\EncodingException; use function VeeWee\Xml\Dom\Locator\document_element; diff --git a/src/Xml/Encoding/xml_encode.php b/src/Xml/Encoding/xml_encode.php index a1da5a92..2da3896a 100644 --- a/src/Xml/Encoding/xml_encode.php +++ b/src/Xml/Encoding/xml_encode.php @@ -4,7 +4,7 @@ namespace VeeWee\Xml\Encoding; -use DOMDocument; +use \DOM\XMLDocument as DOMDocument; use VeeWee\Xml\Encoding\Exception\EncodingException; use function VeeWee\Xml\Encoding\Internal\wrap_exception; diff --git a/src/Xml/Reader/MatchingNode.php b/src/Xml/Reader/MatchingNode.php index 49b5a9cc..5c32bc6f 100644 --- a/src/Xml/Reader/MatchingNode.php +++ b/src/Xml/Reader/MatchingNode.php @@ -3,7 +3,7 @@ namespace VeeWee\Xml\Reader; -use DOMDocument; +use \DOM\XMLDocument as DOMDocument; use VeeWee\Xml\Dom\Document; use VeeWee\Xml\Encoding\Exception\EncodingException; use VeeWee\Xml\Exception\RuntimeException; diff --git a/tests/Xml/Dom/Assert/AssertCDataTest.php b/tests/Xml/Dom/Assert/AssertCDataTest.php index 283e1c00..a0739e5f 100644 --- a/tests/Xml/Dom/Assert/AssertCDataTest.php +++ b/tests/Xml/Dom/Assert/AssertCDataTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Assert; -use DOMNode; +use \DOM\Node; use PHPUnit\Framework\TestCase; use Psl\Type\Exception\AssertException; use VeeWee\Xml\Dom\Document; @@ -16,7 +16,7 @@ final class AssertCDataTest extends TestCase * * @dataProvider provideTestCases */ - public function test_it_knows_cdata(?DOMNode $node, bool $expected): void + public function test_it_knows_cdata(?\DOM\Node $node, bool $expected): void { if (!$expected) { $this->expectException(AssertException::class); diff --git a/tests/Xml/Dom/Assert/AssertDocumentTest.php b/tests/Xml/Dom/Assert/AssertDocumentTest.php index 39c2482d..0bd1fd82 100644 --- a/tests/Xml/Dom/Assert/AssertDocumentTest.php +++ b/tests/Xml/Dom/Assert/AssertDocumentTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Assert; -use DOMNode; +use \DOM\Node; use PHPUnit\Framework\TestCase; use Psl\Type\Exception\AssertException; use VeeWee\Xml\Dom\Document; @@ -16,7 +16,7 @@ final class AssertDocumentTest extends TestCase * * @dataProvider provideTestCases */ - public function test_it_knows_documents(?DOMNode $node, bool $expected): void + public function test_it_knows_documents(?\DOM\Node $node, bool $expected): void { if (!$expected) { $this->expectException(AssertException::class); diff --git a/tests/Xml/Dom/Assert/AssertElementTest.php b/tests/Xml/Dom/Assert/AssertElementTest.php index f98100ff..4bd31e40 100644 --- a/tests/Xml/Dom/Assert/AssertElementTest.php +++ b/tests/Xml/Dom/Assert/AssertElementTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Assert; -use DOMNode; +use \DOM\Node; use PHPUnit\Framework\TestCase; use Psl\Type\Exception\AssertException; use VeeWee\Xml\Dom\Document; @@ -16,7 +16,7 @@ final class AssertElementTest extends TestCase * * @dataProvider provideTestCases */ - public function test_it_knows_elements(?DOMNode $node, bool $expected): void + public function test_it_knows_elements(?\DOM\Node $node, bool $expected): void { if (!$expected) { $this->expectException(AssertException::class); diff --git a/tests/Xml/Dom/Builder/AttributesTest.php b/tests/Xml/Dom/Builder/AttributesTest.php index 111a2ead..3701fd28 100644 --- a/tests/Xml/Dom/Builder/AttributesTest.php +++ b/tests/Xml/Dom/Builder/AttributesTest.php @@ -4,8 +4,9 @@ namespace VeeWee\Tests\Xml\Dom\Builder; -use DOMDocument; +use \DOM\XMLDocument; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Builder\attribute; use function VeeWee\Xml\Dom\Builder\attributes; use function VeeWee\Xml\Dom\Builder\element; @@ -16,7 +17,7 @@ final class AttributesTest extends TestCase { public function test_it_can_build_an_element_with_attributes(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $ns = 'https://namespace.com'; $node = element( diff --git a/tests/Xml/Dom/Builder/CdataTest.php b/tests/Xml/Dom/Builder/CdataTest.php index e2915d61..9b4ad5a5 100644 --- a/tests/Xml/Dom/Builder/CdataTest.php +++ b/tests/Xml/Dom/Builder/CdataTest.php @@ -4,9 +4,10 @@ namespace VeeWee\Tests\Xml\Dom\Builder; -use DOMCdataSection; -use DOMDocument; +use \DOM\CdataSection; +use \DOM\XMLDocument; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use function Psl\Fun\identity; use function VeeWee\Xml\Dom\Builder\cdata; use function VeeWee\Xml\Dom\Mapper\xml_string; @@ -15,20 +16,20 @@ final class CdataTest extends TestCase { public function test_it_can_build_cdata(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $node = cdata($data = 'hello')($doc); - static::assertInstanceOf(DOMCdataSection::class, $node); + static::assertInstanceOf(\DOM\CdataSection::class, $node); static::assertSame($data, $node->textContent); static::assertSame(xml_string()($node), ''); } public function test_it_can_build_cdata_with_configurators(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $node = cdata($data = 'hello', identity())($doc); - static::assertInstanceOf(DOMCdataSection::class, $node); + static::assertInstanceOf(\DOM\CdataSection::class, $node); static::assertSame($data, $node->textContent); } } diff --git a/tests/Xml/Dom/Builder/ChildrenTest.php b/tests/Xml/Dom/Builder/ChildrenTest.php index 6f24d5ca..c97ebc02 100644 --- a/tests/Xml/Dom/Builder/ChildrenTest.php +++ b/tests/Xml/Dom/Builder/ChildrenTest.php @@ -4,8 +4,9 @@ namespace VeeWee\Tests\Xml\Dom\Builder; -use DOMDocument; +use \DOM\XMLDocument; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Builder\cdata; use function VeeWee\Xml\Dom\Builder\children; use function VeeWee\Xml\Dom\Builder\element; @@ -15,7 +16,7 @@ final class ChildrenTest extends TestCase { public function test_it_can_build_document_children(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $actual = children( element('world1'), element('world2') @@ -31,7 +32,7 @@ public function test_it_can_build_document_children(): void public function test_it_can_build_an_element_with_children(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $node = element( 'hello', children( @@ -52,7 +53,7 @@ public function test_it_can_build_an_element_with_children(): void public function test_it_can_add_cdata(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $node = element( 'hello', children( diff --git a/tests/Xml/Dom/Builder/ElementTest.php b/tests/Xml/Dom/Builder/ElementTest.php index 5f7c4f9a..c1629a3e 100644 --- a/tests/Xml/Dom/Builder/ElementTest.php +++ b/tests/Xml/Dom/Builder/ElementTest.php @@ -4,8 +4,9 @@ namespace VeeWee\Tests\Xml\Dom\Builder; -use DOMDocument; +use \DOM\XMLDocument; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use function Psl\Fun\identity; use function VeeWee\Xml\Dom\Builder\element; use function VeeWee\Xml\Dom\Builder\value; @@ -14,7 +15,7 @@ final class ElementTest extends TestCase { public function test_it_can_build_an_element(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $node = element('hello')($doc); static::assertSame('hello', $node->nodeName); @@ -24,7 +25,7 @@ public function test_it_can_build_an_element(): void public function test_it_can_build_an_element_with_configurators(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $node = element('hello', identity())($doc); static::assertSame('hello', $node->nodeName); @@ -34,7 +35,7 @@ public function test_it_can_build_an_element_with_configurators(): void public function test_it_can_build_an_element_with_value(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $node = element('hello', value('world'))($doc); static::assertSame('hello', $node->nodeName); diff --git a/tests/Xml/Dom/Builder/EscapedValueTest.php b/tests/Xml/Dom/Builder/EscapedValueTest.php index 03051623..96957b50 100644 --- a/tests/Xml/Dom/Builder/EscapedValueTest.php +++ b/tests/Xml/Dom/Builder/EscapedValueTest.php @@ -4,8 +4,9 @@ namespace VeeWee\Tests\Xml\Dom\Builder; -use DOMDocument; +use \DOM\XMLDocument; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Builder\element; use function VeeWee\Xml\Dom\Builder\escaped_value; use function VeeWee\Xml\Dom\Mapper\xml_string; @@ -14,7 +15,7 @@ final class EscapedValueTest extends TestCase { public function test_it_can_build_an_element_with_html_value(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $node = element('hello', escaped_value(''))($doc); static::assertSame('', $node->nodeValue); diff --git a/tests/Xml/Dom/Builder/NamespacedAttributeTest.php b/tests/Xml/Dom/Builder/NamespacedAttributeTest.php index 695d6dfe..6b788834 100644 --- a/tests/Xml/Dom/Builder/NamespacedAttributeTest.php +++ b/tests/Xml/Dom/Builder/NamespacedAttributeTest.php @@ -4,9 +4,10 @@ namespace VeeWee\Tests\Xml\Dom\Builder; -use DOMDocument; +use \DOM\XMLDocument; use InvalidArgumentException; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Builder\element; use function VeeWee\Xml\Dom\Builder\namespaced_attribute; @@ -14,7 +15,7 @@ final class NamespacedAttributeTest extends TestCase { public function test_it_throws_exception_if_the_attribute_name_is_not_qualified(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $ns = 'https://namespace.com'; $this->expectException(InvalidArgumentException::class); diff --git a/tests/Xml/Dom/Builder/NamespacedElementTest.php b/tests/Xml/Dom/Builder/NamespacedElementTest.php index 3e6432e6..29be4bf2 100644 --- a/tests/Xml/Dom/Builder/NamespacedElementTest.php +++ b/tests/Xml/Dom/Builder/NamespacedElementTest.php @@ -4,9 +4,10 @@ namespace VeeWee\Tests\Xml\Dom\Builder; -use DOMDocument; -use DOMElement; +use \DOM\XMLDocument; +use \DOM\Element; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use function Psl\Fun\identity; use function VeeWee\Xml\Dom\Builder\namespaced_element; use function VeeWee\Xml\Dom\Builder\value; @@ -15,9 +16,9 @@ final class NamespacedElementTest extends TestCase { public function test_it_can_build_an_element_with_alias(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $ns = 'https://namespace.com'; - /** @var DOMElement $node */ + /** @var \DOM\Element $node */ $node = namespaced_element($ns, 'ns:hello')($doc); static::assertSame($ns, $node->namespaceURI); @@ -27,12 +28,12 @@ public function test_it_can_build_an_element_with_alias(): void static::assertSame($doc, $node->ownerDocument); } - + public function test_it_can_build_an_element_without_alias(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $ns = 'https://namespace.com'; - /** @var DOMElement $node */ + /** @var \DOM\Element $node */ $node = namespaced_element($ns, 'hello')($doc); static::assertSame($ns, $node->namespaceURI); @@ -41,10 +42,10 @@ public function test_it_can_build_an_element_without_alias(): void static::assertSame($doc, $node->ownerDocument); } - + public function test_it_can_build_an_element_with_configurators(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $ns = 'https://namespace.com'; $node = namespaced_element($ns, 'ns:hello', identity())($doc); @@ -54,10 +55,10 @@ public function test_it_can_build_an_element_with_configurators(): void static::assertSame($doc, $node->ownerDocument); } - + public function test_it_can_build_an_element_with_value(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $ns = 'https://namespace.com'; $node = namespaced_element($ns, 'ns:hello', value('world'))($doc); diff --git a/tests/Xml/Dom/Builder/NodesTest.php b/tests/Xml/Dom/Builder/NodesTest.php index 810cf40c..98bc22f3 100644 --- a/tests/Xml/Dom/Builder/NodesTest.php +++ b/tests/Xml/Dom/Builder/NodesTest.php @@ -4,8 +4,9 @@ namespace VeeWee\Tests\Xml\Dom\Builder; -use DOMDocument; +use \DOM\XMLDocument; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Builder\element; use function VeeWee\Xml\Dom\Builder\nodes; @@ -13,11 +14,11 @@ final class NodesTest extends TestCase { public function test_it_can_build_nodes(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $nodes = nodes( element('hello'), element('world'), - static fn (DOMDocument $doc): array => [ + static fn (\DOM\XMLDocument $doc): array => [ element('many1')($doc), element('many2')($doc), ], diff --git a/tests/Xml/Dom/Builder/ValueTest.php b/tests/Xml/Dom/Builder/ValueTest.php index 0590ae56..70f679b5 100644 --- a/tests/Xml/Dom/Builder/ValueTest.php +++ b/tests/Xml/Dom/Builder/ValueTest.php @@ -4,8 +4,9 @@ namespace VeeWee\Tests\Xml\Dom\Builder; -use DOMDocument; +use \DOM\XMLDocument; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Builder\element; use function VeeWee\Xml\Dom\Builder\value; use function VeeWee\Xml\Dom\Mapper\xml_string; @@ -14,7 +15,7 @@ final class ValueTest extends TestCase { public function test_it_can_build_an_element_with_html_value(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $node = element('hello', value(''))($doc); static::assertSame('', $node->nodeValue); diff --git a/tests/Xml/Dom/Builder/XmlnsAttributesTest.php b/tests/Xml/Dom/Builder/XmlnsAttributesTest.php index 59350f3b..27c90c1e 100644 --- a/tests/Xml/Dom/Builder/XmlnsAttributesTest.php +++ b/tests/Xml/Dom/Builder/XmlnsAttributesTest.php @@ -4,8 +4,9 @@ namespace VeeWee\Tests\Xml\Dom\Builder; -use DOMDocument; +use \DOM\XMLDocument; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Builder\element; use function VeeWee\Xml\Dom\Builder\xmlns_attribute; use function VeeWee\Xml\Dom\Builder\xmlns_attributes; @@ -14,7 +15,7 @@ final class XmlnsAttributesTest extends TestCase { public function test_it_can_build_an_element_with_attributes(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $node = element( 'hello', diff --git a/tests/Xml/Dom/Collection/NodeListTest.php b/tests/Xml/Dom/Collection/NodeListTest.php index 253aca4c..92a6aeb0 100644 --- a/tests/Xml/Dom/Collection/NodeListTest.php +++ b/tests/Xml/Dom/Collection/NodeListTest.php @@ -4,9 +4,9 @@ namespace VeeWee\Tests\Xml\Dom\Collection; -use DOMAttr; -use DOMElement; -use DOMNode; +use \DOM\Attr; +use \DOM\Element; +use \DOM\Node; use InvalidArgumentException; use PHPUnit\Framework\TestCase; use Psl\Collection\MutableVector; @@ -66,20 +66,20 @@ public function test_it_can_be_iterated(): void static::assertCount(4, $items); static::assertIsIterable($items); foreach ($items as $item) { - static::assertInstanceOf(DOMElement::class, $item); + static::assertInstanceOf(\DOM\Element::class, $item); } } public function test_it_can_be_created_typed(): void { $items = NodeList::typed( - DOMElement::class, + \DOM\Element::class, $items = $this->loadProducts() ); static::assertCount(4, $items); foreach ($items as $item) { - static::assertInstanceOf(DOMElement::class, $item); + static::assertInstanceOf(\DOM\Element::class, $item); } } @@ -87,7 +87,7 @@ public function test_it_will_trigger_error_when_created_with_invalid_type(): voi { $this->expectException(InvalidArgumentException::class); NodeList::typed( - DOMElement::class, + \DOM\Element::class, $this->loadProducts()->eq(0)->first()->attributes ); } @@ -120,7 +120,7 @@ public function test_it_can_expect_items() public function test_it_can_map(): void { $items = $this->loadProducts()->map( - static fn (DOMElement $element): string => $element->nodeValue + static fn (\DOM\Element $element): string => $element->nodeValue ); static::assertSame( @@ -138,7 +138,7 @@ public function test_it_can_loop_over_all_items(): void { $x = new MutableVector([]); $this->loadProducts()->forEach( - static function (DOMElement $element) use ($x) : void { + static function (\DOM\Element $element) use ($x) : void { $x->add($element->nodeValue); } ); @@ -158,7 +158,7 @@ public function test_it_can_filter(): void { $all = $this->loadProducts(); $filtered = $all->filter( - static fn (DOMElement $element): bool => (bool) ((int)($element->getAttribute('id'))%2) + static fn (\DOM\Element $element): bool => (bool) ((int)($element->getAttribute('id'))%2) ); static::assertCount(2, $filtered); @@ -170,7 +170,7 @@ public function test_it_can_filter(): void public function test_it_can_reduce(): void { $total = $this->loadPrices()->reduce( - static fn (int $total, DOMElement $element): int => $total + (int) $element->nodeValue, + static fn (int $total, \DOM\Element $element): int => $total + (int) $element->nodeValue, 0 ); @@ -180,9 +180,9 @@ public function test_it_can_reduce(): void public function test_it_can_detect(): void { $list = $this->root()->detect( - static fn (DOMElement $element) => filter( + static fn (\DOM\Element $element) => filter( $element->childNodes, - static fn (DOMNode $current) => is_element($current) + static fn (\DOM\Node $current) => is_element($current) ) ); @@ -261,7 +261,7 @@ public function test_it_can_expect_single_on_a_two_item_list(): void $prices = $this->loadPrices(); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Expected single element, got 2 elements.'); - $prices->filter(static fn (DOMElement $price): bool => (int)$price->textContent >= 2)->expectSingle('Expected single element, got %s elements.'); + $prices->filter(static fn (\DOM\Element $price): bool => (int)$price->textContent >= 2)->expectSingle('Expected single element, got %s elements.'); } public function test_it_can_get_last(): void @@ -316,7 +316,7 @@ public function test_it_can_search_siblings(): void public function test_it_can_validate_types(): void { $prices = $this->loadPrices(); - $result = $prices->expectAllOfType(DOMElement::class); + $result = $prices->expectAllOfType(\DOM\Element::class); static::assertSame([...$prices], [...$result]); } @@ -325,13 +325,13 @@ public function test_it_can_validate_types_and_fail(): void { $this->expectException(InvalidArgumentException::class); $prices = $this->loadPrices(); - $prices->expectAllOfType(DOMAttr::class); + $prices->expectAllOfType(\DOM\Attr::class); } public function test_it_can_sort(): void { $prices = $this->loadPrices(); - $sorted = $prices->sort(static fn (DOMNode $a, DOMNode $b) => $b->nodeValue <=> $a->nodeValue); + $sorted = $prices->sort(static fn (\DOM\Node $a, \DOM\Node $b) => $b->nodeValue <=> $a->nodeValue); static::assertSame( [ diff --git a/tests/Xml/Dom/Configurator/DocumentUriTest.php b/tests/Xml/Dom/Configurator/DocumentUriTest.php index 89f550f4..492134a0 100644 --- a/tests/Xml/Dom/Configurator/DocumentUriTest.php +++ b/tests/Xml/Dom/Configurator/DocumentUriTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Configurator; -use DOMDocument; +use DOM\XMLDocument as DOMDocument; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Configurator\document_uri; @@ -14,8 +14,7 @@ final class DocumentUriTest extends TestCase { public function test_it_can_use_document_uri(): void { - $doc = new DOMDocument(); - $doc->loadXML($xml = ''); + $doc = Document::fromXmlString('')->toUnsafeDocument(); static::assertStringStartsWith(getcwd(), $doc->documentURI); $configurator = document_uri($documentUri = 'myfile.wsdl'); diff --git a/tests/Xml/Dom/Configurator/LoaderTest.php b/tests/Xml/Dom/Configurator/LoaderTest.php index b274c3ba..788cd87e 100644 --- a/tests/Xml/Dom/Configurator/LoaderTest.php +++ b/tests/Xml/Dom/Configurator/LoaderTest.php @@ -4,19 +4,20 @@ namespace VeeWee\Tests\Xml\Dom\Configurator; -use DOMDocument; +use \DOM\XMLDocument; use Exception; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Configurator\loader; final class LoaderTest extends TestCase { public function test_it_can_load_xml(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $xml = ''; - $loader = loader(static function (DOMDocument $doc) use ($xml): void { + $loader = loader(static function (\DOM\XMLDocument $doc) use ($xml): void { $doc->loadXML($xml); }); @@ -25,12 +26,12 @@ public function test_it_can_load_xml(): void static::assertXmlStringEqualsXmlString($xml, $doc->saveXML()); } - + public function test_it_can_mark_xml_loading_as_failed(): void { - $doc = new DOMDocument(); + $doc = Document::empty()->toUnsafeDocument(); $exception = new Exception('Could not load the XML document'); - $loader = loader(static function (DOMDocument $doc) use ($exception): void { + $loader = loader(static function (\DOM\XMLDocument $doc) use ($exception): void { throw $exception; }); diff --git a/tests/Xml/Dom/Configurator/PrettyPrintTest.php b/tests/Xml/Dom/Configurator/PrettyPrintTest.php index cb72849a..79ed80c3 100644 --- a/tests/Xml/Dom/Configurator/PrettyPrintTest.php +++ b/tests/Xml/Dom/Configurator/PrettyPrintTest.php @@ -4,8 +4,9 @@ namespace VeeWee\Tests\Xml\Dom\Configurator; -use DOMDocument; +use \DOM\XMLDocument; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Configurator\pretty_print; use function VeeWee\Xml\Dom\Mapper\xml_string; @@ -15,9 +16,8 @@ public function test_it_can_trim_contents(): void { $configurator = pretty_print(); - $doc = new DOMDocument(); + $doc = Document::fromXmlString($xml = ' ')->toUnsafeDocument(); $result = $configurator($doc); - $doc->loadXML($xml = ' '); $expected = << diff --git a/tests/Xml/Dom/Configurator/TraverseTest.php b/tests/Xml/Dom/Configurator/TraverseTest.php index d9e34526..aff13a62 100644 --- a/tests/Xml/Dom/Configurator/TraverseTest.php +++ b/tests/Xml/Dom/Configurator/TraverseTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Configurator; -use DOMNode; +use \DOM\Node; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; use VeeWee\Xml\Dom\Traverser\Action; @@ -18,7 +18,7 @@ public function test_it_can_traverse(): void { $doc = Document::fromXmlString('world', traverse( new class() extends AbstractVisitor { - public function onNodeLeave(DOMNode $node): Action + public function onNodeLeave(\DOM\Node $node): Action { return is_text($node) ? new Action\RemoveNode() diff --git a/tests/Xml/Dom/Configurator/TrimSpacesTest.php b/tests/Xml/Dom/Configurator/TrimSpacesTest.php index b9718c2a..f12fff13 100644 --- a/tests/Xml/Dom/Configurator/TrimSpacesTest.php +++ b/tests/Xml/Dom/Configurator/TrimSpacesTest.php @@ -4,8 +4,9 @@ namespace VeeWee\Tests\Xml\Dom\Configurator; -use DOMDocument; +use \DOM\XMLDocument; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Configurator\trim_spaces; use function VeeWee\Xml\Dom\Mapper\xml_string; @@ -13,10 +14,9 @@ final class TrimSpacesTest extends TestCase { public function test_it_can_trim_contents(): void { - $doc = new DOMDocument(); + $doc = Document::fromXmlString(' ')->toUnsafeDocument(); $configurator = trim_spaces(); $result = $configurator($doc); - $doc->loadXML($xml = ' '); static::assertSame($doc, $result); static::assertFalse($doc->preserveWhiteSpace); diff --git a/tests/Xml/Dom/Configurator/Utf8Test.php b/tests/Xml/Dom/Configurator/Utf8Test.php index fc903e8b..ac45857a 100644 --- a/tests/Xml/Dom/Configurator/Utf8Test.php +++ b/tests/Xml/Dom/Configurator/Utf8Test.php @@ -4,16 +4,16 @@ namespace VeeWee\Tests\Xml\Dom\Configurator; -use DOMDocument; +use \DOM\XMLDocument; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Configurator\utf8; final class Utf8Test extends TestCase { public function test_it_can_convert_to_utf8(): void { - $doc = new DOMDocument(); - $doc->loadXML($xml = ''); + $doc = Document::fromXmlString($xml = '')->toUnsafeDocument(); $configurator = utf8(); diff --git a/tests/Xml/Dom/Configurator/ValidatorTest.php b/tests/Xml/Dom/Configurator/ValidatorTest.php index ee237a3c..eef307b7 100644 --- a/tests/Xml/Dom/Configurator/ValidatorTest.php +++ b/tests/Xml/Dom/Configurator/ValidatorTest.php @@ -4,9 +4,10 @@ namespace VeeWee\Tests\Xml\Dom\Configurator; -use DOMDocument; +use \DOM\XMLDocument; use PHPUnit\Framework\TestCase; use VeeWee\Tests\Xml\ErrorHandling\Issue\UseIssueTrait; +use VeeWee\Xml\Dom\Document; use VeeWee\Xml\ErrorHandling\Issue\IssueCollection; use VeeWee\Xml\ErrorHandling\Issue\Level; use VeeWee\Xml\Exception\RuntimeException; @@ -16,21 +17,21 @@ final class ValidatorTest extends TestCase { use UseIssueTrait; - + public function test_it_can_configure_xml_with_valid_validation_result(): void { - $doc = new DOMDocument(); - $validator = validator(static fn (DOMDocument $doc): IssueCollection => new IssueCollection()); + $doc = Document::empty()->toUnsafeDocument(); + $validator = validator(static fn (\DOM\XMLDocument $doc): IssueCollection => new IssueCollection()); $result = $validator($doc); static::assertSame($doc, $result); } - + public function test_it_can_configure_xml_with_invalid_validation_result(): void { - $doc = new DOMDocument(); - $validator = validator(fn (DOMDocument $doc): IssueCollection => new IssueCollection( + $doc = Document::empty()->toUnsafeDocument(); + $validator = validator(fn (\DOM\XMLDocument $doc): IssueCollection => new IssueCollection( $this->createIssue(Level::fatal()) )); diff --git a/tests/Xml/Dom/DocumentTest.php b/tests/Xml/Dom/DocumentTest.php index 04f9c9d1..09a4d29b 100644 --- a/tests/Xml/Dom/DocumentTest.php +++ b/tests/Xml/Dom/DocumentTest.php @@ -4,8 +4,8 @@ namespace VeeWee\Tests\Xml\Dom; -use DOMDocument; -use DOMNode; +use \DOM\XMLDocument; +use \DOM\Node; use PHPUnit\Framework\TestCase; use VeeWee\Tests\Xml\Helper\FillFileTrait; use VeeWee\Xml\Dom\Document; @@ -24,7 +24,7 @@ final class DocumentTest extends TestCase public function test_it_can_create_a_document_from_dom(): void { - $document = new DOMDocument(); + $document = XMLDocument::createEmpty(); $doc = Document::fromUnsafeDocument($document, identity()); static::assertSame($document, $doc->toUnsafeDocument()); @@ -33,7 +33,7 @@ public function test_it_can_create_a_document_from_dom(): void public function test_it_can_create_an_empty_document(): void { - $document = new DOMDocument(); + $document = XMLDocument::createEmpty(); $doc = Document::empty(); static::assertEquals($document, $doc->toUnsafeDocument()); @@ -42,7 +42,7 @@ public function test_it_can_create_an_empty_document(): void public function test_it_can_create_a_configured_document(): void { - $document = new DOMDocument(); + $document = XMLDocument::createEmpty(); $doc = Document::configure(identity()); static::assertEquals($document, $doc->toUnsafeDocument()); @@ -67,8 +67,7 @@ public function test_it_can_add_various_configurators(): void public function test_it_can_create_a_document_from_xml_node(): void { - $source = new DOMDocument(); - $source->loadXML($xml = ''); + $source = XMLDocument::createFromString($xml = ''); $doc = Document::fromXmlNode( $source->documentElement, @@ -107,7 +106,7 @@ public function test_it_can_create_a_document_from_xml_string(): void public function test_it_can_map(): void { - $doc = new DOMDocument(); + $doc = XMLDocument::createEmpty(); $wrapper = Document::fromUnsafeDocument($doc); $mapped = $wrapper->map(identity()); @@ -119,7 +118,7 @@ public function test_it_can_traverse(): void $doc = Document::fromXmlString('world'); $result = $doc->traverse( new class() extends AbstractVisitor { - public function onNodeLeave(DOMNode $node): Action + public function onNodeLeave(\DOM\Node $node): Action { return is_text($node) ? new Action\RemoveNode() @@ -167,11 +166,11 @@ public function test_it_can_stringify_parts(): void $expected = ''; static::assertSame( - ''.PHP_EOL.$expected.PHP_EOL, + ''.PHP_EOL.$expected, $full ); static::assertSame($expected, $documentElement); static::assertSame($expected, $node); - static::assertSame(' value="world"', $attr); + static::assertSame('value="world"', $attr); } } diff --git a/tests/Xml/Dom/Loader/XmlFileLoaderTest.php b/tests/Xml/Dom/Loader/XmlFileLoaderTest.php index 7a9fdb85..9f3f68d8 100644 --- a/tests/Xml/Dom/Loader/XmlFileLoaderTest.php +++ b/tests/Xml/Dom/Loader/XmlFileLoaderTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Loader; -use DOMDocument; +use \DOM\XMLDocument; use PHPUnit\Framework\TestCase; use VeeWee\Tests\Xml\Helper\FillFileTrait; use VeeWee\Xml\Exception\RuntimeException; @@ -16,7 +16,7 @@ final class XmlFileLoaderTest extends TestCase public function test_it_can_load_xml_file(): void { - $doc = new DOMDocument(); + $doc = new \DOM\XMLDocument(); $xml = ''; [$file, $handle] = $this->fillFile($xml); $loader = xml_file_loader($file); @@ -29,7 +29,7 @@ public function test_it_can_load_xml_file(): void public function test_it_can_load_with_options(): void { - $doc = new DOMDocument(); + $doc = new \DOM\XMLDocument(); $xml = ''; [$file, $handle] = $this->fillFile($xml); $loader = xml_file_loader($file, LIBXML_NOCDATA); @@ -42,7 +42,7 @@ public function test_it_can_load_with_options(): void public function test_it_cannot_load_invalid_xml_file(): void { - $doc = new DOMDocument(); + $doc = new \DOM\XMLDocument(); $xml = 'fillFile($xml); $loader = xml_file_loader($file); @@ -56,7 +56,7 @@ public function test_it_cannot_load_invalid_xml_file(): void public function test_it_throws_exception_on_invalid_file(): void { - $doc = new DOMDocument(); + $doc = new \DOM\XMLDocument(); $loader = xml_file_loader('invalid-file'); $this->expectException(RuntimeException::class); diff --git a/tests/Xml/Dom/Loader/XmlNodeLoaderTest.php b/tests/Xml/Dom/Loader/XmlNodeLoaderTest.php index 863f5e8e..c0a115e3 100644 --- a/tests/Xml/Dom/Loader/XmlNodeLoaderTest.php +++ b/tests/Xml/Dom/Loader/XmlNodeLoaderTest.php @@ -4,8 +4,9 @@ namespace VeeWee\Tests\Xml\Dom\Loader; -use DOMDocument; +use \DOM\XMLDocument; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\Dom\Loader\xml_node_loader; @@ -13,23 +14,21 @@ final class XmlNodeLoaderTest extends TestCase { public function test_it_can_load_xml_node(): void { - $source = new DOMDocument(); - $source->loadXML($xml = ''); + $source = Document::fromXmlString($xml = '')->toUnsafeDocument(); + $doc = Document::empty()->toUnsafeDocument(); - $doc = new DOMDocument(); $loader = xml_node_loader($source->documentElement); $loader($doc); static::assertXmlStringEqualsXmlString($xml, $doc->saveXML()); } - + public function test_it_can_not_load_invalid_xml_node(): void { - $source = new DOMDocument(); - $source->loadXML($xml = ''); + $source = Document::fromXmlString($xml = '')->toUnsafeDocument(); + $doc = Document::empty()->toUnsafeDocument(); - $doc = new DOMDocument(); $loader = xml_node_loader($source); $this->expectException(RuntimeException::class); diff --git a/tests/Xml/Dom/Loader/XmlStringLoaderTest.php b/tests/Xml/Dom/Loader/XmlStringLoaderTest.php index 31111691..ebed9148 100644 --- a/tests/Xml/Dom/Loader/XmlStringLoaderTest.php +++ b/tests/Xml/Dom/Loader/XmlStringLoaderTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Loader; -use DOMDocument; +use \DOM\XMLDocument; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\Dom\Loader\xml_string_loader; @@ -13,7 +13,7 @@ final class XmlStringLoaderTest extends TestCase { public function test_it_can_load_xml_string(): void { - $doc = new DOMDocument(); + $doc = new \DOM\XMLDocument(); $xml = ''; $loader = xml_string_loader($xml); @@ -23,7 +23,7 @@ public function test_it_can_load_xml_string(): void public function test_it_can_not_load_invalid_xml_string(): void { - $doc = new DOMDocument(); + $doc = new \DOM\XMLDocument(); $xml = 'documentElement); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('Can not find parent element for DOMElement hello'); + $this->expectExceptionMessage('Can not find parent element for \DOM\Element hello'); parent_element($hello); } } diff --git a/tests/Xml/Dom/Locator/Node/DetectDocumentTest.php b/tests/Xml/Dom/Locator/Node/DetectDocumentTest.php index d304228f..4c7e1017 100644 --- a/tests/Xml/Dom/Locator/Node/DetectDocumentTest.php +++ b/tests/Xml/Dom/Locator/Node/DetectDocumentTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Locator\Node; -use DOMElement; +use \DOM\Element; use InvalidArgumentException; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; @@ -24,10 +24,10 @@ public function test_it_can_detect_document(): void public function test_it_throws_exception_on_unlinked_node(): void { - $element = new DOMElement('name'); + $element = new \DOM\Element('name'); $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Expected to find an ownerDocument on provided DOMNode.'); + $this->expectExceptionMessage('Expected to find an ownerDocument on provided \DOM\Node.'); detect_document($element); } diff --git a/tests/Xml/Dom/Locator/Xmlns/LinkedNamespacesTest.php b/tests/Xml/Dom/Locator/Xmlns/LinkedNamespacesTest.php index 29a961c8..60fa8091 100644 --- a/tests/Xml/Dom/Locator/Xmlns/LinkedNamespacesTest.php +++ b/tests/Xml/Dom/Locator/Xmlns/LinkedNamespacesTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Locator\Xmlns; -use DOMNameSpaceNode; +use \DOM\NameSpaceNode; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Collection\NodeList; use VeeWee\Xml\Dom\Document; @@ -26,7 +26,7 @@ public function test_it_can_detect_linked_namespaces(): void $parse = static fn (NodeList $list): array => reduce( [...$list], - static fn (array $map, DOMNameSpaceNode $node) => merge($map, [$node->localName => $node->namespaceURI]), + static fn (array $map, \DOM\NameSpaceNode $node) => merge($map, [$node->localName => $node->namespaceURI]), [] ); diff --git a/tests/Xml/Dom/Locator/Xmlns/RecursiveLinkedNamespacesTest.php b/tests/Xml/Dom/Locator/Xmlns/RecursiveLinkedNamespacesTest.php index 1ab23f6d..35fab90d 100644 --- a/tests/Xml/Dom/Locator/Xmlns/RecursiveLinkedNamespacesTest.php +++ b/tests/Xml/Dom/Locator/Xmlns/RecursiveLinkedNamespacesTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Locator\Xmlns; -use DOMNameSpaceNode; +use \DOM\NameSpaceNode; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Collection\NodeList; use VeeWee\Xml\Dom\Document; @@ -26,7 +26,7 @@ public function test_it_can_detect_recursively_linked_namespaces(): void $parse = static fn (NodeList $list): array => reduce( [...$list], - static fn (array $map, DOMNameSpaceNode $node) => merge($map, [$node->localName => $node->namespaceURI]), + static fn (array $map, \DOM\NameSpaceNode $node) => merge($map, [$node->localName => $node->namespaceURI]), [] ); diff --git a/tests/Xml/Dom/Locator/Xsd/LocateXsdSchemasTest.php b/tests/Xml/Dom/Locator/Xsd/LocateXsdSchemasTest.php index c71df259..a0d6bfdb 100644 --- a/tests/Xml/Dom/Locator/Xsd/LocateXsdSchemasTest.php +++ b/tests/Xml/Dom/Locator/Xsd/LocateXsdSchemasTest.php @@ -4,8 +4,9 @@ namespace VeeWee\Tests\Xml\Dom\Locator\Xsd; -use DOMDocument; +use \DOM\XMLDocument; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use VeeWee\Xml\Xsd\Schema\Schema; use function VeeWee\Xml\Dom\Locator\Xsd\locate_all_xsd_schemas; use function VeeWee\Xml\Dom\Locator\Xsd\locate_namespaced_xsd_schemas; @@ -27,7 +28,7 @@ public function test_it_can_locate_namespaced_xsd_schemas(): void ); } - + public function test_it_can_locate_no_namespaced_xsd_schemas(): void { $document = $this->loadXsdContainer(); @@ -42,7 +43,7 @@ public function test_it_can_locate_no_namespaced_xsd_schemas(): void ); } - + public function test_it_can_locate_all_xsd_schemas(): void { $document = $this->loadXsdContainer(); @@ -59,14 +60,11 @@ public function test_it_can_locate_all_xsd_schemas(): void ); } - private function loadXsdContainer(): DOMDocument + private function loadXsdContainer(): \DOM\XMLDocument { $file = FIXTURE_DIR.'/dom/locator/xsd/xsdcontainer.xml'; static::assertFileExists($file); - $document = new DOMDocument(); - $document->load($file); - - return $document; + return Document::fromXmlFile($file)->toUnsafeDocument(); } } diff --git a/tests/Xml/Dom/Manipulator/Node/AppendExternalNodeTest.php b/tests/Xml/Dom/Manipulator/Node/AppendExternalNodeTest.php index de3f1930..2de46ba6 100644 --- a/tests/Xml/Dom/Manipulator/Node/AppendExternalNodeTest.php +++ b/tests/Xml/Dom/Manipulator/Node/AppendExternalNodeTest.php @@ -4,50 +4,48 @@ namespace VeeWee\Tests\Xml\Dom\Manipulator\Node; -use DOMDocument; -use DOMElement; +use \DOM\XMLDocument; +use \DOM\Element; +use Infected\PhpParser\Comment\Doc; use PHPUnit\Framework\TestCase; use RuntimeException; +use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Manipulator\Node\append_external_node; final class AppendExternalNodeTest extends TestCase { public function test_it_can_import_a_node_into_a_document_root(): void { - $source = new DOMDocument(); - $source->loadXML(''); - $target = new DOMDocument(); + $source = Document::fromXmlString('')->toUnsafeDocument(); + $target = Document::empty()->toUnsafeDocument(); $result = append_external_node($target, $source->documentElement); - static::assertInstanceOf(DOMElement::class, $result); + static::assertInstanceOf(\DOM\Element::class, $result); static::assertSame('hello', $result->nodeName); static::assertXmlStringEqualsXmlString($source->saveXML(), $target->saveXML()); } - + public function test_it_can_not_import_a_document_into_a_document(): void { - $source = new DOMDocument(); - $source->loadXML(''); - $target = new DOMDocument(); + $source = Document::fromXmlString('')->toUnsafeDocument(); + $target = Document::empty()->toUnsafeDocument(); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Cannot import node: Node Type Not Supported'); append_external_node($target, $source); } - + public function test_it_can_recursively_import_a_node_into_another_document_node(): void { - $source = new DOMDocument(); - $source->loadXML('VeeWee'); - $target = new DOMDocument(); - $target->loadXML(''); + $source = Document::fromXmlString('VeeWee')->toUnsafeDocument(); + $target = Document::fromXmlString('')->toUnsafeDocument(); $result = append_external_node($target->documentElement, $source->documentElement->firstChild); - static::assertInstanceOf(DOMElement::class, $result); + static::assertInstanceOf(\DOM\Element::class, $result); static::assertSame('world', $result->nodeName); static::assertXmlStringEqualsXmlString($source->saveXML(), $target->saveXML()); } diff --git a/tests/Xml/Dom/Manipulator/Node/ImportNodeDeeplyTest.php b/tests/Xml/Dom/Manipulator/Node/ImportNodeDeeplyTest.php index fda12f62..000cfde0 100644 --- a/tests/Xml/Dom/Manipulator/Node/ImportNodeDeeplyTest.php +++ b/tests/Xml/Dom/Manipulator/Node/ImportNodeDeeplyTest.php @@ -4,9 +4,10 @@ namespace VeeWee\Tests\Xml\Dom\Manipulator\Node; -use DOMDocument; -use DOMElement; +use \DOM\XMLDocument; +use \DOM\Element; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\Dom\Manipulator\Node\import_node_deeply; @@ -14,52 +15,47 @@ final class ImportNodeDeeplyTest extends TestCase { public function test_it_can_import_a_node(): void { - $source = new DOMDocument(); - $source->loadXML(''); - $target = new DOMDocument(); + $source = Document::fromXmlString('')->toUnsafeDocument(); + $target = Document::empty()->toUnsafeDocument(); $result = import_node_deeply($target, $source->documentElement); - static::assertInstanceOf(DOMElement::class, $result); + static::assertInstanceOf(\DOM\Element::class, $result); static::assertSame('hello', $result->nodeName); } - + public function test_it_can_import_a_node_into_a_nodes_document(): void { - $source = new DOMDocument(); - $source->loadXML(''); - $target = new DOMDocument(); - $target->loadXML(''); + $source = Document::fromXmlString('')->toUnsafeDocument(); + $target = Document::fromXmlString('')->toUnsafeDocument(); $result = import_node_deeply($target->documentElement, $source->documentElement); - static::assertInstanceOf(DOMElement::class, $result); + static::assertInstanceOf(\DOM\Element::class, $result); static::assertSame('hello', $result->nodeName); } - + public function test_it_can_not_import_an_invalid_node(): void { - $source = new DOMDocument(); - $source->loadXML(''); - $target = new DOMDocument(); + $source = Document::fromXmlString('')->toUnsafeDocument(); + $target = Document::empty()->toUnsafeDocument(); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Cannot import node: Node Type Not Supported'); import_node_deeply($target, $source); } - + public function test_it_can_recursively_import_a_node_based_on_a_target_document_node(): void { - $source = new DOMDocument(); - $source->loadXML('VeeWee'); - $target = new DOMDocument(); + $source = Document::fromXmlString('VeeWee')->toUnsafeDocument(); + $target = Document::empty()->toUnsafeDocument(); $result = import_node_deeply($target, $source->documentElement->firstChild); - static::assertInstanceOf(DOMElement::class, $result); + static::assertInstanceOf(\DOM\Element::class, $result); static::assertSame('world', $result->nodeName); static::assertSame('myvalue', $result->attributes->getNamedItem('myattrib')->nodeValue); static::assertSame('name', $result->firstChild->nodeName); diff --git a/tests/Xml/Dom/Manipulator/Node/RemoveTest.php b/tests/Xml/Dom/Manipulator/Node/RemoveTest.php index 314a870b..f6e68d49 100644 --- a/tests/Xml/Dom/Manipulator/Node/RemoveTest.php +++ b/tests/Xml/Dom/Manipulator/Node/RemoveTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Manipulator\Node; -use DOMDocument; +use \DOM\XMLDocument as DOMDocument; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; use VeeWee\Xml\Exception\RuntimeException; diff --git a/tests/Xml/Dom/Manipulator/Node/RenameTest.php b/tests/Xml/Dom/Manipulator/Node/RenameTest.php index 975434cf..310e98c4 100644 --- a/tests/Xml/Dom/Manipulator/Node/RenameTest.php +++ b/tests/Xml/Dom/Manipulator/Node/RenameTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Manipulator\Node; -use DOMDocument; +use \DOM\XMLDocument as DOMDocument; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; use VeeWee\Xml\Exception\RuntimeException; diff --git a/tests/Xml/Dom/Manipulator/Node/ReplaceByExternalNodeTest.php b/tests/Xml/Dom/Manipulator/Node/ReplaceByExternalNodeTest.php index ac237782..39610c76 100644 --- a/tests/Xml/Dom/Manipulator/Node/ReplaceByExternalNodeTest.php +++ b/tests/Xml/Dom/Manipulator/Node/ReplaceByExternalNodeTest.php @@ -4,9 +4,10 @@ namespace VeeWee\Tests\Xml\Dom\Manipulator\Node; -use DOMDocument; -use DOMElement; +use \DOM\XMLDocument; +use \DOM\Element; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\Dom\Manipulator\Node\replace_by_external_node; @@ -14,43 +15,37 @@ final class ReplaceByExternalNodeTest extends TestCase { public function test_it_can_replace_a_node(): void { - $source = new DOMDocument(); - $source->loadXML(''); - $target = new DOMDocument(); - $target->loadXML(''); + $source = Document::fromXmlString('')->toUnsafeDocument(); + $target = Document::fromXmlString('')->toUnsafeDocument(); $result = replace_by_external_node($target->documentElement, $source->documentElement); - static::assertInstanceOf(DOMElement::class, $result); + static::assertInstanceOf(\DOM\Element::class, $result); static::assertSame('hello', $result->nodeName); static::assertXmlStringEqualsXmlString($target->saveXML(), $source->saveXML()); } - + public function test_it_can_not_replace_a_document_into_a_document(): void { - $source = new DOMDocument(); - $source->loadXML(''); - $target = new DOMDocument(); + $source = Document::fromXmlString('')->toUnsafeDocument(); + $target = Document::empty()->toUnsafeDocument(); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('Could not replace a node without parent node. (DOMDocument)'); + $this->expectExceptionMessage('Could not replace a node without parent node. (\DOM\XMLDocument)'); replace_by_external_node($target, $source); } - + public function test_it_can_recursively_replace_a_node_with_another_external_node(): void { - $source = new DOMDocument(); - $source->loadXML('VeeWee'); - $target = new DOMDocument(); - $target->loadXML(''); - $expected = new DOMDocument(); - $expected->loadXML('VeeWee'); + $source = Document::fromXmlString('VeeWee')->toUnsafeDocument(); + $target = Document::fromXmlString('')->toUnsafeDocument(); + $expected = Document::fromXmlString('VeeWee')->toUnsafeDocument(); $result = replace_by_external_node($target->documentElement, $source->documentElement->firstChild); - static::assertInstanceOf(DOMElement::class, $result); + static::assertInstanceOf(\DOM\Element::class, $result); static::assertSame('world', $result->nodeName); static::assertXmlStringEqualsXmlString($expected->saveXML(), $target->saveXML()); } diff --git a/tests/Xml/Dom/Manipulator/Node/ReplaceByExternalNodesTest.php b/tests/Xml/Dom/Manipulator/Node/ReplaceByExternalNodesTest.php index c332e7d2..b5358aba 100644 --- a/tests/Xml/Dom/Manipulator/Node/ReplaceByExternalNodesTest.php +++ b/tests/Xml/Dom/Manipulator/Node/ReplaceByExternalNodesTest.php @@ -4,9 +4,10 @@ namespace VeeWee\Tests\Xml\Dom\Manipulator\Node; -use DOMDocument; -use DOMElement; +use \DOM\XMLDocument; +use \DOM\Element; use PHPUnit\Framework\TestCase; +use VeeWee\Xml\Dom\Document; use VeeWee\Xml\Exception\RuntimeException; use function VeeWee\Xml\Dom\Locator\Element\children; use function VeeWee\Xml\Dom\Manipulator\Node\replace_by_external_nodes; @@ -15,63 +16,55 @@ final class ReplaceByExternalNodesTest extends TestCase { public function test_it_can_replace_a_node(): void { - $source = new DOMDocument(); - $source->loadXML(''); - $target = new DOMDocument(); - $target->loadXML(''); + $source = Document::fromXmlString(''); + $target = Document::fromXmlString(''); - $results = replace_by_external_nodes($target->documentElement, [$source->documentElement]); + $results = replace_by_external_nodes($target->locateDocumentElement(), [$source->locateDocumentElement()]); $result = $results[0]; - static::assertInstanceOf(DOMElement::class, $result); + static::assertInstanceOf(\DOM\Element::class, $result); static::assertSame('hello', $result->nodeName); - static::assertXmlStringEqualsXmlString($target->saveXML(), $source->saveXML()); + static::assertXmlStringEqualsXmlString($target->toXmlString(), $source->toXmlString()); } public function test_it_can_replace_many_nodes(): void { - $source = new DOMDocument(); - $source->loadXML(''); - $target = new DOMDocument(); - $target->loadXML(''); - $items = children($source->documentElement); + $source = Document::fromXmlString(''); + $target = Document::fromXmlString(''); + $items = children($source->locateDocumentElement()); - $results = replace_by_external_nodes($target->documentElement->childNodes->item(0), $items); + $results = replace_by_external_nodes($target->locateDocumentElement()->childNodes->item(0), $items); - static::assertInstanceOf(DOMElement::class, $results[0]); + static::assertInstanceOf(\DOM\Element::class, $results[0]); static::assertSame('world', $results[0]->nodeName); - static::assertInstanceOf(DOMElement::class, $results[1]); + static::assertInstanceOf(\DOM\Element::class, $results[1]); static::assertSame('toon', $results[1]->nodeName); - static::assertXmlStringEqualsXmlString($target->saveXML(), $source->saveXML()); + static::assertXmlStringEqualsXmlString($target->toXmlString(), $source->toXmlString()); } public function test_it_can_not_replace_a_document_into_a_document(): void { - $source = new DOMDocument(); - $source->loadXML(''); - $target = new DOMDocument(); + $source = Document::fromXmlString('')->toUnsafeDocument(); + $target = Document::empty()->toUnsafeDocument(); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('Could not replace a node without parent node. (DOMDocument)'); + $this->expectExceptionMessage('Could not replace a node without parent node. (\DOM\XMLDocument)'); replace_by_external_nodes($target, [$source]); } - + public function test_it_can_recursively_replace_a_node_with_another_external_node(): void { - $source = new DOMDocument(); - $source->loadXML('VeeWee'); - $target = new DOMDocument(); - $target->loadXML(''); - $expected = new DOMDocument(); - $expected->loadXML('VeeWee'); - - $results = replace_by_external_nodes($target->documentElement, [$source->documentElement->firstChild]); + $source = Document::fromXmlString('VeeWee'); + $target = Document::fromXmlString(''); + $expected = Document::fromXmlString('VeeWee'); + + $results = replace_by_external_nodes($target->locateDocumentElement(), [$source->locateDocumentElement()->firstChild]); $result = $results[0]; - static::assertInstanceOf(DOMElement::class, $result); + static::assertInstanceOf(\DOM\Element::class, $result); static::assertSame('world', $result->nodeName); - static::assertXmlStringEqualsXmlString($expected->saveXML(), $target->saveXML()); + static::assertXmlStringEqualsXmlString($expected->toXmlString(), $target->toXmlString()); } } diff --git a/tests/Xml/Dom/Mapper/XmlStringTest.php b/tests/Xml/Dom/Mapper/XmlStringTest.php index 7d66e9c4..8bc865dd 100644 --- a/tests/Xml/Dom/Mapper/XmlStringTest.php +++ b/tests/Xml/Dom/Mapper/XmlStringTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Mapper; -use DOMElement; +use \DOM\Element; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; use VeeWee\Xml\Exception\RuntimeException; @@ -31,7 +31,7 @@ public function test_it_can_map_node_to_xml(): void public function test_it_throws_exception_on_invalid_node(): void { $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('Expected to find an ownerDocument on provided DOMNode'); - xml_string()(new DOMElement('hello')); + $this->expectExceptionMessage('Expected to find an ownerDocument on provided \DOM\Node'); + xml_string()(new \DOM\Element('hello')); } } diff --git a/tests/Xml/Dom/Predicate/IsAttributeTest.php b/tests/Xml/Dom/Predicate/IsAttributeTest.php index 6044f798..a1689be2 100644 --- a/tests/Xml/Dom/Predicate/IsAttributeTest.php +++ b/tests/Xml/Dom/Predicate/IsAttributeTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Predicate; -use DOMNode; +use \DOM\Node; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Predicate\is_attribute; @@ -15,7 +15,7 @@ final class IsAttributeTest extends TestCase * * @dataProvider provideTestCases */ - public function test_it_knows_attributes(DOMNode $node, bool $expected): void + public function test_it_knows_attributes(\DOM\Node $node, bool $expected): void { static::assertSame($expected, is_attribute($node)); } diff --git a/tests/Xml/Dom/Predicate/IsCDataTest.php b/tests/Xml/Dom/Predicate/IsCDataTest.php index 779d8340..b7bfc91b 100644 --- a/tests/Xml/Dom/Predicate/IsCDataTest.php +++ b/tests/Xml/Dom/Predicate/IsCDataTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Predicate; -use DOMNode; +use \DOM\Node; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Predicate\is_cdata; @@ -15,7 +15,7 @@ final class IsCDataTest extends TestCase * * @dataProvider provideTestCases */ - public function test_it_knows_cdata(?DOMNode $node, bool $expected): void + public function test_it_knows_cdata(?\DOM\Node $node, bool $expected): void { $actual = is_cdata($node); static::assertSame($expected, $actual); diff --git a/tests/Xml/Dom/Predicate/IsDefaultXmlnsAttributeTest.php b/tests/Xml/Dom/Predicate/IsDefaultXmlnsAttributeTest.php index caaf1701..86f3e312 100644 --- a/tests/Xml/Dom/Predicate/IsDefaultXmlnsAttributeTest.php +++ b/tests/Xml/Dom/Predicate/IsDefaultXmlnsAttributeTest.php @@ -4,8 +4,8 @@ namespace VeeWee\Tests\Xml\Dom\Predicate; -use DOMNameSpaceNode; -use DOMNode; +use \DOM\NameSpaceNode; +use \DOM\Node; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Predicate\is_default_xmlns_attribute; @@ -16,7 +16,7 @@ final class IsDefaultXmlnsAttributeTest extends TestCase * * @dataProvider provideTestCases */ - public function test_it_knows_default_xmlns_attribute(DOMNode|DOMNameSpaceNode $node, bool $expected): void + public function test_it_knows_default_xmlns_attribute(\DOM\Node|\DOM\NameSpaceNode $node, bool $expected): void { static::assertSame($expected, is_default_xmlns_attribute($node)); } diff --git a/tests/Xml/Dom/Predicate/IsDocumentElementTest.php b/tests/Xml/Dom/Predicate/IsDocumentElementTest.php index 018cd06e..5872cef9 100644 --- a/tests/Xml/Dom/Predicate/IsDocumentElementTest.php +++ b/tests/Xml/Dom/Predicate/IsDocumentElementTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Predicate; -use DOMNode; +use \DOM\Node; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Predicate\is_document_element; @@ -15,7 +15,7 @@ final class IsDocumentElementTest extends TestCase * * @dataProvider provideTestCases */ - public function test_it_knows_document_elements(DOMNode $node, bool $expected): void + public function test_it_knows_document_elements(\DOM\Node $node, bool $expected): void { static::assertSame($expected, is_document_element($node)); } diff --git a/tests/Xml/Dom/Predicate/IsDocumentTest.php b/tests/Xml/Dom/Predicate/IsDocumentTest.php index 8ae4435b..3030afb3 100644 --- a/tests/Xml/Dom/Predicate/IsDocumentTest.php +++ b/tests/Xml/Dom/Predicate/IsDocumentTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Predicate; -use DOMNode; +use \DOM\Node; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Predicate\is_document; @@ -15,7 +15,7 @@ final class IsDocumentTest extends TestCase * * @dataProvider provideTestCases */ - public function test_it_knows_documents(DOMNode $node, bool $expected): void + public function test_it_knows_documents(\DOM\Node $node, bool $expected): void { static::assertSame($expected, is_document($node)); } diff --git a/tests/Xml/Dom/Predicate/IsElementTest.php b/tests/Xml/Dom/Predicate/IsElementTest.php index 0f94a3bb..b6bbbe74 100644 --- a/tests/Xml/Dom/Predicate/IsElementTest.php +++ b/tests/Xml/Dom/Predicate/IsElementTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Predicate; -use DOMNode; +use \DOM\Node; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Predicate\is_element; @@ -15,7 +15,7 @@ final class IsElementTest extends TestCase * * @dataProvider provideTestCases */ - public function test_it_knows_elements(DOMNode $node, bool $expected): void + public function test_it_knows_elements(\DOM\Node $node, bool $expected): void { static::assertSame($expected, is_element($node)); } diff --git a/tests/Xml/Dom/Predicate/IsNonEmptyTextTest.php b/tests/Xml/Dom/Predicate/IsNonEmptyTextTest.php index 95cc8230..55f4143e 100644 --- a/tests/Xml/Dom/Predicate/IsNonEmptyTextTest.php +++ b/tests/Xml/Dom/Predicate/IsNonEmptyTextTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Predicate; -use DOMNode; +use \DOM\Node; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Predicate\is_non_empty_text; @@ -15,7 +15,7 @@ final class IsNonEmptyTextTest extends TestCase * * @dataProvider provideTestCases */ - public function test_it_knows_text(DOMNode $node, bool $expected): void + public function test_it_knows_text(\DOM\Node $node, bool $expected): void { static::assertSame($expected, is_non_empty_text($node)); } diff --git a/tests/Xml/Dom/Predicate/IsTextTest.php b/tests/Xml/Dom/Predicate/IsTextTest.php index bbddf787..f3902a09 100644 --- a/tests/Xml/Dom/Predicate/IsTextTest.php +++ b/tests/Xml/Dom/Predicate/IsTextTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Predicate; -use DOMNode; +use \DOM\Node; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Predicate\is_text; @@ -15,7 +15,7 @@ final class IsTextTest extends TestCase * * @dataProvider provideTestCases */ - public function test_it_knows_text(DOMNode $node, bool $expected): void + public function test_it_knows_text(\DOM\Node $node, bool $expected): void { static::assertSame($expected, is_text($node)); } diff --git a/tests/Xml/Dom/Predicate/IsWhitespaceTest.php b/tests/Xml/Dom/Predicate/IsWhitespaceTest.php index 5723c5e1..6be5f427 100644 --- a/tests/Xml/Dom/Predicate/IsWhitespaceTest.php +++ b/tests/Xml/Dom/Predicate/IsWhitespaceTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Predicate; -use DOMNode; +use \DOM\Node; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Predicate\is_whitespace; @@ -15,7 +15,7 @@ final class IsWhitespaceTest extends TestCase * * @dataProvider provideTestCases */ - public function test_it_knows_whitespaces(DOMNode $node, bool $expected): void + public function test_it_knows_whitespaces(\DOM\Node $node, bool $expected): void { static::assertSame($expected, is_whitespace($node)); } diff --git a/tests/Xml/Dom/Predicate/IsXmlnsAttributeTest.php b/tests/Xml/Dom/Predicate/IsXmlnsAttributeTest.php index 78ca9618..32ce19b6 100644 --- a/tests/Xml/Dom/Predicate/IsXmlnsAttributeTest.php +++ b/tests/Xml/Dom/Predicate/IsXmlnsAttributeTest.php @@ -4,8 +4,8 @@ namespace VeeWee\Tests\Xml\Dom\Predicate; -use DOMNameSpaceNode; -use DOMNode; +use \DOM\NameSpaceNode; +use \DOM\Node; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; use function VeeWee\Xml\Dom\Predicate\is_xmlns_attribute; @@ -16,7 +16,7 @@ final class IsXmlnsAttributeTest extends TestCase * * @dataProvider provideTestCases */ - public function test_it_knows_xmlns_attributes(DOMNode|DOMNameSpaceNode $node, bool $expected): void + public function test_it_knows_xmlns_attributes(\DOM\Node|\DOM\NameSpaceNode $node, bool $expected): void { static::assertSame($expected, is_xmlns_attribute($node)); } diff --git a/tests/Xml/Dom/Traverser/TraverserTest.php b/tests/Xml/Dom/Traverser/TraverserTest.php index c343ff52..77c134ae 100644 --- a/tests/Xml/Dom/Traverser/TraverserTest.php +++ b/tests/Xml/Dom/Traverser/TraverserTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Traverser; -use DOMNode; +use \DOM\Node; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; use VeeWee\Xml\Dom\Traverser\Action; @@ -37,7 +37,7 @@ public function test_it_can_traverse_single_node(): void $traverser = new Traverser( new class() extends AbstractVisitor { - public function onNodeLeave(DOMNode $node): Action + public function onNodeLeave(\DOM\Node $node): Action { attribute('who', 'Jos')($node); return new Action\Noop(); @@ -55,7 +55,7 @@ public function test_it_can_traverse_attributes(): void $doc = Document::fromXmlString($actual = ''); $doc->traverse( new class() extends AbstractVisitor { - public function onNodeLeave(DOMNode $node): Action + public function onNodeLeave(\DOM\Node $node): Action { if (!is_attribute($node)) { return new Action\Noop(); @@ -77,7 +77,7 @@ public function test_it_can_traverse_child_nodes(): void $doc = Document::fromXmlString($actual = ' '); $doc->traverse( new class() extends AbstractVisitor { - public function onNodeLeave(DOMNode $node): Action + public function onNodeLeave(\DOM\Node $node): Action { if (is_non_empty_text($node)) { $node->nodeValue = 'Yo'; @@ -107,7 +107,7 @@ public function test_it_can_handle_node_enter_and_leave(): void $doc = Document::fromXmlString($actual = ''); $doc->traverse( new class() extends AbstractVisitor { - public function onNodeEnter(DOMNode $node): Action + public function onNodeEnter(\DOM\Node $node): Action { if (!is_element($node)) { return new Action\Noop(); @@ -117,7 +117,7 @@ public function onNodeEnter(DOMNode $node): Action return new Action\Noop(); } - public function onNodeLeave(DOMNode $node): Action + public function onNodeLeave(\DOM\Node $node): Action { if (!is_element($node)) { return new Action\Noop(); @@ -153,7 +153,7 @@ public function test_it_can_recursively_remove_empty_nodes(): void ); $transformedNode = $doc->traverse(new class extends AbstractVisitor { - public function onNodeLeave(DOMNode $node): Action + public function onNodeLeave(\DOM\Node $node): Action { if (!is_element($node)) { return new Action\Noop(); diff --git a/tests/Xml/Dom/Validator/ValidatorChainTest.php b/tests/Xml/Dom/Validator/ValidatorChainTest.php index 06abfe2a..5ca38310 100644 --- a/tests/Xml/Dom/Validator/ValidatorChainTest.php +++ b/tests/Xml/Dom/Validator/ValidatorChainTest.php @@ -4,7 +4,7 @@ namespace VeeWee\Tests\Xml\Dom\Validator; -use DOMDocument; +use \DOM\XMLDocument as DOMDocument; use PHPUnit\Framework\TestCase; use VeeWee\Tests\Xml\ErrorHandling\Issue\UseIssueTrait; use VeeWee\Xml\Dom\Document; diff --git a/tests/Xml/Dom/Xpath/Locator/QuerySingleTest.php b/tests/Xml/Dom/Xpath/Locator/QuerySingleTest.php index ee2d5777..2dbe8cb1 100644 --- a/tests/Xml/Dom/Xpath/Locator/QuerySingleTest.php +++ b/tests/Xml/Dom/Xpath/Locator/QuerySingleTest.php @@ -2,7 +2,7 @@ namespace VeeWee\Tests\Xml\Dom\Xpath\Locator; -use DOMElement; +use \DOM\Element; use PHPUnit\Framework\TestCase; use VeeWee\Xml\Dom\Document; use VeeWee\Xml\Exception\RuntimeException; @@ -36,7 +36,7 @@ public function test_it_can_find_single_xpath_element(): void $xpath = $this->provideXml()->xpath(); $actual = $xpath->querySingle('//item'); - static::assertInstanceOf(DOMElement::class, $actual); + static::assertInstanceOf(\DOM\Element::class, $actual); } @@ -48,7 +48,7 @@ public function test_it_can_find_single_xpath_element_with_node_context(): void $xpath = $doc->xpath(); $actual = $xpath->querySingle('./world', $hello); - static::assertInstanceOf(DOMElement::class, $actual); + static::assertInstanceOf(\DOM\Element::class, $actual); } private function provideXml(): Document