package and depencies

This commit is contained in:
RafficMohammed
2023-01-08 02:57:24 +05:30
parent d5332eb421
commit 1d54b8bc7f
4309 changed files with 193331 additions and 172289 deletions

View File

@@ -26,11 +26,11 @@ use Symfony\Component\CssSelector\XPath\Translator;
*/
class CssSelectorConverter
{
private $translator;
private $cache;
private Translator $translator;
private array $cache;
private static $xmlCache = [];
private static $htmlCache = [];
private static array $xmlCache = [];
private static array $htmlCache = [];
/**
* @param bool $html Whether HTML support should be enabled. Disable it for XML documents
@@ -59,11 +59,9 @@ class CssSelectorConverter
*
* Optionally, a prefix can be added to the resulting XPath
* expression with the $prefix parameter.
*
* @return string
*/
public function toXPath(string $cssExpr, string $prefix = 'descendant-or-self::')
public function toXPath(string $cssExpr, string $prefix = 'descendant-or-self::'): string
{
return $this->cache[$prefix][$cssExpr] ?? $this->cache[$prefix][$cssExpr] = $this->translator->cssToXPath($cssExpr, $prefix);
return $this->cache[$prefix][$cssExpr] ??= $this->translator->cssToXPath($cssExpr, $prefix);
}
}

View File

