10000 [ExpressionLanguage] Add types to private properties by derrabus · Pull Request #42104 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[ExpressionLanguage] Add types to private properties #42104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Symfony/Component/ExpressionLanguage/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/
class Compiler implements ResetInterface
{
private $source;
private $functions;
private string $source = '';
private array $functions;

public function __construct(array $functions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
*/
class ExpressionFunction
{
private $name;
private $compiler;
private $evaluator;
private string $name;
private \Closure $compiler;
private \Closure $evaluator;

/**
* @param string $name The function name
Expand Down
28 changes: 9 additions & 19 deletions src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class_exists(ParsedExpression::class);
*/
class ExpressionLanguage
{
private $cache;
private $lexer;
private $parser;
private $compiler;
private CacheItemPoolInterface $cache;
private Lexer $lexer;
private Parser $parser;
private Compiler $compiler;

protected $functions = [];
protected array $functions = [];

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

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

private function getLexer(): Lexer
{
if (null === $this->lexer) {
$this->lexer = new Lexer();
}

return $this->lexer;
return $this->lexer ??= new Lexer();
}

private function getParser(): Parser
{
if (null === $this->parser) {
$this->parser = new Parser($this->functions);
}

return $this->parser;
return $this->parser ??= new Parser($this->functions);
}

private function getCompiler(): Compiler
{
if (null === $this->compiler) {
$this->compiler = new Compiler($this->functions);
}
$this->compiler ??= new Compiler($this->functions);

return $this->compiler->reset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class ConstantNode extends Node
{
private $isIdentifier;
private bool $isIdentifier;

public function __construct(mixed $value, bool $isIdentifier = false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class ParsedExpression extends Expression
{
private $nodes;
private Node $nodes;

public function __construct(string $expression, Node $nodes)
{
Expand Down
15 changes: 7 additions & 8 deletions src/Symfony/Component/ExpressionLanguage/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class Parser
public const OPERATOR_LEFT = 1;
public const OPERATOR_RIGHT = 2;

private $stream;
private $unaryOperators;
private $binaryOperators;
private $functions;
private $names;
private $lint;
private TokenStream $stream;
private array $unaryOperators;
private array $binaryOperators;
private array $functions;
private ?array $names;
private bool $lint = false;

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

$this->stream = null;
$this->names = null;
unset($this->stream, $this->names);

return $node;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
class SerializedParsedExpression extends ParsedExpression
{
private $nodes;
private string $nodes;

/**
* @param string $expression An expression
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/ExpressionLanguage/TokenStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class TokenStream
{
public $current;

private $tokens;
private $position = 0;
private $expression;
private array $tokens;
private int $position = 0;
private string $expression;

public function __construct(array $tokens, string $expression = '')
{
Expand Down
0