Skip to content

Commit 4742e79

Browse files
committed
[CssSelector] Add types to private properties
Signed-off-by: Alexander M. Turek <[email protected]>
1 parent d8206f5 commit 4742e79

26 files changed

+77
-95
lines changed

CssSelectorConverter.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
*/
2727
class CssSelectorConverter
2828
{
29-
private $translator;
30-
private $cache;
29+
private Translator $translator;
30+
private array $cache;
3131

32-
private static $xmlCache = [];
33-
private static $htmlCache = [];
32+
private static array $xmlCache = [];
33+
private static array $htmlCache = [];
3434

3535
/**
3636
* @param bool $html Whether HTML support should be enabled. Disable it for XML documents

Node/AbstractNode.php

+2-9
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,10 @@
2323
*/
2424
abstract class AbstractNode implements NodeInterface
2525
{
26-
/**
27-
* @var string
28-
*/
29-
private $nodeName;
26+
private string $nodeName;
3027

3128
public function getNodeName(): string
3229
{
33-
if (null === $this->nodeName) {
34-
$this->nodeName = preg_replace('~.*\\\\([^\\\\]+)Node$~', '$1', static::class);
35-
}
36-
37-
return $this->nodeName;
30+
return $this->nodeName ??= preg_replace('~.*\\\\([^\\\\]+)Node$~', '$1', static::class);
3831
}
3932
}

Node/AttributeNode.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
*/
2424
class AttributeNode extends AbstractNode
2525
{
26-
private $selector;
27-
private $namespace;
28-
private $attribute;
29-
private $operator;
30-
private $value;
26+
private NodeInterface $selector;
27+
private ?string $namespace;
28+
private string $attribute;
29+
private string $operator;
30+
private ?string $value;
3131

3232
public function __construct(NodeInterface $selector, ?string $namespace, string $attribute, string $operator, ?string $value)
3333
{

Node/ClassNode.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
*/
2424
class ClassNode extends AbstractNode
2525
{
26-
private $selector;
27-
private $name;
26+
private NodeInterface $selector;
27+
private string $name;
2828

2929
public function __construct(NodeInterface $selector, string $name)
3030
{

Node/CombinedSelectorNode.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
*/
2424
class CombinedSelectorNode extends AbstractNode
2525
{
26-
private $selector;
27-
private $combinator;
28-
private $subSelector;
26+
private NodeInterface $selector;
27+
private string $combinator;
28+
private NodeInterface $subSelector;
2929

3030
public function __construct(NodeInterface $selector, string $combinator, NodeInterface $subSelector)
3131
{

Node/ElementNode.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
*/
2424
class ElementNode extends AbstractNode
2525
{
26-
private $namespace;
27-
private $element;
26+
private ?string $namespace;
27+
private ?string $element;
2828

2929
public function __construct(string $namespace = null, string $element = null)
3030
{

Node/FunctionNode.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
*/
2626
class FunctionNode extends AbstractNode
2727
{
28-
private $selector;
29-
private $name;
30-
private $arguments;
28+
private NodeInterface $selector;
29+
private string $name;
30+
private array $arguments;
3131

3232
/**
3333
* @param Token[] $arguments

Node/HashNode.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
*/
2424
class HashNode extends AbstractNode
2525
{
26-
private $selector;
27-
private $id;
26+
private NodeInterface $selector;
27+
private string $id;
2828

2929
public function __construct(NodeInterface $selector, string $id)
3030
{

Node/NegationNode.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
*/
2424
class NegationNode extends AbstractNode
2525
{
26-
private $selector;
27-
private $subSelector;
26+
private NodeInterface $selector;
27+
private NodeInterface $subSelector;
2828

2929
public function __construct(NodeInterface $selector, NodeInterface $subSelector)
3030
{

Node/PseudoNode.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
*/
2424
class PseudoNode extends AbstractNode
2525
{
26-
private $selector;
27-
private $identifier;
26+
private NodeInterface $selector;
27+
private string $identifier;
2828

2929
public function __construct(NodeInterface $selector, string $identifier)
3030
{

Node/SelectorNode.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
*/
2424
class SelectorNode extends AbstractNode
2525
{
26-
private $tree;
27-
private $pseudoElement;
26+
private NodeInterface $tree;
27+
private ?string $pseudoElement;
2828

2929
public function __construct(NodeInterface $tree, string $pseudoElement = null)
3030
{

Node/Specificity.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class Specificity
2929
public const B_FACTOR = 10;
3030
public const C_FACTOR = 1;
3131

32-
private $a;
33-
private $b;
34-
private $c;
32+
private int $a;
33+
private int $b;
34+
private int $c;
3535

3636
public function __construct(int $a, int $b, int $c)
3737
{

Parser/Handler/HashHandler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
*/
3030
class HashHandler implements HandlerInterface
3131
{
32-
private $patterns;
33-
private $escaping;
32+
private TokenizerPatterns $patterns;
33+
private TokenizerEscaping $escaping;
3434

3535
public function __construct(TokenizerPatterns $patterns, TokenizerEscaping $escaping)
3636
{

Parser/Handler/IdentifierHandler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
*/
3030
class IdentifierHandler implements HandlerInterface
3131
{
32-
private $patterns;
33-
private $escaping;
32+
private TokenizerPatterns $patterns;
33+
private TokenizerEscaping $escaping;
3434

3535
public function __construct(TokenizerPatterns $patterns, TokenizerEscaping $escaping)
3636
{

Parser/Handler/NumberHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
class NumberHandler implements HandlerInterface
3030
{
31-
private $patterns;
31+
private TokenizerPatterns $patterns;
3232

3333
public function __construct(TokenizerPatterns $patterns)
3434
{

Parser/Handler/StringHandler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
*/
3232
class StringHandler implements HandlerInterface
3333
{
34-
private $patterns;
35-
private $escaping;
34+
private TokenizerPatterns $patterns;
35+
private TokenizerEscaping $escaping;
3636

3737
public function __construct(TokenizerPatterns $patterns, TokenizerEscaping $escaping)
3838
{

Parser/Parser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828
class Parser implements ParserInterface
2929
{
30-
private $tokenizer;
30+
private Tokenizer $tokenizer;
3131

3232
public function __construct(Tokenizer $tokenizer = null)
3333
{

Parser/Reader.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
*/
2424
class Reader
2525
{
26-
private $source;
27-
private $length;
28-
private $position = 0;
26+
private string $source;
27+
private int $length;
28+
private int $position = 0;
2929

3030
public function __construct(string $source)
3131
{

Parser/Token.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class Token
3131
public const TYPE_NUMBER = 'number';
3232
public const TYPE_STRING = 'string';
3333

34-
private $type;
35-
private $value;
36-
private $position;
34+
private ?string $type;
35+
private ?string $value;
36+
private ?int $position;
3737

3838
public function __construct(?string $type, ?string $value, ?int $position)
3939
{

Parser/TokenStream.php

+5-16
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,16 @@ class TokenStream
2929
/**
3030
* @var Token[]
3131
*/
32-
private $tokens = [];
32+
private array $tokens = [];
3333

3434
/**
3535
* @var Token[]
3636
*/
37-
private $used = [];
37+
private array $used = [];
3838

39-
/**
40-
* @var int
41-
*/
42-
private $cursor = 0;
43-
44-
/**
45-
* @var Token|null
46-
*/
47-
private $peeked;
48-
49-
/**
50-
* @var bool
51-
*/
52-
private $peeking = false;
39+
private int $cursor = 0;
40+
private ?Token $peeked;
41+
private bool $peeking = false;
5342

5443
/**
5544
* Pushes a token.

Parser/Tokenizer/Tokenizer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Tokenizer
3131
/**
3232
* @var Handler\HandlerInterface[]
3333
*/
34-
private $handlers;
34+
private array $handlers;
3535

3636
public function __construct()
3737
{

Parser/Tokenizer/TokenizerEscaping.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
class TokenizerEscaping
2525
{
26-
private $patterns;
26+
private TokenizerPatterns $patterns;
2727

2828
public function __construct(TokenizerPatterns $patterns)
2929
{

Parser/Tokenizer/TokenizerPatterns.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
*/
2424
class TokenizerPatterns
2525
{
26-
private $unicodeEscapePattern;
27-
private $simpleEscapePattern;
28-
private $newLineEscapePattern;
29-
private $escapePattern;
30-
private $stringEscapePattern;
31-
private $nonAsciiPattern;
32-
private $nmCharPattern;
33-
private $nmStartPattern;
34-
private $identifierPattern;
35-
private $hashPattern;
36-
private $numberPattern;
37-
private $quotedStringPattern;
26+
private string $unicodeEscapePattern;
27+
private string $simpleEscapePattern;
28+
private string $newLineEscapePattern;
29+
private string $escapePattern;
30+
private string $stringEscapePattern;
31+
private string $nonAsciiPattern;
32+
private string $nmCharPattern;
33+
private string $nmStartPattern;
34+
private string $identifierPattern;
35+
private string $hashPattern;
36+
private string $numberPattern;
37+
private string $quotedStringPattern;
3838

3939
public function __construct()
4040
{

XPath/Extension/NodeExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class NodeExtension extends AbstractExtension
3131
public const ATTRIBUTE_NAME_IN_LOWER_CASE = 2;
3232
public const ATTRIBUTE_VALUE_IN_LOWER_CASE = 4;
3333

34-
private $flags;
34+
private int $flags;
3535

3636
public function __construct(int $flags = 0)
3737
{

XPath/Translator.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,23 @@
3030
*/
3131
class Translator implements TranslatorInterface
3232
{
33-
private $mainParser;
33+
private ParserInterface $mainParser;
3434

3535
/**
3636
* @var ParserInterface[]
3737
*/
38-
private $shortcutParsers = [];
38+
private array $shortcutParsers = [];
3939

4040
/**
4141
* @var Extension\ExtensionInterface[]
4242
*/
43-
private $extensions = [];
43+
private array $extensions = [];
4444

45-
private $nodeTranslators = [];
46-
private $combinationTranslators = [];
47-
private $functionTranslators = [];
48-
private $pseudoClassTranslators = [];
49-
private $attributeMatchingTranslators = [];
45+
private array $nodeTranslators = [];
46+
private array $combinationTranslators = [];
47+
private array $functionTranslators = [];
48+
private array $pseudoClassTranslators = [];
49+
private array $attributeMatchingTranslators = [];
5050

5151
public function __construct(ParserInterface $parser = null)
5252
{

XPath/XPathExpr.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
*/
2424
class XPathExpr
2525
{
26-
private $path;
27-
private $element;
28-
private $condition;
26+
private string $path;
27+
private string $element;
28+
private string $condition;
2929

3030
public function __construct(string $path = '', string $element = '*', string $condition = '', bool $starPrefix = false)
3131
{

0 commit comments

Comments
 (0)