Skip to content

Commit d57df58

Browse files
wouterjnicolas-grekas
authored andcommitted
[Components] Convert to native return types
1 parent 1b1b2d2 commit d57df58

9 files changed

+26
-96
lines changed

Compiler.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ public function __construct(array $functions)
2828
$this->functions = $functions;
2929
}
3030

31-
/**
32-
* @return array
33-
*/
34-
public function getFunction(string $name)
31+
public function getFunction(string $name): array
3532
{
3633
return $this->functions[$name];
3734
}
@@ -66,10 +63,7 @@ public function compile(Node\Node $node): static
6663
return $this;
6764
}
6865

69-
/**
70-
* @return string
71-
*/
72-
public function subcompile(Node\Node $node)
66+
public function subcompile(Node\Node $node): string
7367
{
7468
$current = $this->source;
7569
$this->source = '';

ExpressionFunctionProviderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ interface ExpressionFunctionProviderInterface
1919
/**
2020
* @return ExpressionFunction[]
2121
*/
22-
public function getFunctions();
22+
public function getFunctions(): array;
2323
}

ExpressionLanguage.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,11 @@ public function lint(Expression|string $expression, ?array $names): void
110110
* @param callable $compiler A callable able to compile the function
111111
* @param callable $evaluator A callable able to evaluate the function
112112
*
113-
* @return void
114-
*
115113
* @throws \LogicException when registering a function after calling evaluate(), compile() or parse()
116114
*
117115
* @see ExpressionFunction
118116
*/
119-
public function register(string $name, callable $compiler, callable $evaluator)
117+
public function register(string $name, callable $compiler, callable $evaluator): void
120118
{
121119
if (isset($this->parser)) {
122120
throw new \LogicException('Registering functions after calling evaluate(), compile() or parse() is not supported.');
@@ -125,28 +123,19 @@ public function register(string $name, callable $compiler, callable $evaluator)
125123
$this->functions[$name] = ['compiler' => $compiler, 'evaluator' => $evaluator];
126124
}
127125

128-
/**
129-
* @return void
130-
*/
131-
public function addFunction(ExpressionFunction $function)
126+
public function addFunction(ExpressionFunction $function): void
132127
{
133128
$this->register($function->getName(), $function->getCompiler(), $function->getEvaluator());
134129
}
135130

136-
/**
137-
* @return void
138-
*/
139-
public function registerProvider(ExpressionFunctionProviderInterface $provider)
131+
public function registerProvider(ExpressionFunctionProviderInterface $provider): void
140132
{
141133
foreach ($provider->getFunctions() as $function) {
142134
$this->addFunction($function);
143135
}
144136
}
145137

146-
/**
147-
* @return void
148-
*/
149-
protected function registerFunctions()
138+
protected function registerFunctions(): void
150139
{
151140
$this->addFunction(ExpressionFunction::fromPhp('constant'));
152141

Node/FunctionNode.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ public function evaluate(array $functions, array $values): mixed
5050
return $functions[$this->attributes['name']]['evaluator'](...$arguments);
5151
}
5252

53-
/**
54-
* @return array
55-
*/
56-
public function toArray()
53+
public function toArray(): array
5754
{
5855
$array = [];
5956
$array[] = $this->attributes['name'];

Node/Node.php

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,14 @@ public function __toString(): string
5757
return implode("\n", $repr);
5858
}
5959

60-
/**
61-
* @return void
62-
*/
63-
public function compile(Compiler $compiler)
60+
public function compile(Compiler $compiler): void
6461
{
6562
foreach ($this->nodes as $node) {
6663
$node->compile($compiler);
6764
}
6865
}
6966

70-
/**
71-
* @return mixed
72-
*/
73-
public function evaluate(array $functions, array $values)
67+
public function evaluate(array $functions, array $values): mixed
7468
{
7569
$results = [];
7670
foreach ($this->nodes as $node) {
@@ -81,19 +75,14 @@ public function evaluate(array $functions, array $values)
8175
}
8276

8377
/**
84-
* @return array
85-
*
8678
* @throws \BadMethodCallException when this node cannot be transformed to an array
8779
*/
88-
public function toArray()
80+
public function toArray(): array
8981
{
9082
throw new \BadMethodCallException(sprintf('Dumping a "%s" instance is not supported yet.', static::class));
9183
}
9284

93-
/**
94-
* @return string
95-
*/
96-
public function dump()
85+
public function dump(): string
9786
{
9887
$dump = '';
9988

@@ -104,18 +93,12 @@ public function dump()
10493
return $dump;
10594
}
10695

107-
/**
108-
* @return string
109-
*/
110-
protected function dumpString(string $value)
96+
protected function dumpString(string $value): string
11197
{
11298
return sprintf('"%s"', addcslashes($value, "\0\t\"\\"));
11399
}
114100

115-
/**
116-
* @return bool
117-
*/
118-
protected function isHash(array $value)
101+
protected function isHash(array $value): bool
119102
{
120103
$expectedKey = 0;
121104

ParsedExpression.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ public function __construct(string $expression, Node $nodes)
2929
$this->nodes = $nodes;
3030
}
3131

32-
/**
33-
* @return Node
34-
*/
35-
public function getNodes()
32+
public function getNodes(): Node
3633
{
3734
return $this->nodes;
3835
}

Parser.php

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,7 @@ private function doParse(TokenStream $stream, ?array $names = []): Node\Node
130130
return $node;
131131
}
132132

133-
/**
134-
* @return Node\Node
135-
*/
136-
public function parseExpression(int $precedence = 0)
133+
public function parseExpression(int $precedence = 0): Node\Node
137134
{
138135
$expr = $this->getPrimary();
139136
$token = $this->stream->current;
@@ -154,10 +151,7 @@ public function parseExpression(int $precedence = 0)
154151
return $expr;
155152
}
156153

157-
/**
158-
* @return Node\Node
159-
*/
160-
protected function getPrimary()
154+
protected function getPrimary(): Node\Node
161155
{
162156
$token = $this->stream->current;
163157

@@ -180,10 +174,7 @@ protected function getPrimary()
180174
return $this->parsePrimaryExpression();
181175
}
182176

183-
/**
184-
* @return Node\Node
185-
*/
186-
protected function parseConditionalExpression(Node\Node $expr)
177+
protected function parseConditionalExpression(Node\Node $expr): Node\Node
187178
{
188179
while ($this->stream->current->test(Token::PUNCTUATION_TYPE, '??')) {
189180
$this->stream->next();
@@ -214,10 +205,7 @@ protected function parseConditionalExpression(Node\Node $expr)
214205
return $expr;
215206
}
216207

217-
/**
218-
* @return Node\Node
219-
*/
220-
public function parsePrimaryExpression()
208+
public function parsePrimaryExpression(): Node\Node
221209
{
222210
$token = $this->stream->current;
223211
switch ($token->type) {
@@ -282,10 +270,7 @@ public function parsePrimaryExpression()
282270
return $this->parsePostfixExpression($node);
283271
}
284272

285-
/**
286-
* @return Node\ArrayNode
287-
*/
288-
public function parseArrayExpression()
273+
public function parseArrayExpression(): Node\ArrayNode
289274
{
290275
$this->stream->expect(Token::PUNCTUATION_TYPE, '[', 'An array element was expected');
291276

@@ -309,10 +294,7 @@ public function parseArrayExpression()
309294
return $node;
310295
}
311296

312-
/**
313-
* @return Node\ArrayNode
314-
*/
315-
public function parseHashExpression()
297+
public function parseHashExpression(): Node\ArrayNode
316298
{
317299
$this->stream->expect(Token::PUNCTUATION_TYPE, '{', 'A hash element was expected');
318300

@@ -356,10 +338,7 @@ public function parseHashExpression()
356338
return $node;
357339
}
358340

359-
/**
360-
* @return Node\GetAttrNode|Node\Node
361-
*/
362-
public function parsePostfixExpression(Node\Node $node)
341+
public function parsePostfixExpression(Node\Node $node): Node\GetAttrNode|Node\Node
363342
{
364343
$token = $this->stream->current;
365344
while (Token::PUNCTUATION_TYPE == $token->type) {
@@ -418,10 +397,8 @@ public function parsePostfixExpression(Node\Node $node)
418397

419398
/**
420399
* Parses arguments.
421-
*
422-
* @return Node\Node
423400
*/
424-
public function parseArguments()
401+
public function parseArguments(): Node\Node
425402
{
426403
$args = [];
427404
$this->stream->expect(Token::PUNCTUATION_TYPE, '(', 'A list of arguments must begin with an opening parenthesis');

SerializedParsedExpression.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ public function __construct(string $expression, string $nodes)
3232
$this->nodes = $nodes;
3333
}
3434

35-
/**
36-
* @return Node
37-
*/
38-
public function getNodes()
35+
public function getNodes(): Node
3936
{
4037
return unserialize($this->nodes);
4138
}

TokenStream.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ public function __toString(): string
4141

4242
/**
4343
* Sets the pointer to the next token and returns the old one.
44-
*
45-
* @return void
4644
*/
47-
public function next()
45+
public function next(): void
4846
{
4947
++$this->position;
5048

@@ -57,10 +55,8 @@ public function next()
5755

5856
/**
5957
* @param string|null $message The syntax error message
60-
*
61-
* @return void
6258
*/
63-
public function expect(string $type, string $value = null, string $message = null)
59+
public function expect(string $type, string $value = null, string $message = null): void
6460
{
6561
$token = $this->current;
6662
if (!$token->test($type, $value)) {

0 commit comments

Comments
 (0)