10000 minor #47058 [ExpressionLanguage] Remove usage of properties (fabpot) · symfony/symfony@523ba82 · GitHub
[go: up one dir, main page]

Skip to content

Commit 523ba82

Browse files
committed
minor #47058 [ExpressionLanguage] Remove usage of properties (fabpot)
This PR was merged into the 6.2 branch. Discussion ---------- [ExpressionLanguage] Remove usage of properties | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | n/a <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | n/a Commits ------- 824703b [ExpressionLanguage] Remove usage of properties
2 parents 39191b4 + 824703b commit 523ba82

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php

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

27-
private bool $isShortCircuited = false;
28-
public bool $isNullCoalesce = false;
29-
3027
public function __construct(Node $node, Node $attribute, ArrayNode $arguments, int $type)
3128
{
3229
parent::__construct(
3330
['node' => $node, 'attribute' => $attribute, 'arguments' => $arguments],
34-
['type' => $type]
31+
['type' => $type, 'is_null_coalesce' => false, 'is_short_circuited' => false],
3532
);
3633
}
3734

@@ -73,8 +70,8 @@ public function evaluate(array $functions, array $values)
7370
switch ($this->attributes['type']) {
7471
case self::PROPERTY_CALL:
7572
$obj = $this->nodes['node']->evaluate($functions, $values);
76-
if (null === $obj && ($this->nodes['attribute']->isNullSafe || $this->isNullCoalesce)) {
77-
$this->isShortCircuited = true;
73+
if (null === $obj && ($this->nodes['attribute']->isNullSafe || $this->attributes['is_null_coalesce'])) {
74+
$this->attributes['is_short_circuited'] = true;
7875

7976
return null;
8077
}
@@ -88,7 +85,7 @@ public function evaluate(array $functions, array $values)
8885

8986
$property = $this->nodes['attribute']->attributes['value'];
9087

91-
if ($this->isNullCoalesce) {
88+
if ($this->attributes['is_null_coalesce']) {
9289
return $obj->$property ?? null;
9390
}
9491

@@ -98,7 +95,7 @@ public function evaluate(array $functions, array $values)
9895
$obj = $this->nodes['node']->evaluate($functions, $values);
9996

10097
if (null === $obj && $this->nodes['attribute']->isNullSafe) {
101-
$this->isShortCircuited = true;
98+
$this->attributes['is_short_circuited'] = true;
10299

103100
return null;
104101
}
@@ -122,11 +119,11 @@ public function evaluate(array $functions, array $values)
122119
return null;
123120
}
124121

125-
if (!\is_array($array) && !$array instanceof \ArrayAccess && !(null === $array && $this->isNullCoalesce)) {
122+
if (!\is_array($array) && !$array instanceof \ArrayAccess && !(null === $array && $this->attributes['is_null_coalesce'])) {
126123
throw new \RuntimeException(sprintf('Unable to get an item of non-array "%s".', $this->nodes['node']->dump()));
127124
}
128125

129-
if ($this->isNullCoalesce) {
126+
if ($this->attributes['is_null_coalesce']) {
130127
return $array[$this->nodes['attribute']->evaluate($functions, $values)] ?? null;
131128
}
132129

@@ -136,9 +133,7 @@ public function evaluate(array $functions, array $values)
136133

137134
private function isShortCircuited(): bool
138135
{
139-
return $this->isShortCircuited
140-
|| ($this->nodes['node'] instanceof self && $this->nodes['node']->isShortCircuited())
141-
;
136+
return $this->attributes['is_short_circuited'] || ($this->nodes['node'] instanceof self && $this->nodes['node']->isShortCircuited());
142137
}
143138

144139
public function toArray()

src/Symfony/Component/ExpressionLanguage/Node/NullCoalesceNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function compile(Compiler $compiler)
3939
public function evaluate(array $functions, array $values)
4040
{
4141
if ($this->nodes['expr1'] instanceof GetAttrNode) {
42-
$this->nodes['expr1']->isNullCoalesce = true;
42+
$this->nodes['expr1']->attributes['is_null_coalesce'] = true;
4343
}
4444

4545
return $this->nodes['expr1']->evaluate($functions, $values) ?? $this->nodes['expr2']->evaluate($functions, $values);

0 commit comments

Comments
 (0)
0