Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 304cf32

Browse filesBrowse files
committed
[ExpressionLanguage] Add types to private properties
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent f821d76 commit 304cf32
Copy full SHA for 304cf32

File tree

8 files changed

+29
-40
lines changed
Filter options

8 files changed

+29
-40
lines changed

‎src/Symfony/Component/ExpressionLanguage/Compiler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/Compiler.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
*/
2121
class Compiler implements ResetInterface
2222
{
23-
private $source;
24-
private $functions;
23+
private string $source = '';
24+
private array $functions;
2525

2626
public function __construct(array $functions)
2727
{

‎src/Symfony/Component/ExpressionLanguage/ExpressionFunction.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/ExpressionFunction.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
*/
3131
class ExpressionFunction
3232
{
33-
private $name;
34-
private $compiler;
35-
private $evaluator;
33+
private string $name;
34+
private \Closure $compiler;
35+
private \Closure $evaluator;
3636

3737
/**
3838
* @param string $name The function name
@@ -42,8 +42,8 @@ class ExpressionFunction
4242
public function __construct(string $name, callable $compiler, callable $evaluator)
4343
{
4444
$this->name = $name;
45-
$this->compiler = $compiler;
46-
$this->evaluator = $evaluator;
45+
$this->compiler = $compiler instanceof \Closure ? $compiler : \Closure::fromCallable($compiler);
46+
$this->evaluator = $evaluator instanceof \Closure ? $evaluator : \Closure::fromCallable($evaluator);
4747
}
4848

4949
public function getName()

‎src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php
+9-19Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ class_exists(ParsedExpression::class);
2424
*/
2525
class ExpressionLanguage
2626
{
27-
private $cache;
28-
private $lexer;
29-
private $parser;
30-
private $compiler;
27+
private CacheItemPoolInterface $cache;
28+
private Lexer $lexer;
29+
private Parser $parser;
30+
private Compiler $compiler;
3131

32-
protected $functions = [];
32+
protected array $functions = [];
3333

3434
/**
3535
* @param ExpressionFunctionProviderInterface[] $providers
@@ -122,7 +122,7 @@ public function lint(Expression|string $expression, ?array $names): void
122122
*/
123123
public function register(string $name, callable $compiler, callable $evaluator)
124124
{
125-
if (null !== $this->parser) {
125+
if (isset($this->parser)) {
126126
throw new \LogicException('Registering functions after calling evaluate(), compile() or parse() is not supported.');
127127
}
128128

@@ -148,27 +148,17 @@ protected function registerFunctions()
148148

149149
private function getLexer(): Lexer
150150
{
151-
if (null === $this->lexer) {
152-
$this->lexer = new Lexer();
153-
}
154-
155-
return $this->lexer;
151+
return $this->lexer ??= new Lexer();
156152
}
157153

158154
private function getParser(): Parser
159155
{
160-
if (null === $this->parser) {
161-
$this->parser = new Parser($this->functions);
162-
}
163-
164-
return $this->parser;
156+
return $this->parser ??= new Parser($this->functions);
165157
}
166158

167159
private function getCompiler(): Compiler
168160
{
169-
if (null === $this->compiler) {
170-
$this->compiler = new Compiler($this->functions);
171-
}
161+
$this->compiler ??= new Compiler($this->functions);
172162

173163
return $this->compiler->reset();
174164
}

‎src/Symfony/Component/ExpressionLanguage/Node/ConstantNode.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/Node/ConstantNode.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class ConstantNode extends Node
2222
{
23-
private $isIdentifier;
23+
private bool $isIdentifier;
2424

2525
public function __construct(mixed $value, bool $isIdentifier = false)
2626
{

‎src/Symfony/Component/ExpressionLanguage/ParsedExpression.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/ParsedExpression.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class ParsedExpression extends Expression
2222
{
23-
private $nodes;
23+
private Node $nodes;
2424

2525
public function __construct(string $expression, Node $nodes)
2626
{

‎src/Symfony/Component/ExpressionLanguage/Parser.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/Parser.php
+7-8Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ class Parser
2626
public const OPERATOR_LEFT = 1;
2727
public const OPERATOR_RIGHT = 2;
2828

29-
private $stream;
30-
private $unaryOperators;
31-
private $binaryOperators;
32-
private $functions;
33-
private $names;
34-
private $lint;
29+
private TokenStream $stream;
30+
private array $unaryOperators;
31+
private array $binaryOperators;
32+
private array $functions;
33+
private ?array $names;
34+
private bool $lint = false;
3535

3636
public function __construct(array $functions)
3737
{
@@ -124,8 +124,7 @@ private function doParse(TokenStream $stream, ?array $names = []): Node\Node
124124
throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s".', $stream->current->type, $stream->current->value), $stream->current->cursor, $stream->getExpression());
125125
}
126126

127-
$this->stream = null;
128-
$this->names = null;
127+
unset($this->stream, $this->names);
129128

130129
return $node;
131130
}

‎src/Symfony/Component/ExpressionLanguage/SerializedParsedExpression.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/SerializedParsedExpression.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class SerializedParsedExpression extends ParsedExpression
2020
{
21-
private $nodes;
21+
private string $nodes;
2222

2323
/**
2424
* @param string $expression An expression

‎src/Symfony/Component/ExpressionLanguage/TokenStream.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/TokenStream.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class TokenStream
2020
{
2121
public $current;
2222

23-
private $tokens;
24-
private $position = 0;
25-
private $expression;
23+
private array $tokens;
24+
private int $position = 0;
25+
private string $expression;
2626

2727
public function __construct(array $tokens, string $expression = '')
2828
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.