diff --git a/src/FluentDOM.php b/src/FluentDOM.php index 7f06bc43..6b5166d3 100644 --- a/src/FluentDOM.php +++ b/src/FluentDOM.php @@ -111,7 +111,7 @@ public static function QueryCss( * * @throws InvalidArgument */ - public static function setLoader(Loadable $loader = NULL): void { + public static function setLoader(?Loadable $loader = NULL): void { if (!$loader) { self::$_loader = NULL; return; diff --git a/src/FluentDOM/Creator.php b/src/FluentDOM/Creator.php index ee4c0880..e593fb4e 100644 --- a/src/FluentDOM/Creator.php +++ b/src/FluentDOM/Creator.php @@ -108,7 +108,7 @@ public function pi(string $target, string $content): DOM\ProcessingInstruction { return $this->_document->createProcessingInstruction($target, $content); } - public function each(iterable $traversable, callable $map = NULL): Appendable { + public function each(iterable $traversable, ?callable $map = NULL): Appendable { return new Creator\Nodes($traversable, $map); } } diff --git a/src/FluentDOM/Creator/Nodes.php b/src/FluentDOM/Creator/Nodes.php index 6a1f19fb..530e2ccb 100644 --- a/src/FluentDOM/Creator/Nodes.php +++ b/src/FluentDOM/Creator/Nodes.php @@ -27,7 +27,7 @@ class Nodes implements Appendable, \OuterIterator { private ?\Iterator $_iterator = NULL; - public function __construct(iterable $iterable, callable $map = NULL) { + public function __construct(iterable $iterable, ?callable $map = NULL) { $this->_iterable = $iterable; $this->_map = Constraints::filterCallable($map); } diff --git a/src/FluentDOM/DOM/Document.php b/src/FluentDOM/DOM/Document.php index e63d20a4..d84fee39 100644 --- a/src/FluentDOM/DOM/Document.php +++ b/src/FluentDOM/DOM/Document.php @@ -107,7 +107,7 @@ public function registerNamespace(string $prefix, string $namespaceURI): void { * * @throws \LogicException */ - public function namespaces(iterable $namespaces = NULL): Namespaces { + public function namespaces(?iterable $namespaces = NULL): Namespaces { if (NULL !== $namespaces) { $this->_namespaces->assign([]); foreach($namespaces as $prefix => $namespaceURI) { @@ -130,8 +130,8 @@ public function namespaces(iterable $namespaces = NULL): Namespaces { */ public function createElement( string $name, - string|array $value = NULL, - array $attributes = NULL + string|array|null $value = NULL, + ?array $attributes = NULL ): Element { [$prefix, $localName] = QualifiedName::split($name); $namespaceURI = ''; @@ -164,7 +164,7 @@ public function createElement( public function createElementNS( string|null $namespace, string $qualifiedName, - string $value = NULL + ?string $value = NULL ): Element { /** @var Element $node */ $node = parent::createElementNS($namespace, $qualifiedName); @@ -180,7 +180,7 @@ public function createElementNS( * * @throws \LogicException|\DOMException */ - public function createAttribute(string $name, string $value = NULL): Attribute { + public function createAttribute(string $name, ?string $value = NULL): Attribute { [$prefix] = QualifiedName::split($name); if (empty($prefix)) { $node = parent::createAttribute($name); @@ -201,7 +201,7 @@ public function createAttribute(string $name, string $value = NULL): Attribute { public function appendElement( string $name, string|array $value = '', - array $attributes = NULL + ?array $attributes = NULL ): Element { $this->appendChild( $node = $this->createElement($name, $value, $attributes) @@ -211,8 +211,8 @@ public function appendElement( private function appendAttributes( \DOMElement $node, - string|array $content = NULL, - array $attributes = NULL + string|array|null $content = NULL, + ?array $attributes = NULL ): void { if (\is_array($content)) { /** @noinspection CallableParameterUseCaseInTypeContextInspection */ @@ -225,7 +225,7 @@ private function appendAttributes( } } - private function appendContent(\DOMElement $node, string|array $content = NULL): void { + private function appendContent(\DOMElement $node, string|array|null $content = NULL): void { if (!((empty($content) && !\is_numeric($content)) || \is_array($content) )) { $node->appendChild($this->createTextNode((string)$content)); } @@ -237,7 +237,7 @@ private function appendContent(\DOMElement $node, string|array $content = NULL): * Overloading saveXML() with a removed type hint triggers an E_STRICT error, * so the function needs a new name. :-( */ - public function saveXML(\DOMNode|\DOMNodeList $context = NULL, int $options = NULL): string { + public function saveXML(\DOMNode|\DOMNodeList|null $context = NULL, ?int $options = NULL): string { if ($context instanceof \DOMNodeList) { $result = ''; foreach ($context as $node) { @@ -251,7 +251,7 @@ public function saveXML(\DOMNode|\DOMNodeList $context = NULL, int $options = NU /** * @deprecated */ - public function toXml(\DOMNode|\DOMNodeList $context = NULL, int $options = NULL): string { + public function toXml(\DOMNode|\DOMNodeList|null $context = NULL, ?int $options = NULL): string { return $this->saveXML($context, $options); } /** @@ -269,14 +269,14 @@ public function __toString(): string { * * @deprecated */ - public function toHtml(\DOMNode|\DOMNodeList $context = NULL): string { + public function toHtml(\DOMNode|\DOMNodeList|null $context = NULL): string { return $this->saveHTML($context); } /** * Allow to save HTML fragments, providing a node list */ - public function saveHTML(\DOMNode|\DOMNodeList $context = NULL): string { + public function saveHTML(\DOMNode|\DOMNodeList|null $context = NULL): string { if ($context instanceof \DOMDocumentFragment) { $context = $context->childNodes; } @@ -323,7 +323,7 @@ public function getElementsByTagName(string $qualifiedName): \DOMNodeList { * @throws \DOMException */ public function createDocumentType( - string $qualifiedName = NULL, string $publicId = NULL, string $systemId = NULL + ?string $qualifiedName = NULL, ?string $publicId = NULL, ?string $systemId = NULL ): \DOMDocumentType { return (new Implementation())->createDocumentType($qualifiedName, (string)$publicId, (string)$systemId); } diff --git a/src/FluentDOM/DOM/DocumentFragment.php b/src/FluentDOM/DOM/DocumentFragment.php index 310736dc..8d510709 100644 --- a/src/FluentDOM/DOM/DocumentFragment.php +++ b/src/FluentDOM/DOM/DocumentFragment.php @@ -64,7 +64,7 @@ public function getIterator(): \Iterator { * * @throws \InvalidArgumentException */ - public function namespaces(iterable|\DOMElement $namespaces = NULL): Namespaces { + public function namespaces(iterable|\DOMElement|null $namespaces = NULL): Namespaces { if (NULL !== $namespaces || (!$this->_namespaces instanceof Namespaces)) { $this->_namespaces = new Namespaces(); } @@ -110,7 +110,7 @@ public function registerNamespace(string $prefix, string $namespaceURI): void { * @return bool * @throws \InvalidArgumentException */ - public function appendXml(string $data, iterable|\DOMElement $namespaces = NULL): bool { + public function appendXml(string $data, null|iterable|\DOMElement $namespaces = NULL): bool { $namespaces = $this->namespaces($namespaces); if (\count($namespaces) === 0) { return parent::appendXML($data); @@ -138,7 +138,7 @@ public function appendXml(string $data, iterable|\DOMElement $namespaces = NULL) * @throws \LogicException|\DOMException */ public function appendElement( - string $name, string|array $content = '', array $attributes = NULL + string $name, string|array $content = '', ?array $attributes = NULL ): Element { $this->appendChild( $node = $this->ownerDocument->createElement($name, $content, $attributes) diff --git a/src/FluentDOM/DOM/Element.php b/src/FluentDOM/DOM/Element.php index 76033ce0..0dd85d6b 100644 --- a/src/FluentDOM/DOM/Element.php +++ b/src/FluentDOM/DOM/Element.php @@ -218,7 +218,7 @@ public function append(...$nodes): void { * @throws \LogicException|\DOMException */ public function appendElement( - string $qualifiedName, string|array $content = '', array $attributes = NULL + string $qualifiedName, string|array $content = '', ?array $attributes = NULL ): Element { $this->appendChild( $node = $this->getDocument()->createElement($qualifiedName, $content, $attributes) @@ -452,7 +452,7 @@ private function getDocument(): Document { * * @throws \LogicException */ - public function applyNamespaces(string|array $prefixes = NULL): void { + public function applyNamespaces(string|array|null $prefixes = NULL): void { if ($prefixes !== NULL && !\is_array($prefixes)) { $prefixes = [$prefixes]; } diff --git a/src/FluentDOM/DOM/Implementation.php b/src/FluentDOM/DOM/Implementation.php index f46e4464..4a44288c 100644 --- a/src/FluentDOM/DOM/Implementation.php +++ b/src/FluentDOM/DOM/Implementation.php @@ -21,9 +21,9 @@ class Implementation extends \DOMImplementation { public function createDocument( - string $namespace = NULL, - string $qualifiedName = NULL, - DOMDocumentType $doctype = NULL + ?string $namespace = NULL, + ?string $qualifiedName = NULL, + ?DOMDocumentType $doctype = NULL ): Document { $document = new Document(); if ($doctype) { diff --git a/src/FluentDOM/DOM/Node/ParentNode/Implementation.php b/src/FluentDOM/DOM/Node/ParentNode/Implementation.php index 748981ed..92205801 100644 --- a/src/FluentDOM/DOM/Node/ParentNode/Implementation.php +++ b/src/FluentDOM/DOM/Node/ParentNode/Implementation.php @@ -25,7 +25,7 @@ */ trait Implementation { - abstract public function insertBefore(\DOMNode $newChild, \DOMNode $refChild = NULL); + abstract public function insertBefore(\DOMNode $newChild, ?\DOMNode $refChild = NULL); abstract public function appendChild(\DOMNode $newChild); diff --git a/src/FluentDOM/DOM/Node/WholeText.php b/src/FluentDOM/DOM/Node/WholeText.php index 6897a553..3a072a9c 100644 --- a/src/FluentDOM/DOM/Node/WholeText.php +++ b/src/FluentDOM/DOM/Node/WholeText.php @@ -50,7 +50,7 @@ public function replaceWholeText($content): static|NULL|Text|CdataSection { } return TRUE; }; - $replaceNode = static function(\DOMNode $node = NULL) use ($canReplaceEntity) { + $replaceNode = static function(?\DOMNode $node = NULL) use ($canReplaceEntity) { if ( $node instanceof \DOMNode && !( diff --git a/src/FluentDOM/DOM/Node/Xpath.php b/src/FluentDOM/DOM/Node/Xpath.php index 7cca5a1a..9f0c3336 100644 --- a/src/FluentDOM/DOM/Node/Xpath.php +++ b/src/FluentDOM/DOM/Node/Xpath.php @@ -28,7 +28,7 @@ trait Xpath { * element. */ public function evaluate( - string $expression, Node $context = NULL + string $expression, ?Node $context = NULL ): string|float|bool|\DOMNodeList { $document = $this instanceof Document ? $this diff --git a/src/FluentDOM/DOM/Xpath.php b/src/FluentDOM/DOM/Xpath.php index e3c9bda0..45051588 100644 --- a/src/FluentDOM/DOM/Xpath.php +++ b/src/FluentDOM/DOM/Xpath.php @@ -59,7 +59,7 @@ public function registerNamespace(string $prefix, string $namespace): bool { * is disabled by default. */ public function evaluate( - string $expression, \DOMNode $contextNode = NULL, $registerNodeNS = NULL + string $expression, ?\DOMNode $contextNode = NULL, $registerNodeNS = NULL ): string|float|bool|\DOMNodeList { $registerNodeNS = $registerNodeNS ?? $this->registerNodeNamespaces; return parent::evaluate($expression, $contextNode, (bool)$registerNodeNS); @@ -69,7 +69,7 @@ public function evaluate( * Fetch nodes or scalar values from the DOM using Xpath expression. */ public function __invoke( - string $expression, \DOMNode $contextNode = NULL + string $expression, ?\DOMNode $contextNode = NULL ): string|float|bool|\DOMNodeList { return $this->evaluate($expression, $contextNode); } @@ -83,7 +83,7 @@ public function __invoke( * @deprecated */ public function query( - string $expression, \DOMNode $contextNode = NULL, bool $registerNodeNS = NULL + string $expression, ?\DOMNode $contextNode = NULL, ?bool $registerNodeNS = NULL ): ?\DOMNodeList { $result = $this->evaluate($expression, $contextNode, $registerNodeNS); return $result instanceof \DOMNodeList ? $result : NULL; @@ -97,7 +97,7 @@ public function query( * @param NULL|bool $registerNodeNS * @return \DOMNode|NULL */ - public function firstOf(string $expression, \DOMNode $contextNode = NULL, bool $registerNodeNS = NULL): ?\DOMNode { + public function firstOf(string $expression, ?\DOMNode $contextNode = NULL, ?bool $registerNodeNS = NULL): ?\DOMNode { $nodes = $this->evaluate($expression, $contextNode, $registerNodeNS); if ($nodes instanceof \DOMNodeList && $nodes->length > 0) { return $nodes->item(0); diff --git a/src/FluentDOM/Loader/HtmlLoader.php b/src/FluentDOM/Loader/HtmlLoader.php index 4120cceb..b9c366b7 100644 --- a/src/FluentDOM/Loader/HtmlLoader.php +++ b/src/FluentDOM/Loader/HtmlLoader.php @@ -73,7 +73,7 @@ function() use ($source, $contentType, $options) { return NULL; } - private function ensureEncodingPI(string $source, string $encoding = NULL, bool $force = FALSE): string { + private function ensureEncodingPI(string $source, ?string $encoding = NULL, bool $force = FALSE): string { $hasXmlPi = \preg_match('(<\\?xml\\s)', $source); if (!$force && ($charset = $this->getCharsetFromMetaTag($source))) { $encoding = (string)$charset; diff --git a/src/FluentDOM/Loader/Json/JsonDOMLoader.php b/src/FluentDOM/Loader/Json/JsonDOMLoader.php index 03de5e8b..45e5c784 100644 --- a/src/FluentDOM/Loader/Json/JsonDOMLoader.php +++ b/src/FluentDOM/Loader/Json/JsonDOMLoader.php @@ -118,7 +118,7 @@ private function prepareOnMapKey($options): ?callable { * * function callback(string $key, bool $isArrayElement) {} */ - public function onMapKey(callable $callback = NULL): ?callable { + public function onMapKey(?callable $callback = NULL): ?callable { if (NULL !== $callback) { $this->_onMapKey = Constraints::filterCallable($callback); } diff --git a/src/FluentDOM/Loader/LoaderResult.php b/src/FluentDOM/Loader/LoaderResult.php index d667e7a0..aa8c72ef 100644 --- a/src/FluentDOM/Loader/LoaderResult.php +++ b/src/FluentDOM/Loader/LoaderResult.php @@ -20,7 +20,7 @@ class LoaderResult { private NULL|\DOMNode|iterable $_selection; public function __construct( - Document $document, string $contentType, \DOMNode|iterable $selection = NULL + Document $document, string $contentType, null|\DOMNode|iterable $selection = NULL ) { $this->_document = $document; $this->_contentType = $contentType; diff --git a/src/FluentDOM/Loader/Text/CSVLoader.php b/src/FluentDOM/Loader/Text/CSVLoader.php index 36852c2a..91d7f226 100644 --- a/src/FluentDOM/Loader/Text/CSVLoader.php +++ b/src/FluentDOM/Loader/Text/CSVLoader.php @@ -91,7 +91,7 @@ public function loadFragment($source, string $contentType, $options = []): ?Docu * @throws \DOMException|UnattachedNode */ private function appendLines( - \DOMNode $parent, iterable $lines, bool $hasHeaderLine, array $columns = NULL + \DOMNode $parent, iterable $lines, bool $hasHeaderLine, ?array $columns = NULL ): void { $document = Implementation::getNodeDocument($parent); $headers = NULL; @@ -126,7 +126,7 @@ private function appendField(Element $parent, string $name, string $value): void } } - private function getHeaders(array $record, bool $hasHeaderLine, array $columns = NULL): array { + private function getHeaders(array $record, bool $hasHeaderLine, ?array $columns = NULL): array { if (\is_array($columns)) { $headers = []; foreach ($record as $index => $field) { diff --git a/src/FluentDOM/Loader/XDM/JsonAsXDMLoader.php b/src/FluentDOM/Loader/XDM/JsonAsXDMLoader.php index 012114a2..83d0f5d1 100644 --- a/src/FluentDOM/Loader/XDM/JsonAsXDMLoader.php +++ b/src/FluentDOM/Loader/XDM/JsonAsXDMLoader.php @@ -101,7 +101,7 @@ public function loadFragment( * @throws UnattachedNode|\DOMException */ protected function transferTo( - \DOMNode $target, mixed $json, string $key = NULL, int $recursions = 100 + \DOMNode $target, mixed $json, ?string $key = NULL, int $recursions = 100 ): void { if ($recursions < 1) { return; diff --git a/src/FluentDOM/Loaders.php b/src/FluentDOM/Loaders.php index 665be036..eaa84fcc 100644 --- a/src/FluentDOM/Loaders.php +++ b/src/FluentDOM/Loaders.php @@ -29,7 +29,7 @@ class Loaders implements \IteratorAggregate, Loadable { /** * Store the a list of loaders if provided. */ - public function __construct(iterable $list = NULL) { + public function __construct(?iterable $list = NULL) { if (is_iterable($list)) { /** @var array|\Traversable $list */ foreach ($list as $loader) { diff --git a/src/FluentDOM/Nodes.php b/src/FluentDOM/Nodes.php index 5245836f..4575d1d2 100644 --- a/src/FluentDOM/Nodes.php +++ b/src/FluentDOM/Nodes.php @@ -77,7 +77,7 @@ class Nodes implements \ArrayAccess, \Countable, \IteratorAggregate { * @throws \OutOfBoundsException * @throws \LogicException */ - public function __construct(mixed $source = NULL, string $contentType = NULL) { + public function __construct(mixed $source = NULL, ?string $contentType = NULL) { if (NULL !== $source) { $this->load($source, $contentType); } elseif (NULL !== $contentType) { @@ -96,7 +96,7 @@ public function __construct(mixed $source = NULL, string $contentType = NULL) { */ public function load( mixed $source, - string $contentType = NULL, + ?string $contentType = NULL, iterable $options = [] ): self { $contentType = $contentType ?: 'text/xml'; @@ -155,7 +155,7 @@ private function prepareSource( * Set the loaders list. * @throws \InvalidArgumentException */ - public function loaders(Loadable|iterable $loaders = NULL): Loadable { + public function loaders(Loadable|iterable|null $loaders = NULL): Loadable { if (NULL !== $loaders) { if ($loaders instanceof Loadable) { $this->_loaders = $loaders; @@ -199,8 +199,8 @@ public function item(int $position): \DOMNode|NULL { * @throws \LogicException */ public function xpath( - string $expression = NULL, - \DOMNode $contextNode = NULL + ?string $expression = NULL, + ?\DOMNode $contextNode = NULL ): Xpath|\DOMNodeList|float|string { if (NULL !== $expression) { return $this->getXpath()->evaluate($expression, $contextNode); @@ -264,7 +264,7 @@ private function applyNamespaces(): void { * * @throws \LogicException */ - public function formatOutput(string $contentType = NULL): self { + public function formatOutput(?string $contentType = NULL): self { if (NULL !== $contentType) { $this->setContentType($contentType); } @@ -358,7 +358,7 @@ public function prepareSelector(string $selector, int $contextMode): string { * @throws \InvalidArgumentException */ public function getSelectorCallback( - callable|string|iterable|\DOMNode $selector = NULL + callable|string|iterable|\DOMNode|null $selector = NULL ): ?\Closure { if (NULL === $selector) { return NULL; @@ -395,7 +395,7 @@ public function getSelectorCallback( /** * Test that selector matches context and return TRUE/FALSE */ - protected function matches(string $selector, \DOMNode $context = NULL): bool { + protected function matches(string $selector, ?\DOMNode $context = NULL): bool { $check = $this->xpath->evaluate( $this->prepareSelector($selector, self::CONTEXT_SELF), $context ); @@ -576,7 +576,7 @@ public function __toString(): string { * @throws \OutOfBoundsException * @throws \InvalidArgumentException */ - public function spawn(iterable|\DOMElement|\DOMCharacterData $elements = NULL): static { + public function spawn(iterable|\DOMElement|\DOMCharacterData|null $elements = NULL): static { $result = clone $this; $result->_parent = $this; $result->_document = $this->getDocument(); @@ -606,7 +606,7 @@ public function end(): self { * @throws \OutOfBoundsException */ public function push( - iterable|\DOMElement|\DOMCharacterData $elements = NULL, bool $ignoreTextNodes = FALSE + iterable|\DOMElement|\DOMCharacterData|null $elements = NULL, bool $ignoreTextNodes = FALSE ): static { if (Constraints::filterNode($elements, $ignoreTextNodes)) { if ($elements->ownerDocument !== $this->_document) { @@ -641,7 +641,7 @@ public function push( */ public function each( callable $function, - callable|bool $elementsFilter = NULL + callable|bool|null $elementsFilter = NULL ): self { if (TRUE === $elementsFilter) { $filter = static function ($node) { @@ -747,7 +747,7 @@ private function prepareSelectorAsFilter(string $selector, int $contextMode): \C * @throws \LogicException * @throws \InvalidArgumentException */ - public function index(string|\DOMNode|iterable $selector = NULL): int { + public function index(string|\DOMNode|iterable|null $selector = NULL): int { if (\count($this->_nodes) > 0) { if (NULL === $selector) { return (int)$this->xpath( @@ -810,7 +810,7 @@ public function unique(array $array): array { } public function serializerFactories( - Serializer\Factory\Group $factories = NULL + ?Serializer\Factory\Group $factories = NULL ): Serializer\Factory\Group { if (NULL !== $factories) { $this->_serializerFactories = $factories; diff --git a/src/FluentDOM/Nodes/Builder.php b/src/FluentDOM/Nodes/Builder.php index 5735c597..d4e5fc14 100644 --- a/src/FluentDOM/Nodes/Builder.php +++ b/src/FluentDOM/Nodes/Builder.php @@ -61,7 +61,7 @@ private function getNodeList( * @throws \InvalidArgumentException * @throws \LogicException */ - public function getTargetNodes(mixed $selector, \DOMNode $context = NULL): array { + public function getTargetNodes(mixed $selector, ?\DOMNode $context = NULL): array { if ($nodes = $this->getNodeList($selector)) { return $nodes; } diff --git a/src/FluentDOM/Nodes/Fetcher.php b/src/FluentDOM/Nodes/Fetcher.php index 2ce0e079..1cc291f7 100644 --- a/src/FluentDOM/Nodes/Fetcher.php +++ b/src/FluentDOM/Nodes/Fetcher.php @@ -40,7 +40,7 @@ public function __construct(Nodes $nodes) { * @throws \InvalidArgumentException */ public function fetch( - string $expression, callable $filter = NULL, callable $stopAt = NULL, int $options = 0 + string $expression, ?callable $filter = NULL, ?callable $stopAt = NULL, int $options = 0 ): array { if ($this->validateContextIgnore($expression, $options)) { $nodes = $this->fetchFor( @@ -105,9 +105,9 @@ private function unique(array $nodes, int $options): array { */ private function fetchFor( string $expression, - \DOMNode $context = NULL, - callable $filter = NULL, - callable $stopAt = NULL, + ?\DOMNode $context = NULL, + ?callable $filter = NULL, + ?callable $stopAt = NULL, int $options = 0 ): array { $nodes = $this->fetchNodes($expression, $context, $options); @@ -124,7 +124,7 @@ private function fetchFor( * @throws \InvalidArgumentException */ private function fetchNodes( - string $expression, \DOMNode $context = NULL, int $options = 0 + string $expression, ?\DOMNode $context = NULL, int $options = 0 ): array { $nodes = $this->_nodes->xpath($expression, $context); if (!$nodes instanceof \DOMNodeList) { @@ -148,7 +148,7 @@ private function fetchNodes( * @return array */ private function filterNodes( - array $nodes, callable $filter = NULL, callable $stopAt = NULL, int $options = 0 + array $nodes, ?callable $filter = NULL, ?callable $stopAt = NULL, int $options = 0 ): array { $result = []; foreach ($nodes as $index => $node) { @@ -179,7 +179,7 @@ private function filterNodes( * @return bool[] */ private function getNodeStatus( - \DOMNode $node, int $index, callable $filter = NULL, callable $stopAt = NULL + \DOMNode $node, int $index, ?callable $filter = NULL, ?callable $stopAt = NULL ): array { return [ empty($filter) || $filter($node, $index), diff --git a/src/FluentDOM/Query.php b/src/FluentDOM/Query.php index d6063e49..deaa6611 100644 --- a/src/FluentDOM/Query.php +++ b/src/FluentDOM/Query.php @@ -265,7 +265,7 @@ private function applyToSelector( * @example ../examples/Query/add.php Usage Examples: FluentDOM::add() */ public function add( - string|iterable $selector, iterable|\DOMNode $context = NULL + string|iterable $selector, iterable|\DOMNode|null $context = NULL ): static { $result = $this->spawn($this); if (NULL !== $context) { @@ -302,7 +302,7 @@ public function addBack(): static { * @throws \InvalidArgumentException * @example ../examples/Query/children.php Usage Examples: FluentDOM\Query::children() */ - public function children(string $selector = NULL): static { + public function children(?string $selector = NULL): static { return $this->fetch('*', $selector, NULL, Nodes\Fetcher::UNIQUE); } @@ -315,7 +315,7 @@ public function children(string $selector = NULL): static { * @throws \InvalidArgumentException * @example ../examples/Query/closest.php Usage Example: FluentDOM\Query::closest() */ - public function closest(string|callable $selector, iterable $context = NULL): static { + public function closest(string|callable $selector, ?iterable $context = NULL): static { $context = $context ? $this->spawn($context) : $this; return $context->fetch( 'ancestor-or-self::*', @@ -397,7 +397,7 @@ public function first(): static { * * @param int|NULL $position optional offset of a single element to get. */ - public function get(int $position = NULL): array|\DOMNode|NULL { + public function get(?int $position = NULL): array|\DOMNode|NULL { if (NULL === $position) { return $this->_nodes; } @@ -514,7 +514,7 @@ function (\DOMNode $node, $index) use ($callback) { * @throws \InvalidArgumentException * @example ../examples/Query/next.php Usage Example: FluentDOM\Query::next() */ - public function next(string $selector = NULL): static { + public function next(?string $selector = NULL): static { return $this->fetch( 'following-sibling::node()[ self::* or (self::text() and normalize-space(.) != "") @@ -533,7 +533,7 @@ public function next(string $selector = NULL): static { * @throws \InvalidArgumentException * @example ../examples/Query/nextAll.php Usage Example: FluentDOM\Query::nextAll() */ - public function nextAll(string $selector = NULL): static { + public function nextAll(?string $selector = NULL): static { return $this->fetch( 'following-sibling::*|following-sibling::text()[normalize-space(.) != ""]', $selector @@ -548,7 +548,7 @@ public function nextAll(string $selector = NULL): static { * @throws \LogicException * @throws \InvalidArgumentException */ - public function nextUntil(string $selector = NULL, string $filter = NULL): static { + public function nextUntil(?string $selector = NULL, ?string $filter = NULL): static { return $this->fetch( 'following-sibling::*|following-sibling::text()[normalize-space(.) != ""]', $filter, @@ -579,7 +579,7 @@ public function parent(): static { * @throws \InvalidArgumentException * @example ../examples/Query/parents.php Usage Example: FluentDOM\Query::parents() */ - public function parents(string $selector = NULL): static { + public function parents(?string $selector = NULL): static { return $this->fetch('ancestor::*', $selector, NULL, Fetcher::REVERSE); } @@ -591,7 +591,7 @@ public function parents(string $selector = NULL): static { * @throws \LogicException * @throws \InvalidArgumentException */ - public function parentsUntil(string $stopAt = NULL, string $filter = NULL): static { + public function parentsUntil(?string $stopAt = NULL, ?string $filter = NULL): static { return $this->fetch('ancestor::*', $filter, $stopAt, Nodes\Fetcher::REVERSE); } @@ -604,7 +604,7 @@ public function parentsUntil(string $stopAt = NULL, string $filter = NULL): stat * @throws \InvalidArgumentException * @example ../examples/Query/prev.php Usage Example: FluentDOM\Query::prev() */ - public function prev(string $selector = NULL): static { + public function prev(?string $selector = NULL): static { return $this->fetch( 'preceding-sibling::node()[ self::* or (self::text() and normalize-space(.) != "") @@ -623,7 +623,7 @@ public function prev(string $selector = NULL): static { * @throws \InvalidArgumentException * @example ../examples/Query/prevAll.php Usage Example: FluentDOM\Query::prevAll() */ - public function prevAll(string $selector = NULL): static { + public function prevAll(?string $selector = NULL): static { return $this->fetch( 'preceding-sibling::*|preceding-sibling::text()[normalize-space(.) != ""]', $selector, @@ -640,7 +640,7 @@ public function prevAll(string $selector = NULL): static { * @throws \LogicException * @throws \InvalidArgumentException */ - public function prevUntil(string $selector = NULL, string $filter = NULL): static { + public function prevUntil(?string $selector = NULL, ?string $filter = NULL): static { return $this->fetch( 'preceding-sibling::*|preceding-sibling::text()[normalize-space(.) != ""]', $filter, @@ -669,7 +669,7 @@ public function reverse(): static { * @throws \InvalidArgumentException * @example ../examples/Query/siblings.php Usage Example: FluentDOM\Query::siblings() */ - public function siblings(string $selector = NULL): static { + public function siblings(?string $selector = NULL): static { return $this->fetch( 'preceding-sibling::*| preceding-sibling::text()[normalize-space(.) != ""]| @@ -688,7 +688,7 @@ public function siblings(string $selector = NULL): static { * @throws \InvalidArgumentException * @example ../examples/Query/slice.php Usage Example: FluentDOM\Query::slice() */ - public function slice(int $start, int $end = NULL): static { + public function slice(int $start, ?int $end = NULL): static { $result = $this->spawn(); if ($end === NULL) { $result->push(\array_slice($this->_nodes, $start)); @@ -922,7 +922,7 @@ function ($targetNode, $contentNodes) { * @throws \InvalidArgumentException * @example ../examples/Query/remove.php Usage Example: FluentDOM\Query::remove() */ - public function remove(string $selector = NULL): static { + public function remove(?string $selector = NULL): static { $result = $this->spawn(); foreach ($this->_nodes as $node) { if ( @@ -942,7 +942,7 @@ public function remove(string $selector = NULL): static { * @throws \InvalidArgumentException * @example ../examples/Query/text.php Usage Example: FluentDOM\Query::text() */ - public function text(string|callable $text = NULL): string|static { + public function text(string|callable|null $text = NULL): string|static { if (NULL !== $text) { $callback = Constraints::filterCallable($text); foreach ($this->_nodes as $index => $node) { @@ -961,7 +961,7 @@ public function text(string|callable $text = NULL): string|static { * Replace the parent nodes of the current selection with * their child nodes and remove the parent nodes. */ - public function unwrap(string $selector = NULL): static { + public function unwrap(?string $selector = NULL): static { $parents = $this->parent(); if (NULL !== $selector) { $parents = $parents->filter($selector); @@ -1086,7 +1086,7 @@ public function wrapInner(string|\DOMNode|iterable|callable $content): static { * @throws \LogicException * @example ../examples/Query/xml.php Usage Example: FluentDOM::xml() */ - public function xml(string|callable $xml = NULL): string|static { + public function xml(string|callable|null $xml = NULL): string|static { return $this->content( $xml, function ($node) { @@ -1110,7 +1110,7 @@ function ($node, $fragment) { * @throws \InvalidArgumentException * @throws InvalidFragmentLoader */ - public function outerXml(string|callable $xml = NULL): string|static { + public function outerXml(string|callable|null $xml = NULL): string|static { return $this->outerContent( $xml, function ($node) { @@ -1131,7 +1131,7 @@ function ($xml) { * @throws \InvalidArgumentException * @throws InvalidFragmentLoader */ - public function outerHtml(string|callable $html = NULL): string|static { + public function outerHtml(string|callable|null $html = NULL): string|static { return $this->outerContent( $html, function ($node) { @@ -1152,7 +1152,7 @@ function ($html) { * @throws \InvalidArgumentException * @throws InvalidFragmentLoader */ - public function html(string|callable $html = NULL): string|static { + public function html(string|callable|null $html = NULL): string|static { return $this->content( $html, function (\DOMNode $parent) { @@ -1224,7 +1224,7 @@ function (\DOMNode $node, $fragment) { /** * @throws \InvalidArgumentException */ - private function getNamesList(string|array $names = NULL): ?array { + private function getNamesList(string|array|null $names = NULL): ?array { if (\is_array($names)) { return $names; } @@ -1242,7 +1242,7 @@ private function getNamesList(string|array $names = NULL): ?array { */ private function getSetterValues( string|iterable $name, - string|float|int|callable $value = NULL + string|float|int|callable|null $value = NULL ): iterable { return is_string($name) ? [$name => $value] : $name; } @@ -1368,7 +1368,7 @@ public function removeClass(string|callable $class = ''): static { * @throws \InvalidArgumentException * @example ../examples/Query/toggleClass.php Usage Example: FluentDOM\Query::toggleClass() */ - public function toggleClass(string|callable $class, bool $switch = NULL): static { + public function toggleClass(string|callable $class, ?bool $switch = NULL): static { $callback = Constraints::filterCallable($class); $this->each( function (\DOMElement $node, $index) use ($class, $switch, $callback) { @@ -1405,7 +1405,7 @@ function (\DOMElement $node, $index) use ($class, $switch, $callback) { * toggles the specified classes if the switch is NULL. */ private function changeClassString( - string $current, string $toggle, bool $switch = NULL + string $current, string $toggle, ?bool $switch = NULL ): ?string { $currentClasses = \array_flip( \preg_split('(\s+)', \trim($current), 0, PREG_SPLIT_NO_EMPTY) ?: [] @@ -1441,7 +1441,7 @@ private function changeClassString( * @throws \InvalidArgumentException */ public function css( - string|array|Query\Css\Properties $property = NULL, + string|array|Query\Css\Properties|null $property = NULL, callable|float|int|string|NULL ...$arguments ): NULL|string|static { if (\is_string($property) && \count($arguments) === 0) { @@ -1508,7 +1508,7 @@ function (\DOMElement $node) use ($values) { * @throws \InvalidArgumentException * @example ../examples/Query/removeData.php Usage Example: FluentDOM\Query::removeData() */ - public function removeData(string|array $name = NULL): static { + public function removeData(string|array|null $name = NULL): static { $names = $this->getNamesList($name); $this->each( function ($node) use ($names) { @@ -1532,7 +1532,7 @@ function ($node) use ($names) { * Validate if the element has an data attributes attached. If it is called without an * actual $element parameter, it will check the first matched node. */ - public function hasData(\DOMElement $element = NULL): bool { + public function hasData(?\DOMElement $element = NULL): bool { if ($element || ($element = $this->getFirstElement())) { $data = new Query\Data($element); return \count($data) > 0; diff --git a/src/FluentDOM/Query/Css/Properties.php b/src/FluentDOM/Query/Css/Properties.php index 5e2b6e9d..6a31bccf 100644 --- a/src/FluentDOM/Query/Css/Properties.php +++ b/src/FluentDOM/Query/Css/Properties.php @@ -148,7 +148,7 @@ public function offsetUnset(mixed $offset): void { * Compile value argument into a string (it can be an callback) */ public function compileValue( - mixed $value, \DOMElement $node, int $index, string $currentValue = NULL + mixed $value, \DOMElement $node, int $index, ?string $currentValue = NULL ): string { if (!\is_string($value) && \is_callable($value, TRUE)) { return (string)$value($node, $index, $currentValue); diff --git a/src/FluentDOM/Utility/Namespaces.php b/src/FluentDOM/Utility/Namespaces.php index d16ee022..ecc5ff9d 100644 --- a/src/FluentDOM/Utility/Namespaces.php +++ b/src/FluentDOM/Utility/Namespaces.php @@ -29,7 +29,7 @@ class Namespaces implements NamespaceResolver, \ArrayAccess, \IteratorAggregate, private array $_stash = []; - public function __construct(iterable $namespaces = NULL) { + public function __construct(?iterable $namespaces = NULL) { if (NULL !== $namespaces) { $this->assign($namespaces); } diff --git a/src/FluentDOM/Utility/QualifiedName.php b/src/FluentDOM/Utility/QualifiedName.php index 397e77c9..63ab895e 100644 --- a/src/FluentDOM/Utility/QualifiedName.php +++ b/src/FluentDOM/Utility/QualifiedName.php @@ -69,7 +69,7 @@ private function setQName(string $name): void { * * @throws \UnexpectedValueException */ - private function isNCName(string $name, int $offset = 0, string $fullName = NULL): void { + private function isNCName(string $name, int $offset = 0, ?string $fullName = NULL): void { $nameStartChar = 'A-Z_a-z'. '\\x{C0}-\\x{D6}\\x{D8}-\\x{F6}\\x{F8}-\\x{2FF}\\x{370}-\\x{37D}'. diff --git a/src/FluentDOM/Utility/ResourceWrapper.php b/src/FluentDOM/Utility/ResourceWrapper.php index c03450d1..a67883ad 100644 --- a/src/FluentDOM/Utility/ResourceWrapper.php +++ b/src/FluentDOM/Utility/ResourceWrapper.php @@ -84,7 +84,7 @@ public function url_stat( public function stream_open( /** @noinspection PhpUnusedParameterInspection */ - string $path, string $mode, int $options, string &$opened_path = NULL + string $path, string $mode, int $options, ?string &$opened_path = NULL ): bool { [$protocol, $id] = \explode('://', $path); $context = \stream_context_get_options($this->context); diff --git a/src/FluentDOM/XMLReader.php b/src/FluentDOM/XMLReader.php index 7c5ff33a..eb2165ea 100644 --- a/src/FluentDOM/XMLReader.php +++ b/src/FluentDOM/XMLReader.php @@ -46,7 +46,7 @@ public function registerNamespace(string $prefix, string $namespaceURI): void { * a namespace prefix it will be resolved using the registered namespaces. */ public function next( - string $name = NULL, string $namespaceURI = NULL, callable $filter = NULL + ?string $name = NULL, ?string $namespaceURI = NULL, ?callable $filter = NULL ): bool { if (NULL !== $name) { [$localName, $namespaceURI, $ignoreNamespace] = $this->prepareCondition($name, $namespaceURI); @@ -80,7 +80,7 @@ public function next( * @param callable|NULL $filter * @return bool */ - public function read(string $name = NULL, string $namespaceURI = NULL, callable $filter = NULL): bool { + public function read(?string $name = NULL, ?string $namespaceURI = NULL, ?callable $filter = NULL): bool { if (NULL !== $name) { [$localName, $namespaceURI, $ignoreNamespace] = $this->prepareCondition($name, $namespaceURI); while (parent::read()) { @@ -141,7 +141,7 @@ public function expand($baseNode = NULL): \DOMNode|FALSE { * @param string|NULL $namespaceURI * @return array */ - private function prepareCondition(string $name, string $namespaceURI = NULL): array { + private function prepareCondition(string $name, ?string $namespaceURI = NULL): array { if (NULL !== $namespaceURI) { $localName = $name; $ignoreNamespace = FALSE; @@ -160,7 +160,7 @@ private function prepareCondition(string $name, string $namespaceURI = NULL): ar * @return bool * @throws InvalidArgumentType */ - public function attachStream($stream, string $encoding = NULL, int $options = 0): bool { + public function attachStream($stream, ?string $encoding = NULL, int $options = 0): bool { if (!\is_resource($stream)) { throw new InvalidArgument('stream', 'resource'); } diff --git a/src/FluentDOM/XMLReader/Iterator.php b/src/FluentDOM/XMLReader/Iterator.php index e4123bfa..3434d28b 100644 --- a/src/FluentDOM/XMLReader/Iterator.php +++ b/src/FluentDOM/XMLReader/Iterator.php @@ -40,7 +40,7 @@ class Iterator implements \Iterator { * Iterator constructor. */ public function __construct( - XMLReader $reader, string $name = NULL, callable $filter = NULL + XMLReader $reader, ?string $name = NULL, ?callable $filter = NULL ) { $this->_reader = $reader; $this->_name = $name; @@ -77,7 +77,7 @@ public function next(): void { * @return bool */ protected function move( - XMLReader $reader, string $name = NULL, callable $filter = NULL + XMLReader $reader, ?string $name = NULL, ?callable $filter = NULL ): bool { while ($reader->read($name, NULL, $filter)) { if ($reader->nodeType !== \XMLReader::END_ELEMENT) { diff --git a/src/FluentDOM/XMLReader/SiblingIterator.php b/src/FluentDOM/XMLReader/SiblingIterator.php index f97eab05..8058377e 100644 --- a/src/FluentDOM/XMLReader/SiblingIterator.php +++ b/src/FluentDOM/XMLReader/SiblingIterator.php @@ -24,7 +24,7 @@ class SiblingIterator extends Iterator { protected function move( - XMLReader $reader, string $name = NULL, callable $filter = NULL + XMLReader $reader, ?string $name = NULL, ?callable $filter = NULL ): bool { return ($this->key() < 0) ? $reader->read($name, NULL, $filter) diff --git a/src/FluentDOM/XMLWriter.php b/src/FluentDOM/XMLWriter.php index 429d0a56..8a069abc 100644 --- a/src/FluentDOM/XMLWriter.php +++ b/src/FluentDOM/XMLWriter.php @@ -54,7 +54,7 @@ public function startElement(string $name): bool { return $this->startElementNS((string)$prefix, $localName, $namespaceURI); } - public function writeElement(string $name, string $content = NULL): bool { + public function writeElement(string $name, ?string $content = NULL): bool { list($prefix, $localName) = QualifiedName::split($name); $namespaceURI = $this->_namespaces->resolveNamespace((string)$prefix); return $this->writeElementNS((string)$prefix, $localName, $namespaceURI, $content); @@ -72,7 +72,7 @@ public function startElementNS(?string $prefix, string $name, ?string $namespace } public function writeElementNS( - ?string $prefix, string $name, ?string $namespace, string $content = NULL + ?string $prefix, string $name, ?string $namespace, ?string $content = NULL ): bool { if ($this->_xmlnsStack->isDefined($prefix, $namespace)) { return parent::writeElement(empty($prefix) ? $name : $prefix.':'.$name, $content); diff --git a/src/FluentDOM/XMLWriter/NamespaceDefinition.php b/src/FluentDOM/XMLWriter/NamespaceDefinition.php index b420785c..3f532333 100644 --- a/src/FluentDOM/XMLWriter/NamespaceDefinition.php +++ b/src/FluentDOM/XMLWriter/NamespaceDefinition.php @@ -20,7 +20,7 @@ class NamespaceDefinition implements \IteratorAggregate, NamespaceResolver { private int $_indent; private Namespaces $_namespaces; - public function __construct(iterable $inherit = NULL) { + public function __construct(?iterable $inherit = NULL) { $this->_indent = 0; $this->_namespaces = new Namespaces($inherit); } diff --git a/tests/FluentDOM/NodesTest.php b/tests/FluentDOM/NodesTest.php index 07e77a5e..225ef6ef 100644 --- a/tests/FluentDOM/NodesTest.php +++ b/tests/FluentDOM/NodesTest.php @@ -20,7 +20,7 @@ require_once __DIR__.'/TestCase.php'; class Nodes_TestProxy extends Nodes { - public function matches(string $selector, \DOMNode $context = NULL): bool { + public function matches(string $selector, ?\DOMNode $context = NULL): bool { return parent::matches($selector, $context); } } @@ -1170,7 +1170,7 @@ public function testGetSerializerFactoriesInitializesFromStaticClass(): void { * @param \DOMNode|NULL $selection * @return LoaderResult|MockObject */ - public function createLoaderResultMock(Document $document, \DOMNode $selection = NULL): LoaderResult|MockObject { + public function createLoaderResultMock(Document $document, ?\DOMNode $selection = NULL): LoaderResult|MockObject { $result = $this ->getMockBuilder(Loader\LoaderResult::class) ->disableOriginalConstructor()