Skip to content

Commit

Permalink
Merge branch '4.4' into 5.1
Browse files Browse the repository at this point in the history
* 4.4:
  Changed private static array-properties to const
  • Loading branch information
nicolas-grekas committed Jan 25, 2021
2 parents ed58fc7 + 66e8566 commit ee64c66
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions Node/BinaryNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
*/
class BinaryNode extends Node
{
private static $operators = [
private const OPERATORS = [
'~' => '.',
'and' => '&&',
'or' => '||',
];

private static $functions = [
private const FUNCTIONS = [
'**' => 'pow',
'..' => 'range',
'in' => 'in_array',
Expand Down Expand Up @@ -57,9 +57,9 @@ public function compile(Compiler $compiler)
return;
}

if (isset(self::$functions[$operator])) {
if (isset(self::FUNCTIONS[$operator])) {
$compiler
->raw(sprintf('%s(', self::$functions[$operator]))
->raw(sprintf('%s(', self::FUNCTIONS[$operator]))
->compile($this->nodes['left'])
->raw(', ')
->compile($this->nodes['right'])
Expand All @@ -69,8 +69,8 @@ public function compile(Compiler $compiler)
return;
}

if (isset(self::$operators[$operator])) {
$operator = self::$operators[$operator];
if (isset(self::OPERATORS[$operator])) {
$operator = self::OPERATORS[$operator];
}

$compiler
Expand All @@ -89,13 +89,13 @@ public function evaluate(array $functions, array $values)
$operator = $this->attributes['operator'];
$left = $this->nodes['left']->evaluate($functions, $values);

if (isset(self::$functions[$operator])) {
if (isset(self::FUNCTIONS[$operator])) {
$right = $this->nodes['right']->evaluate($functions, $values);

if ('not in' === $operator) {
return !\in_array($left, $right);
}
$f = self::$functions[$operator];
$f = self::FUNCTIONS[$operator];

return $f($left, $right);
}
Expand Down
4 changes: 2 additions & 2 deletions Node/UnaryNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class UnaryNode extends Node
{
private static $operators = [
private const OPERATORS = [
'!' => '!',
'not' => '!',
'+' => '+',
Expand All @@ -39,7 +39,7 @@ public function compile(Compiler $compiler)
{
$compiler
->raw('(')
->raw(self::$operators[$this->attributes['operator']])
->raw(self::OPERATORS[$this->attributes['operator']])
->compile($this->nodes['node'])
->raw(')')
;
Expand Down

0 comments on commit ee64c66

Please sign in to comment.