Skip to content

Commit

Permalink
[REFACTOR] PHP 8 Syntax, Add Types
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWeinert committed Oct 16, 2023
1 parent d51617a commit f30a1f7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 38 deletions.
14 changes: 3 additions & 11 deletions src/FluentDOM/DOM/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,14 @@ class Document extends \DOMDocument implements Node\ParentNode {
Node\QuerySelector\Implementation,
Node\Xpath;

/**
* @var Xpath
*/
private $_xpath;
private ?Xpath $_xpath = NULL;

/**
* @var Namespaces
*/
private $_namespaces;
private ?Namespaces $_namespaces;

/**
* Map dom node classes to extended descendants.
*
* @var array
*/
private static $_classes = [
private static array $_classes = [
'DOMDocument' => self::class,
'DOMAttr' => Attribute::class,
'DOMCdataSection' => CdataSection::class,
Expand Down
17 changes: 5 additions & 12 deletions src/FluentDOM/DOM/Xpath.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,19 @@ public function __construct(\DOMDocument $document) {
* If the owner document is a FluentDOM\DOM\Document register the namespace on the
* document object, too.
*
* @param string $prefix
* @param string $namespaceURI
* @return bool
* @throws \LogicException
*/
public function registerNamespace($prefix, $namespaceURI): bool {
public function registerNamespace(string $prefix, string $namespace): bool {
if (
$this->_documentReference instanceOf Document &&
(
!$this->_documentReference->namespaces()->offsetExists($prefix) ||
$this->_documentReference->namespaces()->offsetGet($prefix) !== $namespaceURI
$this->_documentReference->namespaces()->offsetGet($prefix) !== $namespace
)
) {
$this->_documentReference->registerNamespace($prefix, $namespaceURI);
$this->_documentReference->registerNamespace($prefix, $namespace);
}
return parent::registerNamespace($prefix, $namespaceURI);
return parent::registerNamespace($prefix, $namespace);
}

/**
Expand Down Expand Up @@ -94,13 +91,9 @@ public function __invoke(
* calls evaluate().
*
* @deprecated
* @param string $expression
* @param \DOMNode|NULL $contextNode
* @param NULL|bool $registerNodeNS
* @return \DOMNodeList|NULL
*/
public function query(
$expression, \DOMNode $contextNode = NULL, $registerNodeNS = NULL
string $expression, \DOMNode $contextNode = NULL, bool $registerNodeNS = NULL
): ?\DOMNodeList {
$result = $this->evaluate($expression, $contextNode, $registerNodeNS);
return $result instanceof \DOMNodeList ? $result : NULL;
Expand Down
11 changes: 1 addition & 10 deletions src/FluentDOM/Nodes/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,12 @@
*/
class Builder {

/**
* @var Nodes
*/
private $_nodes;
private Nodes $_nodes;

/**
* @param Nodes $nodes
*/
public function __construct(Nodes $nodes) {
$this->_nodes = $nodes;
}

/**
* @return Nodes
*/
public function getOwner(): Nodes {
return $this->_nodes;
}
Expand Down
10 changes: 5 additions & 5 deletions src/FluentDOM/Nodes/Compare.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/**
/*
* FluentDOM
*
* @link https://thomas.weinert.info/FluentDOM/
* @copyright Copyright 2009-2019 FluentDOM Contributors
* @copyright Copyright 2009-2023 FluentDOM Contributors
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*
*/
Expand All @@ -16,9 +16,9 @@
*/
class Compare {

private $_xpath ;
private $_document;
private $_cache = [];
private \DOMXPath $_xpath ;
private \DOMDocument $_document;
private array $_cache = [];

public function __construct(\DOMXPath $xpath) {
$this->_xpath = $xpath;
Expand Down

0 comments on commit f30a1f7

Please sign in to comment.