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

[ExpressionLanguage] [5.0] add type-hints whenever possible #32346

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
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
8 changes: 2 additions & 6 deletions 8 src/Symfony/Component/ExpressionLanguage/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,9 @@ public function subcompile(Node\Node $node)
/**
* Adds a raw string to the compiled code.
*
* @param string $string The string
*
* @return $this
*/
public function raw($string)
public function raw(string $string)
{
$this->source .= $string;

Expand All @@ -92,11 +90,9 @@ public function raw($string)
/**
* Adds a quoted string to the compiled code.
*
* @param string $value The string
*
* @return $this
*/
public function string($value)
public function string(string $value)
{
$this->source .= sprintf('"%s"', addcslashes($value, "\0\t\"\$\\"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public function getEvaluator()
/**
* Creates an ExpressionFunction from a PHP function name.
*
* @param string $phpFunctionName The PHP function name
* @param string|null $expressionFunctionName The expression function name (default: same than the PHP function name)
*
* @return self
Expand All @@ -73,7 +72,7 @@ public function getEvaluator()
* @throws \InvalidArgumentException if given PHP function name is in namespace
* and expression function name is not defined
*/
public static function fromPhp($phpFunctionName, $expressionFunctionName = null)
public static function fromPhp(string $phpFunctionName, string $expressionFunctionName = null)
{
$phpFunctionName = ltrim($phpFunctionName, '\\');
if (!\function_exists($phpFunctionName)) {
Expand Down
12 changes: 4 additions & 8 deletions 12 src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ public function __construct(CacheItemPoolInterface $cache = null, array $provide
* Compiles an expression source code.
*
* @param Expression|string $expression The expression to compile
* @param array $names An array of valid names
*
* @return string The compiled PHP source code
*/
public function compile($expression, $names = [])
public function compile($expression, array $names = [])
{
return $this->getCompiler()->compile($this->parse($expression, $names)->getNodes())->getSource();
}
Expand All @@ -58,11 +57,10 @@ public function compile($expression, $names = [])
* Evaluate an expression.
*
* @param Expression|string $expression The expression to compile
* @param array $values An array of values
*
* @return mixed The result of the evaluation of the expression
*/
public function evaluate($expression, $values = [])
public function evaluate($expression, array $values = [])
{
return $this->parse($expression, array_keys($values))->getNodes()->evaluate($this->functions, $values);
}
Expand All @@ -71,11 +69,10 @@ public function evaluate($expression, $values = [])
* Parses an expression.
*
* @param Expression|string $expression The expression to parse
* @param array $names An array of valid names
*
* @return ParsedExpression A ParsedExpression instance
*/
public function parse($expression, $names)
public function parse($expression, array $names)
{
if ($expression instanceof ParsedExpression) {
return $expression;
Expand Down Expand Up @@ -104,15 +101,14 @@ public function parse($expression, $names)
/**
* Registers a function.
*
* @param string $name The function name
* @param callable $compiler A callable able to compile the function
* @param callable $evaluator A callable able to evaluate the function
*
* @throws \LogicException when registering a function after calling evaluate(), compile() or parse()
*
* @see ExpressionFunction
*/
public function register($name, callable $compiler, callable $evaluator)
public function register(string $name, callable $compiler, callable $evaluator)
{
if (null !== $this->parser) {
throw new \LogicException('Registering functions after calling evaluate(), compile() or parse() is not supported.');
Expand Down
4 changes: 1 addition & 3 deletions 4 src/Symfony/Component/ExpressionLanguage/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ class Lexer
/**
* Tokenizes an expression.
*
* @param string $expression The expression to tokenize
*
* @return TokenStream A token stream instance
*
* @throws SyntaxError
*/
public function tokenize($expression)
public function tokenize(string $expression)
{
$expression = str_replace(["\r", "\n", "\t", "\v", "\f"], ' ', $expression);
$cursor = 0;
Expand Down
7 changes: 2 additions & 5 deletions 7 src/Symfony/Component/ExpressionLanguage/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,11 @@ public function __construct(array $functions)
* variable 'container' can be used in the expression
* but the compiled code will use 'this'.
*
* @param TokenStream $stream A token stream instance
* @param array $names An array of valid names
*
* @return Node\Node A node tree
*
* @throws SyntaxError
*/
public function parse(TokenStream $stream, $names = [])
public function parse(TokenStream $stream, array $names = [])
{
$this->stream = $stream;
$this->names = $names;
Expand All @@ -105,7 +102,7 @@ public function parse(TokenStream $stream, $names = [])
return $node;
}

public function parseExpression($precedence = 0)
public function parseExpression(int $precedence = 0)
{
$expr = $this->getPrimary();
$token = $this->stream->current;
Expand Down
5 changes: 2 additions & 3 deletions 5 src/Symfony/Component/ExpressionLanguage/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ public function __toString()
/**
* Tests the current token for a type and/or a value.
*
* @param array|int $type The type to test
* @param string|null $value The token value
* @param array|int $type The type to test
*
* @return bool
*/
public function test($type, $value = null)
public function test($type, string $value = null)
{
return $this->type === $type && (null === $value || $this->value == $value);
}
Expand Down
3 changes: 1 addition & 2 deletions 3 src/Symfony/Component/ExpressionLanguage/TokenStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ public function next()
* Tests a token.
*
* @param array|int $type The type to test
* @param string|null $value The token value
* @param string|null $message The syntax error message
*/
public function expect($type, $value = null, $message = null)
public function expect($type, string $value = null, string $message = null)
{
$token = $this->current;
if (!$token->test($type, $value)) {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.