Skip to content

Commit a9cee6e

Browse files
authored
nit
1 parent 58c967a commit a9cee6e

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

src/Dom/Selector/CssSelector.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,31 @@
1010
final class CssSelector implements Selector
1111
{
1212
/** @var string */
13-
private $expression;
13+
private $expressionEncoded;
1414

1515
public function __construct(string $expression)
1616
{
17-
$this->expression = $expression;
18-
}
19-
20-
public function expressionCount(): string
21-
{
22-
$encodedExpr = \json_encode(
23-
$this->expression,
17+
$this->expressionEncoded = \json_encode(
18+
$expression,
2419
\JSON_UNESCAPED_SLASHES
2520
| \JSON_UNESCAPED_UNICODE
2621
| \JSON_THROW_ON_ERROR
2722
);
23+
}
2824

25+
public function expressionCount(): string
26+
{
2927
return \sprintf(
3028
'document.querySelectorAll(%s).length',
31-
$encodedExpr
29+
$this->expressionEncoded
3230
);
3331
}
3432

3533
public function expressionFindOne(int $position): string
3634
{
37-
$encodedExpr = \json_encode(
38-
$this->expression,
39-
\JSON_UNESCAPED_SLASHES
40-
| \JSON_UNESCAPED_UNICODE
41-
| \JSON_THROW_ON_ERROR
42-
);
43-
4435
return \sprintf(
4536
'document.querySelectorAll(%s)[%d]',
46-
$encodedExpr,
37+
$this->expressionEncoded,
4738
$position - 1
4839
);
4940
}

0 commit comments

Comments
 (0)