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 143b616

Browse filesBrowse files
committed
[ExpressionLanguage] [5.0] add type-hints whenever possible
1 parent cc9778e commit 143b616
Copy full SHA for 143b616

File tree

7 files changed

+14
-30
lines changed
Filter options

7 files changed

+14
-30
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/Compiler.php
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,9 @@ public function subcompile(Node\Node $node)
7878
/**
7979
* Adds a raw string to the compiled code.
8080
*
81-
* @param string $string The string
82-
*
8381
* @return $this
8482
*/
85-
public function raw($string)
83+
public function raw(string $string)
8684
{
8785
$this->source .= $string;
8886

@@ -92,11 +90,9 @@ public function raw($string)
9290
/**
9391
* Adds a quoted string to the compiled code.
9492
*
95-
* @param string $value The string
96-
*
9793
* @return $this
9894
*/
99-
public function string($value)
95+
public function string(string $value)
10096
{
10197
$this->source .= sprintf('"%s"', addcslashes($value, "\0\t\"\$\\"));
10298

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/ExpressionFunction.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public function getEvaluator()
6464
/**
6565
* Creates an ExpressionFunction from a PHP function name.
6666
*
67-
* @param string $phpFunctionName The PHP function name
6867
* @param string|null $expressionFunctionName The expression function name (default: same than the PHP function name)
6968
*
7069
* @return self
@@ -73,7 +72,7 @@ public function getEvaluator()
7372
* @throws \InvalidArgumentException if given PHP function name is in namespace
7473
* and expression function name is not defined
7574
*/
76-
public static function fromPhp($phpFunctionName, $expressionFunctionName = null)
75+
public static function fromPhp(string $phpFunctionName, string $expressionFunctionName = null)
7776
{
7877
$phpFunctionName = ltrim($phpFunctionName, '\\');
7978
if (!\function_exists($phpFunctionName)) {

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php
+4-8Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ public function __construct(CacheItemPoolInterface $cache = null, array $provide
4545
* Compiles an expression source code.
4646
*
4747
* @param Expression|string $expression The expression to compile
48-
* @param array $names An array of valid names
4948
*
5049
* @return string The compiled PHP source code
5150
*/
52-
public function compile($expression, $names = [])
51+
public function compile($expression, array $names = [])
5352
{
5453
return $this->getCompiler()->compile($this->parse($expression, $names)->getNodes())->getSource();
5554
}
@@ -58,11 +57,10 @@ public function compile($expression, $names = [])
5857
* Evaluate an expression.
5958
*
6059
* @param Expression|string $expression The expression to compile
61-
* @param array $values An array of values
6260
*
6361
* @return mixed The result of the evaluation of the expression
6462
*/
65-
public function evaluate($expression, $values = [])
63+
public function evaluate($expression, array $values = [])
6664
{
6765
return $this->parse($expression, array_keys($values))->getNodes()->evaluate($this->functions, $values);
6866
}
@@ -71,11 +69,10 @@ public function evaluate($expression, $values = [])
7169
* Parses an expression.
7270
*
7371
* @param Expression|string $expression The expression to parse
74-
* @param array $names An array of valid names
7572
*
7673
* @return ParsedExpression A ParsedExpression instance
7774
*/
78-
public function parse($expression, $names)
75+
public function parse($expression, array $names)
7976
{
8077
if ($expression instanceof ParsedExpression) {
8178
return $expression;
@@ -104,15 +101,14 @@ public function parse($expression, $names)
104101
/**
105102
* Registers a function.
106103
*
107-
* @param string $name The function name
108104
* @param callable $compiler A callable able to compile the function
109105
* @param callable $evaluator A callable able to evaluate the function
110106
*
111107
* @throws \LogicException when registering a function after calling evaluate(), compile() or parse()
112108
*
113109
* @see ExpressionFunction
114110
*/
115-
public function register($name, callable $compiler, callable $evaluator)
111+
public function register(string $name, callable $compiler, callable $evaluator)
116112
{
117113
if (null !== $this->parser) {
118114
throw new \LogicException('Registering functions after calling evaluate(), compile() or parse() is not supported.');

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/Lexer.php
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ class Lexer
2121
/**
2222
* Tokenizes an expression.
2323
*
24-
* @param string $expression The expression to tokenize
25-
*
2624
* @return TokenStream A token stream instance
2725
*
2826
* @throws SyntaxError
2927
*/
30-
public function tokenize($expression)
28+
public function tokenize(string $expression)
3129
{
3230
$expression = str_replace(["\r", "\n", "\t", "\v", "\f"], ' ', $expression);
3331
$cursor = 0;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/Parser.php
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,11 @@ public function __construct(array $functions)
8585
* variable 'container' can be used in the expression
8686
* but the compiled code will use 'this'.
8787
*
88-
* @param TokenStream $stream A token stream instance
89-
* @param array $names An array of valid names
90-
*
9188
* @return Node\Node A node tree
9289
*
9390
* @throws SyntaxError
9491
*/
95-
public function parse(TokenStream $stream, $names = [])
92+
public function parse(TokenStream $stream, array $names = [])
9693
{
9794
$this->stream = $stream;
9895
$this->names = $names;
@@ -105,7 +102,7 @@ public function parse(TokenStream $stream, $names = [])
105102
return $node;
106103
}
107104

108-
public function parseExpression($precedence = 0)
105+
public function parseExpression(int $precedence = 0)
109106
{
110107
$expr = $this->getPrimary();
111108
$token = $this->stream->current;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/Token.php
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ public function __toString()
5454
/**
5555
* Tests the current token for a type and/or a value.
5656
*
57-
* @param array|int $type The type to test
58-
* @param string|null $value The token value
57+
* @param array|int $type The type to test
5958
*
6059
* @return bool
6160
*/
62-
public function test($type, $value = null)
61+
public function test($type, string $value = null)
6362
{
6463
return $this->type === $type && (null === $value || $this->value == $value);
6564
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/TokenStream.php
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,10 @@ public function next()
5858
/**
5959
* Tests a token.
6060
*
61-
* @param array|int $type The type to test
62-
* @param string|null $value The token value
61+
* @param array|int $type The type to test
6362
* @param string|null $message The syntax error message
6463
*/
65-
public function expect($type, $value = null, $message = null)
64+
public function expect($type, string $value = null, string $message = null)
6665
{
6766
$token = $this->current;
6867
if (!$token->test($type, $value)) {

0 commit comments

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