@@ -23,42 +23,27 @@ use Symfony\Component\CssSelector\Parser\Token;
*/
class SyntaxErrorException extends ParseException
{
/**
* @return self
*/
public static function unexpectedToken(string $expectedValue, Token $foundToken)
public static function unexpectedToken(string $expectedValue, Token $foundToken): self
{
return new self(sprintf('Expected %s, but %s found.', $expectedValue, $foundToken));
}
/**
* @return self
*/
public static function pseudoElementFound(string $pseudoElement, string $unexpectedLocation)
public static function pseudoElementFound(string $pseudoElement, string $unexpectedLocation): self
{
return new self(sprintf('Unexpected pseudo-element "::%s" found %s.', $pseudoElement, $unexpectedLocation));
}
/**
* @return self
*/
public static function unclosedString(int $position)
public static function unclosedString(int $position): self
{
return new self(sprintf('Unclosed/invalid string at %s.', $position));
}
/**
* @return self
*/
public static function nestedNot()
public static function nestedNot(): self
{
return new self('Got nested ::not().');
}
/**
* @return self
*/
public static function stringAsFunctionArgument()
public static function stringAsFunctionArgument(): self
{
return new self('String not allowed as function argument.');
}

View File

@@ -23,17 +23,10 @@ namespace Symfony\Component\CssSelector\Node;
*/
abstract class AbstractNode implements NodeInterface
{
/**
* @var string
*/
private $nodeName;
private string $nodeName;
public function getNodeName(): string
{
if (null === $this->nodeName) {
$this->nodeName = preg_replace('~.*\\\\([^\\\\]+)Node$~', '$1', static::class);
}
return $this->nodeName;
return $this->nodeName ??= preg_replace('~.*\\\\([^\\\\]+)Node$~', '$1', static::class);
}
}

View File

@@ -23,11 +23,11 @@ namespace Symfony\Component\CssSelector\Node;
*/
class AttributeNode extends AbstractNode
{
private $selector;
private $namespace;
private $attribute;
private $operator;
private $value;
private NodeInterface $selector;
private ?string $namespace;
private string $attribute;
private string $operator;
private ?string $value;
public function __construct(NodeInterface $selector, ?string $namespace, string $attribute, string $operator, ?string $value)
{
@@ -63,9 +63,6 @@ class AttributeNode extends AbstractNode
return $this->value;
}
/**
* {@inheritdoc}
*/
public function getSpecificity(): Specificity
{
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));

View File

@@ -23,8 +23,8 @@ namespace Symfony\Component\CssSelector\Node;
*/
class ClassNode extends AbstractNode
{
private $selector;
private $name;
private NodeInterface $selector;
private string $name;
public function __construct(NodeInterface $selector, string $name)
{
@@ -42,9 +42,6 @@ class ClassNode extends AbstractNode
return $this->name;
}
/**
* {@inheritdoc}
*/
public function getSpecificity(): Specificity
{
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));

View File

@@ -23,9 +23,9 @@ namespace Symfony\Component\CssSelector\Node;
*/
class CombinedSelectorNode extends AbstractNode
{
private $selector;
private $combinator;
private $subSelector;
private NodeInterface $selector;
private string $combinator;
private NodeInterface $subSelector;
public function __construct(NodeInterface $selector, string $combinator, NodeInterface $subSelector)
{
@@ -49,9 +49,6 @@ class CombinedSelectorNode extends AbstractNode
return $this->subSelector;
}
/**
* {@inheritdoc}
*/
public function getSpecificity(): Specificity
{
return $this->selector->getSpecificity()->plus($this->subSelector->getSpecificity());

View File

@@ -23,8 +23,8 @@ namespace Symfony\Component\CssSelector\Node;
*/
class ElementNode extends AbstractNode
{
private $namespace;
private $element;
private ?string $namespace;
private ?string $element;
public function __construct(string $namespace = null, string $element = null)
{
@@ -42,9 +42,6 @@ class ElementNode extends AbstractNode
return $this->element;
}
/**
* {@inheritdoc}
*/
public function getSpecificity(): Specificity
{
return new Specificity(0, 0, $this->element ? 1 : 0);

View File

@@ -25,9 +25,9 @@ use Symfony\Component\CssSelector\Parser\Token;
*/
class FunctionNode extends AbstractNode
{
private $selector;
private $name;
private $arguments;
private NodeInterface $selector;
private string $name;
private array $arguments;
/**
* @param Token[] $arguments
@@ -57,9 +57,6 @@ class FunctionNode extends AbstractNode
return $this->arguments;
}
/**
* {@inheritdoc}
*/
public function getSpecificity(): Specificity
{
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));

View File

@@ -23,8 +23,8 @@ namespace Symfony\Component\CssSelector\Node;
*/
class HashNode extends AbstractNode
{
private $selector;
private $id;
private NodeInterface $selector;
private string $id;
public function __construct(NodeInterface $selector, string $id)
{
@@ -42,9 +42,6 @@ class HashNode extends AbstractNode
return $this->id;
}
/**
* {@inheritdoc}
*/
public function getSpecificity(): Specificity
{
return $this->selector->getSpecificity()->plus(new Specificity(1, 0, 0));

View File

@@ -23,8 +23,8 @@ namespace Symfony\Component\CssSelector\Node;
*/
class NegationNode extends AbstractNode
{
private $selector;
private $subSelector;
private NodeInterface $selector;
private NodeInterface $subSelector;
public function __construct(NodeInterface $selector, NodeInterface $subSelector)
{
@@ -42,9 +42,6 @@ class NegationNode extends AbstractNode
return $this->subSelector;
}
/**
* {@inheritdoc}
*/
public function getSpecificity(): Specificity
{
return $this->selector->getSpecificity()->plus($this->subSelector->getSpecificity());

View File

@@ -23,8 +23,8 @@ namespace Symfony\Component\CssSelector\Node;
*/
class PseudoNode extends AbstractNode
{
private $selector;
private $identifier;
private NodeInterface $selector;
private string $identifier;
public function __construct(NodeInterface $selector, string $identifier)
{
@@ -42,9 +42,6 @@ class PseudoNode extends AbstractNode
return $this->identifier;
}
/**
* {@inheritdoc}
*/
public function getSpecificity(): Specificity
{
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));

View File

@@ -23,8 +23,8 @@ namespace Symfony\Component\CssSelector\Node;
*/
class SelectorNode extends AbstractNode
{
private $tree;
private $pseudoElement;
private NodeInterface $tree;
private ?string $pseudoElement;
public function __construct(NodeInterface $tree, string $pseudoElement = null)
{
@@ -42,9 +42,6 @@ class SelectorNode extends AbstractNode
return $this->pseudoElement;
}
/**
* {@inheritdoc}
*/
public function getSpecificity(): Specificity
{
return $this->tree->getSpecificity()->plus(new Specificity(0, 0, $this->pseudoElement ? 1 : 0));

View File

@@ -29,9 +29,9 @@ class Specificity
public const B_FACTOR = 10;
public const C_FACTOR = 1;
private $a;
private $b;
private $c;
private int $a;
private int $b;
private int $c;
public function __construct(int $a, int $b, int $c)
{

View File

@@ -26,9 +26,6 @@ use Symfony\Component\CssSelector\Parser\TokenStream;
*/
class CommentHandler implements HandlerInterface
{
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream): bool
{
if ('/*' !== $reader->getSubstring(2)) {

View File

@@ -29,8 +29,8 @@ use Symfony\Component\CssSelector\Parser\TokenStream;
*/
class HashHandler implements HandlerInterface
{
private $patterns;
private $escaping;
private TokenizerPatterns $patterns;
private TokenizerEscaping $escaping;
public function __construct(TokenizerPatterns $patterns, TokenizerEscaping $escaping)
{
@@ -38,9 +38,6 @@ class HashHandler implements HandlerInterface
$this->escaping = $escaping;
}
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream): bool
{
$match = $reader->findPattern($this->patterns->getHashPattern());

View File

@@ -29,8 +29,8 @@ use Symfony\Component\CssSelector\Parser\TokenStream;
*/
class IdentifierHandler implements HandlerInterface
{
private $patterns;
private $escaping;
private TokenizerPatterns $patterns;
private TokenizerEscaping $escaping;
public function __construct(TokenizerPatterns $patterns, TokenizerEscaping $escaping)
{
@@ -38,9 +38,6 @@ class IdentifierHandler implements HandlerInterface
$this->escaping = $escaping;
}
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream): bool
{
$match = $reader->findPattern($this->patterns->getIdentifierPattern());

View File

@@ -28,16 +28,13 @@ use Symfony\Component\CssSelector\Parser\TokenStream;
*/
class NumberHandler implements HandlerInterface
{
private $patterns;
private TokenizerPatterns $patterns;
public function __construct(TokenizerPatterns $patterns)
{
$this->patterns = $patterns;
}
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream): bool
{
$match = $reader->findPattern($this->patterns->getNumberPattern());

View File

@@ -31,8 +31,8 @@ use Symfony\Component\CssSelector\Parser\TokenStream;
*/
class StringHandler implements HandlerInterface
{
private $patterns;
private $escaping;
private TokenizerPatterns $patterns;
private TokenizerEscaping $escaping;
public function __construct(TokenizerPatterns $patterns, TokenizerEscaping $escaping)
{
@@ -40,9 +40,6 @@ class StringHandler implements HandlerInterface
$this->escaping = $escaping;
}
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream): bool
{
$quote = $reader->getSubstring(1);

View File

@@ -27,9 +27,6 @@ use Symfony\Component\CssSelector\Parser\TokenStream;
*/
class WhitespaceHandler implements HandlerInterface
{
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream): bool
{
$match = $reader->findPattern('~^[ \t\r\n\f]+~');

View File

@@ -27,16 +27,13 @@ use Symfony\Component\CssSelector\Parser\Tokenizer\Tokenizer;
*/
class Parser implements ParserInterface
{
private $tokenizer;
private Tokenizer $tokenizer;
public function __construct(Tokenizer $tokenizer = null)
{
$this->tokenizer = $tokenizer ?? new Tokenizer();
}
/**
* {@inheritdoc}
*/
public function parse(string $source): array
{
$reader = new Reader($source);
@@ -242,7 +239,7 @@ class Parser implements ParserInterface
}
}
if (empty($arguments)) {
if (!$arguments) {
throw SyntaxErrorException::unexpectedToken('at least one argument', $next);
}

View File

@@ -23,9 +23,9 @@ namespace Symfony\Component\CssSelector\Parser;
*/
class Reader
{
private $source;
private $length;
private $position = 0;
private string $source;
private int $length;
private int $position = 0;
public function __construct(string $source)
{
@@ -60,10 +60,7 @@ class Reader
return false === $position ? false : $position - $this->position;
}
/**
* @return array|false
*/
public function findPattern(string $pattern)
public function findPattern(string $pattern): array|false
{
$source = substr($this->source, $this->position);

View File

@@ -28,9 +28,6 @@ use Symfony\Component\CssSelector\Parser\ParserInterface;
*/
class ClassParser implements ParserInterface
{
/**
* {@inheritdoc}
*/
public function parse(string $source): array
{
// Matches an optional namespace, optional element, and required class

View File

@@ -27,9 +27,6 @@ use Symfony\Component\CssSelector\Parser\ParserInterface;
*/
class ElementParser implements ParserInterface
{
/**
* {@inheritdoc}
*/
public function parse(string $source): array
{
// Matches an optional namespace, required element or `*`

View File

@@ -31,9 +31,6 @@ use Symfony\Component\CssSelector\Parser\ParserInterface;
*/
class EmptyStringParser implements ParserInterface
{
/**
* {@inheritdoc}
*/
public function parse(string $source): array
{
// Matches an empty string

View File

@@ -28,9 +28,6 @@ use Symfony\Component\CssSelector\Parser\ParserInterface;
*/
class HashParser implements ParserInterface
{
/**
* {@inheritdoc}
*/
public function parse(string $source): array
{
// Matches an optional namespace, optional element, and required id

View File

@@ -31,9 +31,9 @@ class Token
public const TYPE_NUMBER = 'number';
public const TYPE_STRING = 'string';
private $type;
private $value;
private $position;
private ?string $type;
private ?string $value;
private ?int $position;
public function __construct(?string $type, ?string $value, ?int $position)
{
@@ -68,7 +68,7 @@ class Token
return false;
}
if (empty($values)) {
if (!$values) {
return true;
}

View File

@@ -29,34 +29,23 @@ class TokenStream
/**
* @var Token[]
*/
private $tokens = [];
private array $tokens = [];
/**
* @var Token[]
*/
private $used = [];
private array $used = [];
/**
* @var int
*/
private $cursor = 0;
/**
* @var Token|null
*/
private $peeked;
/**
* @var bool
*/
private $peeking = false;
private int $cursor = 0;
private ?Token $peeked;
private bool $peeking = false;
/**
* Pushes a token.
*
* @return $this
*/
public function push(Token $token): self
public function push(Token $token): static
{
$this->tokens[] = $token;
@@ -68,7 +57,7 @@ class TokenStream
*
* @return $this
*/
public function freeze(): self
public function freeze(): static
{
return $this;
}

View File

@@ -31,7 +31,7 @@ class Tokenizer
/**
* @var Handler\HandlerInterface[]
*/
private $handlers;
private array $handlers;
public function __construct()
{

View File

@@ -23,7 +23,7 @@ namespace Symfony\Component\CssSelector\Parser\Tokenizer;
*/
class TokenizerEscaping
{
private $patterns;
private TokenizerPatterns $patterns;
public function __construct(TokenizerPatterns $patterns)
{

View File

@@ -23,18 +23,18 @@ namespace Symfony\Component\CssSelector\Parser\Tokenizer;
*/
class TokenizerPatterns
{
private $unicodeEscapePattern;
private $simpleEscapePattern;
private $newLineEscapePattern;
private $escapePattern;
private $stringEscapePattern;
private $nonAsciiPattern;
private $nmCharPattern;
private $nmStartPattern;
private $identifierPattern;
private $hashPattern;
private $numberPattern;
private $quotedStringPattern;
private string $unicodeEscapePattern;
private string $simpleEscapePattern;
private string $newLineEscapePattern;
private string $escapePattern;
private string $stringEscapePattern;
private string $nonAsciiPattern;
private string $nmCharPattern;
private string $nmStartPattern;
private string $identifierPattern;
private string $hashPattern;
private string $numberPattern;
private string $quotedStringPattern;
public function __construct()
{

View File

@@ -23,41 +23,26 @@ namespace Symfony\Component\CssSelector\XPath\Extension;
*/
abstract class AbstractExtension implements ExtensionInterface
{
/**
* {@inheritdoc}
*/
public function getNodeTranslators(): array
{
return [];
}
/**
* {@inheritdoc}
*/
public function getCombinationTranslators(): array
{
return [];
}
/**
* {@inheritdoc}
*/
public function getFunctionTranslators(): array
{
return [];
}
/**
* {@inheritdoc}
*/
public function getPseudoClassTranslators(): array
{
return [];
}
/**
* {@inheritdoc}
*/
public function getAttributeMatchingTranslators(): array
{
return [];

View File

@@ -26,20 +26,17 @@ use Symfony\Component\CssSelector\XPath\XPathExpr;
*/
class AttributeMatchingExtension extends AbstractExtension
{
/**
* {@inheritdoc}
*/
public function getAttributeMatchingTranslators(): array
{
return [
'exists' => [$this, 'translateExists'],
'=' => [$this, 'translateEquals'],
'~=' => [$this, 'translateIncludes'],
'|=' => [$this, 'translateDashMatch'],
'^=' => [$this, 'translatePrefixMatch'],
'$=' => [$this, 'translateSuffixMatch'],
'*=' => [$this, 'translateSubstringMatch'],
'!=' => [$this, 'translateDifferent'],
'exists' => $this->translateExists(...),
'=' => $this->translateEquals(...),
'~=' => $this->translateIncludes(...),
'|=' => $this->translateDashMatch(...),
'^=' => $this->translatePrefixMatch(...),
'$=' => $this->translateSuffixMatch(...),
'*=' => $this->translateSubstringMatch(...),
'!=' => $this->translateDifferent(...),
];
}
@@ -109,9 +106,6 @@ class AttributeMatchingExtension extends AbstractExtension
));
}
/**
* {@inheritdoc}
*/
public function getName(): string
{
return 'attribute-matching';

View File

@@ -25,16 +25,13 @@ use Symfony\Component\CssSelector\XPath\XPathExpr;
*/
class CombinationExtension extends AbstractExtension
{
/**
* {@inheritdoc}
*/
public function getCombinationTranslators(): array
{
return [
' ' => [$this, 'translateDescendant'],
'>' => [$this, 'translateChild'],
'+' => [$this, 'translateDirectAdjacent'],
'~' => [$this, 'translateIndirectAdjacent'],
' ' => $this->translateDescendant(...),
'>' => $this->translateChild(...),
'+' => $this->translateDirectAdjacent(...),
'~' => $this->translateIndirectAdjacent(...),
];
}
@@ -61,9 +58,6 @@ class CombinationExtension extends AbstractExtension
return $xpath->join('/following-sibling::', $combinedXpath);
}
/**
* {@inheritdoc}
*/
public function getName(): string
{
return 'combination';

View File

@@ -30,18 +30,15 @@ use Symfony\Component\CssSelector\XPath\XPathExpr;
*/
class FunctionExtension extends AbstractExtension
{
/**
* {@inheritdoc}
*/
public function getFunctionTranslators(): array
{
return [
'nth-child' => [$this, 'translateNthChild'],
'nth-last-child' => [$this, 'translateNthLastChild'],
'nth-of-type' => [$this, 'translateNthOfType'],
'nth-last-of-type' => [$this, 'translateNthLastOfType'],
'contains' => [$this, 'translateContains'],
'lang' => [$this, 'translateLang'],
'nth-child' => $this->translateNthChild(...),
'nth-last-child' => $this->translateNthLastChild(...),
'nth-of-type' => $this->translateNthOfType(...),
'nth-last-of-type' => $this->translateNthLastOfType(...),
'contains' => $this->translateContains(...),
'lang' => $this->translateLang(...),
];
}
@@ -161,9 +158,6 @@ class FunctionExtension extends AbstractExtension
));
}
/**
* {@inheritdoc}
*/
public function getName(): string
{
return 'function';

View File

@@ -36,30 +36,24 @@ class HtmlExtension extends AbstractExtension
->setFlag(NodeExtension::ATTRIBUTE_NAME_IN_LOWER_CASE, true);
}
/**
* {@inheritdoc}
*/
public function getPseudoClassTranslators(): array
{
return [
'checked' => [$this, 'translateChecked'],
'link' => [$this, 'translateLink'],
'disabled' => [$this, 'translateDisabled'],
'enabled' => [$this, 'translateEnabled'],
'selected' => [$this, 'translateSelected'],
'invalid' => [$this, 'translateInvalid'],
'hover' => [$this, 'translateHover'],
'visited' => [$this, 'translateVisited'],
'checked' => $this->translateChecked(...),
'link' => $this->translateLink(...),
'disabled' => $this->translateDisabled(...),
'enabled' => $this->translateEnabled(...),
'selected' => $this->translateSelected(...),
'invalid' => $this->translateInvalid(...),
'hover' => $this->translateHover(...),
'visited' => $this->translateVisited(...),
];
}
/**
* {@inheritdoc}
*/
public function getFunctionTranslators(): array
{
return [
'lang' => [$this, 'translateLang'],
'lang' => $this->translateLang(...),
];
}
@@ -177,9 +171,6 @@ class HtmlExtension extends AbstractExtension
return $xpath->addCondition('0');
}
/**
* {@inheritdoc}
*/
public function getName(): string
{
return 'html';

View File

@@ -31,7 +31,7 @@ class NodeExtension extends AbstractExtension
public const ATTRIBUTE_NAME_IN_LOWER_CASE = 2;
public const ATTRIBUTE_VALUE_IN_LOWER_CASE = 4;
private $flags;
private int $flags;
public function __construct(int $flags = 0)
{
@@ -41,7 +41,7 @@ class NodeExtension extends AbstractExtension
/**
* @return $this
*/
public function setFlag(int $flag, bool $on): self
public function setFlag(int $flag, bool $on): static
{
if ($on && !$this->hasFlag($flag)) {
$this->flags += $flag;
@@ -59,21 +59,18 @@ class NodeExtension extends AbstractExtension
return (bool) ($this->flags & $flag);
}
/**
* {@inheritdoc}
*/
public function getNodeTranslators(): array
{
return [
'Selector' => [$this, 'translateSelector'],
'CombinedSelector' => [$this, 'translateCombinedSelector'],
'Negation' => [$this, 'translateNegation'],
'Function' => [$this, 'translateFunction'],
'Pseudo' => [$this, 'translatePseudo'],
'Attribute' => [$this, 'translateAttribute'],
'Class' => [$this, 'translateClass'],
'Hash' => [$this, 'translateHash'],
'Element' => [$this, 'translateElement'],
'Selector' => $this->translateSelector(...),
'CombinedSelector' => $this->translateCombinedSelector(...),
'Negation' => $this->translateNegation(...),
'Function' => $this->translateFunction(...),
'Pseudo' => $this->translatePseudo(...),
'Attribute' => $this->translateAttribute(...),
'Class' => $this->translateClass(...),
'Hash' => $this->translateHash(...),
'Element' => $this->translateElement(...),
];
}
@@ -182,9 +179,6 @@ class NodeExtension extends AbstractExtension
return $xpath;
}
/**
* {@inheritdoc}
*/
public function getName(): string
{
return 'node';

View File

@@ -26,20 +26,17 @@ use Symfony\Component\CssSelector\XPath\XPathExpr;
*/
class PseudoClassExtension extends AbstractExtension
{
/**
* {@inheritdoc}
*/
public function getPseudoClassTranslators(): array
{
return [
'root' => [$this, 'translateRoot'],
'first-child' => [$this, 'translateFirstChild'],
'last-child' => [$this, 'translateLastChild'],
'first-of-type' => [$this, 'translateFirstOfType'],
'last-of-type' => [$this, 'translateLastOfType'],
'only-child' => [$this, 'translateOnlyChild'],
'only-of-type' => [$this, 'translateOnlyOfType'],
'empty' => [$this, 'translateEmpty'],
'root' => $this->translateRoot(...),
'first-child' => $this->translateFirstChild(...),
'last-child' => $this->translateLastChild(...),
'first-of-type' => $this->translateFirstOfType(...),
'last-of-type' => $this->translateLastOfType(...),
'only-child' => $this->translateOnlyChild(...),
'only-of-type' => $this->translateOnlyOfType(...),
'empty' => $this->translateEmpty(...),
];
}
@@ -112,9 +109,6 @@ class PseudoClassExtension extends AbstractExtension
return $xpath->addCondition('not(*) and not(string-length())');
}
/**
* {@inheritdoc}
*/
public function getName(): string
{
return 'pseudo-class';

View File

@@ -30,23 +30,23 @@ use Symfony\Component\CssSelector\Parser\ParserInterface;
*/
class Translator implements TranslatorInterface
{
private $mainParser;
private ParserInterface $mainParser;
/**
* @var ParserInterface[]
*/
private $shortcutParsers = [];
private array $shortcutParsers = [];
/**
* @var Extension\ExtensionInterface[]
*/
private $extensions = [];
private array $extensions = [];
private $nodeTranslators = [];
private $combinationTranslators = [];
private $functionTranslators = [];
private $pseudoClassTranslators = [];
private $attributeMatchingTranslators = [];
private array $nodeTranslators = [];
private array $combinationTranslators = [];
private array $functionTranslators = [];
private array $pseudoClassTranslators = [];
private array $attributeMatchingTranslators = [];
public function __construct(ParserInterface $parser = null)
{
@@ -87,9 +87,6 @@ class Translator implements TranslatorInterface
return sprintf('concat(%s)', implode(', ', $parts));
}
/**
* {@inheritdoc}
*/
public function cssToXPath(string $cssExpr, string $prefix = 'descendant-or-self::'): string
{
$selectors = $this->parseSelectors($cssExpr);
@@ -106,9 +103,6 @@ class Translator implements TranslatorInterface
return implode(' | ', $selectors);
}
/**
* {@inheritdoc}
*/
public function selectorToXPath(SelectorNode $selector, string $prefix = 'descendant-or-self::'): string
{
return ($prefix ?: '').$this->nodeToXPath($selector);
@@ -117,7 +111,7 @@ class Translator implements TranslatorInterface
/**
* @return $this
*/
public function registerExtension(Extension\ExtensionInterface $extension): self
public function registerExtension(Extension\ExtensionInterface $extension): static
{
$this->extensions[$extension->getName()] = $extension;
@@ -145,7 +139,7 @@ class Translator implements TranslatorInterface
/**
* @return $this
*/
public function registerParserShortcut(ParserInterface $shortcut): self
public function registerParserShortcut(ParserInterface $shortcut): static
{
$this->shortcutParsers[] = $shortcut;
@@ -220,7 +214,7 @@ class Translator implements TranslatorInterface
foreach ($this->shortcutParsers as $shortcut) {
$tokens = $shortcut->parse($css);
if (!empty($tokens)) {
if ($tokens) {
return $tokens;
}
}

View File

@@ -23,9 +23,9 @@ namespace Symfony\Component\CssSelector\XPath;
*/
class XPathExpr
{
private $path;
private $element;
private $condition;
private string $path;
private string $element;
private string $condition;
public function __construct(string $path = '', string $element = '*', string $condition = '', bool $starPrefix = false)
{
@@ -46,7 +46,7 @@ class XPathExpr
/**
* @return $this
*/
public function addCondition(string $condition): self
public function addCondition(string $condition): static
{
$this->condition = $this->condition ? sprintf('(%s) and (%s)', $this->condition, $condition) : $condition;
@@ -61,7 +61,7 @@ class XPathExpr
/**
* @return $this
*/
public function addNameTest(): self
public function addNameTest(): static
{
if ('*' !== $this->element) {
$this->addCondition('name() = '.Translator::getXpathLiteral($this->element));
@@ -74,7 +74,7 @@ class XPathExpr
/**
* @return $this
*/
public function addStarPrefix(): self
public function addStarPrefix(): static
{
$this->path .= '*/';
@@ -86,7 +86,7 @@ class XPathExpr
*
* @return $this
*/
public function join(string $combiner, self $expr): self
public function join(string $combiner, self $expr): static
{
$path = $this->__toString().$combiner;

View File

@@ -20,8 +20,7 @@
}
],
"require": {
"php": ">=7.2.5",
"symfony/polyfill-php80": "^1.16"
"php": ">=8.1"
},
"autoload": {
"psr-4": { "Symfony\\Component\\CssSelector\\": "" },