Skip to content

Commit

Permalink
[ExpressionLanguage] Add types to private properties
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander M. Turek <me@derrabus.de>
  • Loading branch information
derrabus committed Jul 15, 2021
1 parent e3d5d00 commit 7781098
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 38 deletions.
4 changes: 2 additions & 2 deletions 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
6 changes: 3 additions & 3 deletions ExpressionFunction.php
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 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
2 changes: 1 addition & 1 deletion Node/ConstantNode.php
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
2 changes: 1 addition & 1 deletion ParsedExpression.php
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 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
2 changes: 1 addition & 1 deletion SerializedParsedExpression.php
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 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 comments on commit 7781098

Please sign in to comment.