Skip to content

Commit 96accae

Browse files
committed
Fix Two Operands exception
1 parent 8a10b88 commit 96accae

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ before_script:
1010
script:
1111
- phpunit
1212

13-
after_script:
13+
after_script:
1414
- php vendor/bin/coveralls -v

src/SQLParser/Node/NodeFactory.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
namespace SQLParser\Node;
3434

3535
use Mouf\Database\MagicQueryException;
36+
use Mouf\Database\MagicQueryParserException;
3637
use SQLParser\SqlRenderInterface;
3738
use Doctrine\DBAL\Connection;
3839
use Mouf\MoufManager;
@@ -620,16 +621,16 @@ public static function simplify($nodes)
620621
*/
621622

622623
if (isset(self::$OPERATOR_TO_CLASS[$operation]) && is_subclass_of(self::$OPERATOR_TO_CLASS[$operation], 'SQLParser\Node\AbstractTwoOperandsOperator')) {
623-
$leftOperand = array_shift($operands);
624-
while (!empty($operands)) {
625-
$rightOperand = array_shift($operands);
626-
627-
$instance = new self::$OPERATOR_TO_CLASS[$operation]();
628-
$instance->setLeftOperand($leftOperand);
629-
$instance->setRightOperand($rightOperand);
630-
$leftOperand = $instance;
624+
if (count($operands) !== 2) {
625+
throw new MagicQueryParserException("Expected exactly 2 operands on ".self::$OPERATOR_TO_CLASS[$operation].". Found ".count($operands));
631626
}
632627

628+
$leftOperand = array_shift($operands);
629+
$rightOperand = array_shift($operands);
630+
$instance = new self::$OPERATOR_TO_CLASS[$operation]();
631+
$instance->setLeftOperand($leftOperand);
632+
$instance->setRightOperand($rightOperand);
633+
633634
return $instance;
634635
} elseif (isset(self::$OPERATOR_TO_CLASS[$operation]) && is_subclass_of(self::$OPERATOR_TO_CLASS[$operation], 'SQLParser\Node\AbstractManyInstancesOperator')) {
635636
$instance = new self::$OPERATOR_TO_CLASS[$operation]();

0 commit comments

Comments
 (0)