Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/FluentDOM.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/FluentDOM/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/FluentDOM/Creator/Nodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
28 changes: 14 additions & 14 deletions src/FluentDOM/DOM/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 = '';
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -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 */
Expand All @@ -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));
}
Expand All @@ -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) {
Expand All @@ -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);
}
/**
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/FluentDOM/DOM/DocumentFragment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/FluentDOM/DOM/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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];
}
Expand Down
6 changes: 3 additions & 3 deletions src/FluentDOM/DOM/Implementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/FluentDOM/DOM/Node/ParentNode/Implementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/FluentDOM/DOM/Node/WholeText.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
!(
Expand Down
2 changes: 1 addition & 1 deletion src/FluentDOM/DOM/Node/Xpath.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/FluentDOM/DOM/Xpath.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/FluentDOM/Loader/HtmlLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/FluentDOM/Loader/Json/JsonDOMLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/FluentDOM/Loader/LoaderResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/FluentDOM/Loader/Text/CSVLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/FluentDOM/Loader/XDM/JsonAsXDMLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/FluentDOM/Loaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading