Skip to content

Commit 75eea25

Browse files
wouterjnicolas-grekas
authored andcommitted
Add PHP types to private methods and functions
1 parent acbfd5f commit 75eea25

File tree

8 files changed

+28
-25
lines changed

8 files changed

+28
-25
lines changed

Node/ArgumentsNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
*/
2121
class ArgumentsNode extends ArrayNode
2222
{
23-
public function compile(Compiler $compiler)
23+
public function compile(Compiler $compiler): void
2424
{
2525
$this->compileArguments($compiler, false);
2626
}
2727

28-
public function toArray()
28+
public function toArray(): array
2929
{
3030
$array = [];
3131

Node/ArrayNode.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct()
2727
$this->index = -1;
2828
}
2929

30-
public function addElement(Node $value, Node $key = null)
30+
public function addElement(Node $value, Node $key = null): void
3131
{
3232
$key ??= new ConstantNode(++$this->index);
3333

@@ -37,14 +37,14 @@ public function addElement(Node $value, Node $key = null)
3737
/**
3838
* Compiles the node to PHP.
3939
*/
40-
public function compile(Compiler $compiler)
40+
public function compile(Compiler $compiler): void
4141
{
4242
$compiler->raw('[');
4343
$this->compileArguments($compiler);
4444
$compiler->raw(']');
4545
}
4646

47-
public function evaluate(array $functions, array $values)
47+
public function evaluate(array $functions, array $values): array
4848
{
4949
$result = [];
5050
foreach ($this->getKeyValuePairs() as $pair) {
@@ -54,7 +54,7 @@ public function evaluate(array $functions, array $values)
5454
return $result;
5555
}
5656

57-
public function toArray()
57+
public function toArray(): array
5858
{
5959
$value = [];
6060
foreach ($this->getKeyValuePairs() as $pair) {
@@ -84,7 +84,7 @@ public function toArray()
8484
return $array;
8585
}
8686

87-
protected function getKeyValuePairs()
87+
protected function getKeyValuePairs(): array
8888
{
8989
$pairs = [];
9090
foreach (array_chunk($this->nodes, 2) as $pair) {
@@ -94,7 +94,7 @@ protected function getKeyValuePairs()
9494
return $pairs;
9595
}
9696

97-
protected function compileArguments(Compiler $compiler, bool $withKeys = true)
97+
protected function compileArguments(Compiler $compiler, bool $withKeys = true): void
9898
{
9999
$first = true;
100100
foreach ($this->getKeyValuePairs() as $pair) {

Node/BinaryNode.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(string $operator, Node $left, Node $right)
4545
);
4646
}
4747

48-
public function compile(Compiler $compiler)
48+
public function compile(Compiler $compiler): void
4949
{
5050
$operator = $this->attributes['operator'];
5151

@@ -92,7 +92,7 @@ public function compile(Compiler $compiler)
9292
;
9393
}
9494

95-
public function evaluate(array $functions, array $values)
95+
public function evaluate(array $functions, array $values): mixed
9696
{
9797
$operator = $this->attributes['operator'];
9898
$left = $this->nodes['left']->evaluate($functions, $values);
@@ -171,7 +171,7 @@ public function evaluate(array $functions, array $values)
171171
}
172172
}
173173

174-
public function toArray()
174+
public function toArray(): array
175175
{
176176
return ['(', $this->nodes['left'], ' '.$this->attributes['operator'].' ', $this->nodes['right'], ')'];
177177
}

Node/ConditionalNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(Node $expr1, Node $expr2, Node $expr3)
2727
);
2828
}
2929

30-
public function compile(Compiler $compiler)
30+
public function compile(Compiler $compiler): void
3131
{
3232
$compiler
3333
->raw('((')
@@ -49,7 +49,7 @@ public function evaluate(array $functions, array $values)
4949
return $this->nodes['expr3']->evaluate($functions, $values);
5050
}
5151

52-
public function toArray()
52+
public function toArray(): array
5353
{
5454
return ['(', $this->nodes['expr1'], ' ? ', $this->nodes['expr2'], ' : ', $this->nodes['expr3'], ')'];
5555
}

Node/ConstantNode.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ public function __construct(mixed $value, bool $isIdentifier = false, bool $isNu
3333
);
3434
}
3535

36-
public function compile(Compiler $compiler)
36+
public function compile(Compiler $compiler): void
3737
{
3838
$compiler->repr($this->attributes['value']);
3939
}
4040

41-
public function evaluate(array $functions, array $values)
41+
public function evaluate(array $functions, array $values): mixed
4242
{
4343
return $this->attributes['value'];
4444
}
4545

46-
public function toArray()
46+
public function toArray(): array
4747
{
4848
$array = [];
4949
$value = $this->attributes['value'];

Node/GetAttrNode.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class GetAttrNode extends Node
2424
public const METHOD_CALL = 2;
2525
public const ARRAY_CALL = 3;
2626

27+
/**
28+
* @param self::* $type
29+
*/
2730
public function __construct(Node $node, Node $attribute, ArrayNode $arguments, int $type)
2831
{
2932
parent::__construct(
@@ -32,7 +35,7 @@ public function __construct(Node $node, Node $attribute, ArrayNode $arguments, i
3235
);
3336
}
3437

35-
public function compile(Compiler $compiler)
38+
public function compile(Compiler $compiler): void
3639
{
3740
$nullSafe = $this->nodes['attribute'] instanceof ConstantNode && $this->nodes['attribute']->isNullSafe;
3841
switch ($this->attributes['type']) {
@@ -65,7 +68,7 @@ public function compile(Compiler $compiler)
6568
}
6669
}
6770

68-
public function evaluate(array $functions, array $values)
71+
public function evaluate(array $functions, array $values): mixed
6972
{
7073
switch ($this->attributes['type']) {
7174
case self::PROPERTY_CALL:
@@ -136,7 +139,7 @@ private function isShortCircuited(): bool
136139
return $this->attributes['is_short_circuited'] || ($this->nodes['node'] instanceof self && $this->nodes['node']->isShortCircuited());
137140
}
138141

139-
public function toArray()
142+
public function toArray(): array
140143
{
141144
switch ($this->attributes['type']) {
142145
case self::PROPERTY_CALL:

Node/NameNode.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ public function __construct(string $name)
2828
);
2929
}
3030

31-
public function compile(Compiler $compiler)
31+
public function compile(Compiler $compiler): void
3232
{
3333
$compiler->raw('$'.$this->attributes['name']);
3434
}
3535

36-
public function evaluate(array $functions, array $values)
36+
public function evaluate(array $functions, array $values): mixed
3737
{
3838
return $values[$this->attributes['name']];
3939
}
4040

41-
public function toArray()
41+
public function toArray(): array
4242
{
4343
return [$this->attributes['name']];
4444
}

Node/NullCoalesceNode.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(Node $expr1, Node $expr2)
2525
parent::__construct(['expr1' => $expr1, 'expr2' => $expr2]);
2626
}
2727

28-
public function compile(Compiler $compiler)
28+
public function compile(Compiler $compiler): void
2929
{
3030
$compiler
3131
->raw('((')
@@ -36,7 +36,7 @@ public function compile(Compiler $compiler)
3636
;
3737
}
3838

39-
public function evaluate(array $functions, array $values)
39+
public function evaluate(array $functions, array $values): mixed
4040
{
4141
if ($this->nodes['expr1'] instanceof GetAttrNode) {
4242
$this->nodes['expr1']->attributes['is_null_coalesce'] = true;
@@ -45,7 +45,7 @@ public function evaluate(array $functions, array $values)
4545
return $this->nodes['expr1']->evaluate($functions, $values) ?? $this->nodes['expr2']->evaluate($functions, $values);
4646
}
4747

48-
public function toArray()
48+
public function toArray(): array
4949
{
5050
return ['(', $this->nodes['expr1'], ') ?? (', $this->nodes['expr2'], ')'];
5151
}

0 commit comments

Comments
 (0)