diff --git a/src/Expression.php b/src/Expression.php index bcf7d2dbb..c8bf44c00 100644 --- a/src/Expression.php +++ b/src/Expression.php @@ -94,10 +94,6 @@ public function __construct(protected array $expression) /** * Resolves an expression. * - * @param CompilationContext $compilationContext - * - * @return CompiledExpression - * * @throws CompilerException|Exception * @throws Exception * @throws ReflectionException diff --git a/src/Statements/LetStatement.php b/src/Statements/LetStatement.php index 8cc3558b6..ce7e9e040 100644 --- a/src/Statements/LetStatement.php +++ b/src/Statements/LetStatement.php @@ -45,8 +45,6 @@ use Zephir\Statements\Let\Variable as LetVariable; use Zephir\Statements\Let\VariableAppend as LetVariableAppend; -use function is_object; - /** * Let statement is used to assign variables */ @@ -59,9 +57,7 @@ class LetStatement extends StatementAbstract public function compile(CompilationContext $compilationContext): void { $readDetector = new ReadDetector(); - - $statement = $this->statement; - foreach ($statement['assignments'] as $assignment) { + foreach ($this->statement['assignments'] as $assignment) { $variable = $assignment['variable']; /** @@ -93,6 +89,7 @@ public function compile(CompilationContext $compilationContext): void /** * Incr/Decr assignments don't require an expression */ + $resolvedExpr = null; if (isset($assignment['expr'])) { /** * Replace on direct-assignment if this bitwise-assignment @@ -102,44 +99,23 @@ public function compile(CompilationContext $compilationContext): void $expr = new Expression($assignment['expr']); - switch ($assignment['assign-type']) { - case 'variable': - if (!$readDetector->detect($variable, $assignment['expr'])) { - if (isset($assignment['operator'])) { - if ('assign' == $assignment['operator']) { - $expr->setExpectReturn(true, $symbolVariable); - } - } else { - $expr->setExpectReturn(true, $symbolVariable); - } - } else { - if (isset($assignment['operator'])) { - if ('assign' == $assignment['operator']) { - $expr->setExpectReturn(true); - } - } else { - $expr->setExpectReturn(true); - } + if ($assignment['assign-type'] === 'variable') { + if (!$readDetector->detect($variable, $assignment['expr'])) { + if (!isset($assignment['operator']) || 'assign' === $assignment['operator']) { + $expr->setExpectReturn(true, $symbolVariable); } - break; + } else { + if (!isset($assignment['operator']) || 'assign' === $assignment['operator']) { + $expr->setExpectReturn(true); + } + } } - switch ($assignment['expr']['type']) { - case 'property-access': - case 'array-access': - case 'type-hint': - $expr->setReadOnly(true); - break; + if (in_array($assignment['expr']['type'], ['property-access', 'array-access', 'type-hint'])) { + $expr->setReadOnly(true); } $resolvedExpr = $expr->compile($compilationContext); - - /** - * Bad implemented operators could return values different from objects - */ - if (!is_object($resolvedExpr)) { - throw new CompilerException('Resolved expression is not valid', $assignment['expr']); - } } if ($symbolVariable) {