Skip to content

Commit 5b09677

Browse files
committed
Prevent to visit node that got dropped later in loop
1 parent d547532 commit 5b09677

22 files changed

+309
-218
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"ext-mbstring": "*"
1515
},
1616
"require-dev": {
17-
"phpunit/phpunit": "^6.0 || ^7.0",
18-
"codeclimate/php-test-reporter": "dev-master"
17+
"phpunit/phpunit": "^6.5.14 || ^7.5.20 || ^8.5.31 || ^9.5.27"
1918
},
2019
"minimum-stability": "stable",
2120
"autoload": {

src/JsPhpize/Compiler/Compiler.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,23 @@ protected function visitDyiade(Dyiade $dyiade, $indent)
191191
return $this->compileLazyDyiade($this->engine->getHelperName('and'), $leftHand, $rightHand);
192192
case '+':
193193
$arguments = [$leftHand, $rightHand];
194-
while (
195-
($dyiade = $dyiade->rightHand) instanceof Dyiade &&
196-
$dyiade->operator === '+'
197-
) {
198-
/* @var Dyiade $dyiade */
194+
$innerRightHand = $dyiade->rightHand;
195+
196+
if ($innerRightHand instanceof Dyiade && $innerRightHand->operator === '+') {
197+
$last = $dyiade;
199198
array_pop($arguments);
200-
$arguments[] = $this->visitNode($dyiade->leftHand, $indent);
201-
$arguments[] = $this->visitNode($dyiade->rightHand, $indent);
199+
200+
while (
201+
($dyiade = $dyiade->rightHand) instanceof Dyiade &&
202+
$dyiade->operator === '+'
203+
) {
204+
$last = $dyiade;
205+
$arguments[] = $this->visitNode($dyiade->leftHand, $indent);
206+
}
207+
208+
if ($last instanceof Dyiade && $last->operator === '+') {
209+
$arguments[] = $this->visitNode($last->rightHand, $indent);
210+
}
202211
}
203212

204213
return $this->helperWrap($this->engine->getHelperName('plus'), $arguments);

src/JsPhpize/Compiler/Helpers/Dot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function ($base) {
7373
{
7474
$value = $this->getValue();
7575

76-
if (method_exists($value, '__toBoolean')) {
76+
if (is_object($value) && method_exists($value, '__toBoolean')) {
7777
return $value->__toBoolean();
7878
}
7979

src/JsPhpize/Compiler/Helpers/Dot.ref.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function (&$base) {
7373
{
7474
$value = $this->getValue();
7575

76-
if (method_exists($value, '__toBoolean')) {
76+
if (is_object($value) && method_exists($value, '__toBoolean')) {
7777
return $value->__toBoolean();
7878
}
7979

src/JsPhpize/Compiler/Helpers/DotObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function ($base) {
7373
{
7474
$value = $this->getValue();
7575

76-
if (method_exists($value, '__toBoolean')) {
76+
if (is_object($value) && method_exists($value, '__toBoolean')) {
7777
return $value->__toBoolean();
7878
}
7979

src/JsPhpize/Compiler/Helpers/DotObject.ref.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function (&$base) {
7373
{
7474
$value = $this->getValue();
7575

76-
if (method_exists($value, '__toBoolean')) {
76+
if (is_object($value) && method_exists($value, '__toBoolean')) {
7777
return $value->__toBoolean();
7878
}
7979

src/JsPhpize/Compiler/Helpers/DotWithArrayPrototype.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function ($base) {
153153
{
154154
$value = $this->getValue();
155155

156-
if (method_exists($value, '__toBoolean')) {
156+
if (is_object($value) && method_exists($value, '__toBoolean')) {
157157
return $value->__toBoolean();
158158
}
159159

src/JsPhpize/Compiler/Helpers/DotWithArrayPrototype.ref.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function (&$base) {
153153
{
154154
$value = $this->getValue();
155155

156-
if (method_exists($value, '__toBoolean')) {
156+
if (is_object($value) && method_exists($value, '__toBoolean')) {
157157
return $value->__toBoolean();
158158
}
159159

src/JsPhpize/Compiler/Helpers/Set.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function ($base, $key, $operator, $value) {
55
$base[$key] = $value;
66
break;
77
}
8-
if (method_exists($base, $method = "set" . ucfirst($key))) {
8+
if (is_object($base) && method_exists($base, $method = "set" . ucfirst($key))) {
99
$base->$method($value);
1010
break;
1111
}

src/JsPhpize/Stream/ExpressionStream.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,26 @@
22

33
namespace JsPhpize\Stream;
44

5+
use Attribute;
6+
7+
// @codeCoverageIgnoreStart
8+
if (\PHP_VERSION >= 8 && \PHP_VERSION < 8.2 && !class_exists('AllowDynamicProperties')) {
9+
#[Attribute(Attribute::TARGET_CLASS)]
10+
final class AllowDynamicProperties
11+
{
12+
public function __construct()
13+
{
14+
}
15+
}
16+
}
17+
// @codeCoverageIgnoreEnd
18+
519
/**
620
* Creates a wrapper in order to allow the Zend PhpRenderer
721
* to include the compiled file.
822
* Class JsPhpize\Stream\ExrpressionStream.
923
*/
24+
#[\AllowDynamicProperties]
1025
class ExpressionStream
1126
{
1227
/**

0 commit comments

Comments
 (0)