diff --git a/src/Config.php b/src/Config.php index c133ca5e6..8d19efaf1 100644 --- a/src/Config.php +++ b/src/Config.php @@ -254,13 +254,13 @@ public function jsonSerialize(): array /** * Allows to check whether a $key is defined. * - * @param mixed $key + * @param mixed $offset * * @return bool */ - public function offsetExists($key): bool + public function offsetExists($offset): bool { - return isset($this->container[$key]) || array_key_exists($key, $this->container); + return isset($this->container[$offset]) || array_key_exists($offset, $this->container); } /** @@ -294,40 +294,40 @@ public function offsetGet($offset) /** * Sets a configuration value. * - * @param mixed $key + * @param mixed $offset * @param mixed $value */ #[ReturnTypeWillChange] - public function offsetSet($key, $value): void + public function offsetSet($offset, $value): void { - if (!is_array($key)) { + if (!is_array($offset)) { $this->container[$key] = $value; return; } - $namespace = key($key); - $key = current($key); + $namespace = key($offset); + $offset = current($offset); if (!array_key_exists($namespace, $this->container)) { $this->container[$namespace] = []; } - $this->container[$namespace][$key] = $value; + $this->container[$namespace][$offset] = $value; } /** * Unsets a $key from internal container. * - * @param mixed $key + * @param mixed $offset * * @deprecated * */ #[ReturnTypeWillChange] - public function offsetUnset($key): void + public function offsetUnset($offset): void { - unset($this->container[$key]); + unset($this->container[$offset]); } /** diff --git a/src/Exception/CompilerException.php b/src/Exception/CompilerException.php index 7d31f7f34..716b89171 100644 --- a/src/Exception/CompilerException.php +++ b/src/Exception/CompilerException.php @@ -31,7 +31,11 @@ class CompilerException extends RuntimeException * @param int $code the Exception code [optional] * @param Exception|Throwable $previous the previous throwable used for the exception chaining [optional] */ - public function __construct(string $message = '', $extra = null, $code = 0, $previous = null) + public function __construct( + string $message = '', + ?array $extra = null, + int $code = 0, + Exception | Throwable $previous = null) { if (is_array($extra) && isset($extra['file'])) { $message .= ' in ' . $extra['file'] . ' on line ' . $extra['line']; @@ -129,7 +133,7 @@ public static function illegalOperationTypeOnStaticVariable( array $statement ): self { return new self( - "Operator '{$operator}' isn't supported for static variables and {$dataType} typed expressions", + "Operator '$operator' isn't supported for static variables and $dataType typed expressions", $statement ); } diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index ed87b9dd6..9861299cb 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -23,12 +23,12 @@ interface ExceptionInterface * * @return string */ - public function getErrorRegion(); + public function getErrorRegion(): string; /** * Gets extra info. * - * @return array + * @return array|null */ - public function getExtra(); + public function getExtra(): array | null; } diff --git a/src/Exception/ParseException.php b/src/Exception/ParseException.php index a35a32396..ae99a3858 100644 --- a/src/Exception/ParseException.php +++ b/src/Exception/ParseException.php @@ -31,8 +31,12 @@ class ParseException extends RuntimeException * @param int $code the Exception code [optional] * @param Exception|Throwable $previous the previous throwable used for the exception chaining [optional] */ - public function __construct($message = '', $extra = null, $code = 0, $previous = null) - { + public function __construct( + string $message = '', + ?array $extra = null, + int $code = 0, + Exception | Throwable $previous = null + ) { if (is_array($extra) && isset($extra['file'])) { $message .= ' in ' . $extra['file'] . ' on line ' . $extra['line']; } diff --git a/src/Operators/AbstractOperator.php b/src/Operators/AbstractOperator.php index 88778dc4e..eba8bf31c 100644 --- a/src/Operators/AbstractOperator.php +++ b/src/Operators/AbstractOperator.php @@ -106,7 +106,7 @@ public function getExpected(CompilationContext $compilationContext, array $expre * @param CompilationContext $compilationContext * @param string $type * - * @return Variable + * @return Variable|null */ public function getExpectedComplexLiteral( CompilationContext $compilationContext, diff --git a/src/Operators/Arithmetical/ArithmeticalBaseOperator.php b/src/Operators/Arithmetical/ArithmeticalBaseOperator.php index 9259884c0..11f33e5bb 100644 --- a/src/Operators/Arithmetical/ArithmeticalBaseOperator.php +++ b/src/Operators/Arithmetical/ArithmeticalBaseOperator.php @@ -141,7 +141,6 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; default: throw new CompilerException( @@ -149,7 +148,6 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; case 'bool': switch ($right->getType()) { @@ -178,7 +176,6 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; case 'double': switch ($right->getType()) { @@ -254,7 +251,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -262,14 +259,14 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'string': switch ($right->getType()) { default: throw new CompilerException('Operation is not supported between strings', $expression); } - break; + case 'variable': $variableLeft = $compilationContext->symbolTable->getVariableForRead( @@ -342,7 +339,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -350,7 +347,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'char': switch ($right->getType()) { @@ -403,7 +400,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -411,7 +408,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'bool': switch ($right->getType()) { @@ -481,7 +478,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -489,7 +486,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'double': switch ($right->getType()) { @@ -571,7 +568,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -579,7 +576,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'string': throw new CompilerException("Cannot operate string variables'", $expression); @@ -627,9 +624,8 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; } - break; + case 'variable': switch ($right->getType()) { @@ -657,7 +653,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + /* a(var) + a(x) */ case 'variable': @@ -686,7 +682,7 @@ public function compile($expression, CompilationContext $compilationContext) ), $expression ); - break; + /* a(var) + a(bool) */ case 'bool': @@ -699,7 +695,7 @@ public function compile($expression, CompilationContext $compilationContext) ) . ')', $expression ); - break; + /* a(var) + a(var) */ case 'variable': @@ -735,7 +731,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -743,12 +739,12 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException("Unknown '" . $variableLeft->getType() . "'", $expression); } - break; + default: throw new CompilerException('Unsupported type: ' . $left->getType(), $expression); diff --git a/src/Operators/Arithmetical/DivOperator.php b/src/Operators/Arithmetical/DivOperator.php index ec8230bb9..8d0f83f4a 100644 --- a/src/Operators/Arithmetical/DivOperator.php +++ b/src/Operators/Arithmetical/DivOperator.php @@ -120,7 +120,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -128,7 +128,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'bool': switch ($right->getType()) { @@ -157,7 +157,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'double': switch ($right->getType()) { @@ -221,7 +221,7 @@ public function compile($expression, CompilationContext $compilationContext) 'zephir_safe_div_double_zval(' . $left->getCode() . ', ' . $symbolRight . ')', $expression ); - break; + default: throw new CompilerException( @@ -230,7 +230,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -238,7 +238,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'string': case 'array': @@ -249,7 +249,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'variable': $variableLeft = $compilationContext->symbolTable->getVariableForRead( @@ -328,7 +328,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -337,7 +337,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -345,7 +345,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'bool': switch ($right->getType()) { @@ -422,7 +422,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -431,7 +431,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -439,7 +439,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'double': switch ($right->getType()) { @@ -514,7 +514,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -522,7 +522,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'string': throw new CompilerException("Cannot operate string variables'", $expression); @@ -616,7 +616,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -624,7 +624,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'variable': $op1 = $compilationContext->backend->getVariableCode($variableLeft); @@ -731,7 +731,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -740,7 +740,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -748,12 +748,12 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException("Unknown '" . $variableLeft->getType() . "'", $expression); } - break; + default: throw new CompilerException('Unsupported type: ' . $left->getType(), $expression); diff --git a/src/Operators/Arithmetical/ModOperator.php b/src/Operators/Arithmetical/ModOperator.php index 0299836fc..014a1c31c 100644 --- a/src/Operators/Arithmetical/ModOperator.php +++ b/src/Operators/Arithmetical/ModOperator.php @@ -121,7 +121,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -129,7 +129,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -137,7 +137,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'bool': switch ($right->getType()) { @@ -166,7 +166,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'double': switch ($right->getType()) { @@ -238,7 +238,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -248,7 +248,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -256,7 +256,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'string': case 'array': @@ -267,7 +267,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'variable': $variableLeft = $compilationContext->symbolTable->getVariableForRead( @@ -341,7 +341,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -351,7 +351,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -359,7 +359,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'bool': switch ($right->getType()) { @@ -449,7 +449,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -459,7 +459,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -467,7 +467,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'double': switch ($right->getType()) { @@ -541,7 +541,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -550,7 +550,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -558,7 +558,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'string': case 'array': @@ -581,7 +581,7 @@ public function compile($expression, CompilationContext $compilationContext) 'zephir_safe_mod_zval_long(' . $op1 . ', ' . $op2 . ')', $expression ); - break; + case 'double': $op2 = $right->getCode(); @@ -591,7 +591,7 @@ public function compile($expression, CompilationContext $compilationContext) 'zephir_safe_mod_zval_double(' . $op1 . ', ' . $op2 . ')', $expression ); - break; + /* a(var) + a(x) */ case 'variable': @@ -612,7 +612,7 @@ public function compile($expression, CompilationContext $compilationContext) ) . ')', $expression ); - break; + /* a(var) + a(bool) */ case 'bool': @@ -622,7 +622,7 @@ public function compile($expression, CompilationContext $compilationContext) ) . ')', $expression ); - break; + /* a(var) + a(var) */ case 'variable': @@ -655,7 +655,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -663,7 +663,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'variable': $op1 = $compilationContext->backend->getVariableCode($variableLeft); @@ -709,7 +709,7 @@ public function compile($expression, CompilationContext $compilationContext) ) . ')', $expression ); - break; + case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead( @@ -763,7 +763,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -772,7 +772,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -780,7 +780,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -788,7 +788,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( diff --git a/src/Operators/Bitwise/BitwiseBaseOperator.php b/src/Operators/Bitwise/BitwiseBaseOperator.php index 78aca6733..753492c09 100644 --- a/src/Operators/Bitwise/BitwiseBaseOperator.php +++ b/src/Operators/Bitwise/BitwiseBaseOperator.php @@ -125,7 +125,7 @@ public function compile($expression, CompilationContext $compilationContext) ) . ' ' . $this->operator . ' zephir_get_numberval(' . $symbol . '))', $expression ); - break; + default: throw new CompilerException( @@ -133,14 +133,14 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( "Cannot operate 'int' with '" . $right->getType() . "'", $expression ); } - break; + case 'bool': switch ($right->getType()) { @@ -201,7 +201,7 @@ public function compile($expression, CompilationContext $compilationContext) ) . ') ' . $this->operator . ' zephir_get_numberval(' . $symbol . '))', $expression ); - break; + default: throw new CompilerException( @@ -209,7 +209,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -217,7 +217,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'double': switch ($right->getType()) { @@ -284,7 +284,7 @@ public function compile($expression, CompilationContext $compilationContext) ) . ') ' . $this->operator . ' zephir_get_numberval(' . $symbol . '))', $expression ); - break; + default: throw new CompilerException( @@ -293,7 +293,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -301,14 +301,14 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'string': switch ($right->getType()) { default: throw new CompilerException('Operation is not supported between strings', $expression); } - break; + case 'variable': $variableLeft = $compilationContext->symbolTable->getVariableForRead( @@ -376,7 +376,7 @@ public function compile($expression, CompilationContext $compilationContext) ) . ' ' . $this->operator . ' (int) (zephir_get_numberval(' . $symbol . ')))', $expression ); - break; + default: throw new CompilerException( @@ -385,7 +385,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -393,7 +393,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'bool': switch ($right->getType()) { @@ -459,7 +459,7 @@ public function compile($expression, CompilationContext $compilationContext) ) . ' ' . $this->operator . ' zephir_get_numberval(' . $symbol . '))', $expression ); - break; + default: throw new CompilerException( @@ -468,7 +468,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -476,7 +476,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'double': switch ($right->getType()) { @@ -551,7 +551,6 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); - break; default: throw new CompilerException( @@ -560,7 +559,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -568,7 +567,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + case 'string': throw new CompilerException("Cannot operate string variables'", $expression); @@ -597,7 +596,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + /* a(var) + a(x) */ case 'variable': @@ -621,7 +620,7 @@ public function compile($expression, CompilationContext $compilationContext) ) . ')', $expression ); - break; + /* a(var) + a(bool) */ case 'bool': @@ -633,7 +632,7 @@ public function compile($expression, CompilationContext $compilationContext) ) . ')', $expression ); - break; + /* a(var) + a(var) */ case 'variable': @@ -663,7 +662,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException( @@ -671,12 +670,12 @@ public function compile($expression, CompilationContext $compilationContext) $expression ); } - break; + default: throw new CompilerException("Unknown '" . $variableLeft->getType() . "'", $expression); } - break; + default: throw new CompilerException('Unsupported type: ' . $left->getType(), $expression); @@ -712,7 +711,6 @@ public function optimizeConstantFolding( break; default: return null; - break; } switch ($expression['right']['type']) { @@ -725,7 +723,6 @@ public function optimizeConstantFolding( break; default: return null; - break; } /* diff --git a/src/Operators/Bitwise/BitwiseNotOperator.php b/src/Operators/Bitwise/BitwiseNotOperator.php index 09341a2a1..4dc3cbe46 100644 --- a/src/Operators/Bitwise/BitwiseNotOperator.php +++ b/src/Operators/Bitwise/BitwiseNotOperator.php @@ -74,7 +74,6 @@ public function compile($expression, CompilationContext $compilationContext) default: throw new CompilerException('Unknown type: ' . $variable->getType(), $expression); } - break; default: throw new CompilerException('Unknown type: ' . $left->getType(), $expression); diff --git a/src/Operators/Comparison/ComparisonBaseOperator.php b/src/Operators/Comparison/ComparisonBaseOperator.php index b1fb74370..8a6cdf309 100644 --- a/src/Operators/Comparison/ComparisonBaseOperator.php +++ b/src/Operators/Comparison/ComparisonBaseOperator.php @@ -128,12 +128,12 @@ public function compile(array $expression, CompilationContext $compilationContex $expression['right'] ); } - break; + default: throw new CompilerException('Unknown type: ' . $right->getType(), $expression); } - break; + case 'int': case 'uint': @@ -208,7 +208,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression['right'] ); } - break; + default: throw new CompilerException( @@ -216,7 +216,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression ); } - break; + case 'bool': switch ($right->getType()) { @@ -297,7 +297,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression['right'] ); } - break; + default: throw new CompilerException( @@ -305,7 +305,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression ); } - break; + case 'string': $variableLeft = $compilationContext->symbolTable->getTempLocalVariableForWrite( @@ -326,7 +326,7 @@ public function compile(array $expression, CompilationContext $compilationContex $this->zvalNullOperator . '(' . $variableLeftCode . ')', $expression['left'] ); - break; + case 'string': $compilationContext->headersManager->add('kernel/operators'); @@ -336,7 +336,7 @@ public function compile(array $expression, CompilationContext $compilationContex $this->zvalStringOperator . '(' . $variableLeftCode . ', "' . $right->getCode() . '")', $expression['left'] ); - break; + case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead( @@ -356,7 +356,7 @@ public function compile(array $expression, CompilationContext $compilationContex $this->zvalOperator . '(' . $variableLeftCode . ', ' . $variableRight . ')', $expression ); - break; + default: throw new CompilerException( @@ -364,12 +364,12 @@ public function compile(array $expression, CompilationContext $compilationContex $expression['right'] ); } - break; + default: throw new CompilerException('Unknown type: ' . $right->getType(), $expression['left']); } - break; + case 'variable': $variable = $compilationContext->symbolTable->getVariableForRead( @@ -446,7 +446,7 @@ public function compile(array $expression, CompilationContext $compilationContex $this->zvalLongNegOperator . '(' . $variableRightCode . ', ' . $variableCode . ')', $expression ); - break; + default: throw new CompilerException( @@ -454,7 +454,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression['right'] ); } - break; + default: throw new CompilerException( @@ -462,7 +462,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression ); } - break; + case 'double': switch ($right->getType()) { @@ -531,7 +531,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression['right'] ); } - break; + default: throw new CompilerException( @@ -539,7 +539,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression ); } - break; + case 'bool': switch ($right->getType()) { @@ -606,7 +606,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression['right'] ); } - break; + default: throw new CompilerException( @@ -614,7 +614,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression ); } - break; + case 'array': switch ($right->getType()) { @@ -651,12 +651,12 @@ public function compile(array $expression, CompilationContext $compilationContex $expression['right'] ); } - break; + default: throw new CompilerException('Unknown type: ' . $right->getType(), $expression['left']); } - break; + case 'string': $compilationContext->headersManager->add('kernel/operators'); @@ -701,12 +701,12 @@ public function compile(array $expression, CompilationContext $compilationContex $expression['right'] ); } - break; + default: throw new CompilerException('Unknown type: ' . $right->getType(), $expression['left']); } - break; + case 'variable': case 'mixed': @@ -810,17 +810,17 @@ public function compile(array $expression, CompilationContext $compilationContex $expression['right'] ); } - break; + default: throw new CompilerException('Unknown type: ' . $right->getType(), $expression['left']); } - break; + default: throw new CompilerException('Unknown type: ' . $variable->getType(), $expression); } - break; + default: throw new CompilerException('Unknown type: ' . $left->getType(), $expression); @@ -885,69 +885,40 @@ public function optimizeTypeOf(array $expr, CompilationContext $compilationConte switch ($variableVariable->getType()) { case 'double': - switch ($value) { - case 'double': - case 'float': - $condition = '1 ' . $operator . ' 1'; - break; - - default: - $condition = '1 ' . $operator . ' 0'; - break; - } + $condition = match ($value) { + 'double', 'float' => '1 ' . $operator . ' 1', + default => '1 ' . $operator . ' 0', + }; break; case 'int': case 'integer': case 'long': - switch ($value) { - case 'int': - case 'integer': - case 'long': - $condition = '1 ' . $operator . ' 1'; - break; - - default: - $condition = '1 ' . $operator . ' 0'; - break; - } + $condition = match ($value) { + 'int', 'integer', 'long' => '1 ' . $operator . ' 1', + default => '1 ' . $operator . ' 0', + }; break; case 'bool': - switch ($value) { - case 'bool': - case 'boolean': - $condition = '1 ' . $operator . ' 1'; - break; - - default: - $condition = '1 ' . $operator . ' 0'; - break; - } + $condition = match ($value) { + 'bool', 'boolean' => '1 ' . $operator . ' 1', + default => '1 ' . $operator . ' 0', + }; break; case 'array': - switch ($value) { - case 'array': - $condition = '1 ' . $operator . ' 1'; - break; - - default: - $condition = '1 ' . $operator . ' 0'; - break; - } + $condition = match ($value) { + 'array' => '1 ' . $operator . ' 1', + default => '1 ' . $operator . ' 0', + }; break; case 'string': - switch ($value) { - case 'string': - $condition = '1 ' . $operator . ' 1'; - break; - - default: - $condition = '1 ' . $operator . ' 0'; - break; - } + $condition = match ($value) { + 'string' => '1 ' . $operator . ' 1', + default => '1 ' . $operator . ' 0', + }; break; case 'variable': diff --git a/src/Operators/Logical/LogicalBaseOperator.php b/src/Operators/Logical/LogicalBaseOperator.php index 9c8f971a4..72fe54b1a 100644 --- a/src/Operators/Logical/LogicalBaseOperator.php +++ b/src/Operators/Logical/LogicalBaseOperator.php @@ -95,7 +95,7 @@ public function compile($expression, CompilationContext $compilationContext): Co $expression ); } - break; + default: throw new CompilerException( @@ -103,7 +103,7 @@ public function compile($expression, CompilationContext $compilationContext): Co $expression ); } - break; + case 'bool': switch ($right->getType()) { @@ -156,7 +156,7 @@ public function compile($expression, CompilationContext $compilationContext): Co $expression ); } - break; + default: throw new CompilerException( @@ -164,7 +164,7 @@ public function compile($expression, CompilationContext $compilationContext): Co $expression ); } - break; + case 'double': switch ($right->getType()) { case 'double': @@ -188,11 +188,11 @@ public function compile($expression, CompilationContext $compilationContext): Co $expression ); } - break; + case 'string': throw new CompilerException('Operation is not supported between strings', $expression); - break; + case 'variable': $variableLeft = $compilationContext->symbolTable->getVariableForRead( @@ -246,7 +246,7 @@ public function compile($expression, CompilationContext $compilationContext): Co $expression ); } - break; + default: throw new CompilerException( @@ -254,7 +254,7 @@ public function compile($expression, CompilationContext $compilationContext): Co $expression ); } - break; + case 'bool': switch ($right->getType()) { @@ -313,7 +313,7 @@ public function compile($expression, CompilationContext $compilationContext): Co $expression ); } - break; + default: throw new CompilerException( @@ -321,7 +321,7 @@ public function compile($expression, CompilationContext $compilationContext): Co $expression ); } - break; + case 'double': switch ($right->getType()) { @@ -388,7 +388,7 @@ public function compile($expression, CompilationContext $compilationContext): Co $expression ); } - break; + default: throw new CompilerException( @@ -396,7 +396,7 @@ public function compile($expression, CompilationContext $compilationContext): Co $expression ); } - break; + case 'string': switch ($right->getType()) { @@ -475,7 +475,7 @@ public function compile($expression, CompilationContext $compilationContext): Co $expression ); } - break; + default: throw new CompilerException( @@ -483,7 +483,7 @@ public function compile($expression, CompilationContext $compilationContext): Co $expression ); } - break; + case 'variable': $variableLeftCode = $compilationContext->backend->getVariableCode($variableLeft); @@ -553,7 +553,7 @@ public function compile($expression, CompilationContext $compilationContext): Co $expression ); } - break; + default: throw new CompilerException( @@ -561,12 +561,12 @@ public function compile($expression, CompilationContext $compilationContext): Co $expression ); } - break; + default: throw new CompilerException("Unknown '" . $variableLeft->getType() . "'", $expression); } - break; + default: throw new CompilerException('Unsupported type: ' . $left->getType(), $expression); diff --git a/src/Operators/Other/CastOperator.php b/src/Operators/Other/CastOperator.php index b812214bf..b0f6dc554 100644 --- a/src/Operators/Other/CastOperator.php +++ b/src/Operators/Other/CastOperator.php @@ -156,7 +156,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression ); } - break; + default: throw new CompilerException( @@ -164,7 +164,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression ); } - break; + case Types::T_LONG: switch ($resolved->getType()) { @@ -240,7 +240,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression ); } - break; + default: throw new CompilerException( @@ -248,7 +248,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression ); } - break; + case Types::T_DOUBLE: switch ($resolved->getType()) { @@ -334,7 +334,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression ); } - break; + default: throw new CompilerException( @@ -342,7 +342,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression ); } - break; + case Types::T_BOOL: switch ($resolved->getType()) { @@ -376,36 +376,31 @@ public function compile(array $expression, CompilationContext $compilationContex if ($symbolVariable->isTemporal()) { $symbolVariable->setIdle(true); } - switch ($symbolVariable->getType()) { - case Types::T_INT: - case Types::T_CHAR: - case Types::T_UCHAR: - return new CompiledExpression( - 'bool', - sprintf('(zend_bool) %s', $symbolVariable->getName()), - $expression - ); - - case Types::T_VARIABLE: - case Types::T_MIXED: - return new CompiledExpression( - 'bool', - sprintf('zephir_get_boolval(%s)', $symbol), - $expression - ); + return match ($symbolVariable->getType()) { + Types::T_INT, + Types::T_CHAR, + Types::T_UCHAR => new CompiledExpression( + 'bool', + sprintf('(zend_bool) %s', $symbolVariable->getName()), + $expression + ), + Types::T_VARIABLE, + Types::T_MIXED => new CompiledExpression( + 'bool', + sprintf('zephir_get_boolval(%s)', $symbol), + $expression + ), + default => throw new CompilerException( + sprintf( + 'Cannot cast: %s(%s) to %s', + $resolved->getType(), + $symbolVariable->getType(), + $expression['left'] + ), + $expression + ), + }; - default: - throw new CompilerException( - sprintf( - 'Cannot cast: %s(%s) to %s', - $resolved->getType(), - $symbolVariable->getType(), - $expression['left'] - ), - $expression - ); - } - break; default: throw new CompilerException( @@ -413,7 +408,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression ); } - break; + case Types::T_CHAR: switch ($resolved->getType()) { @@ -462,7 +457,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression ); } - break; + case Types::T_STRING: switch ($resolved->getType()) { @@ -530,14 +525,14 @@ public function compile(array $expression, CompilationContext $compilationContex ); } - break; + default: throw new CompilerException( sprintf('Cannot cast: %s to %s', $resolved->getType(), $expression['left']), $expression ); } - break; + case Types::T_ARRAY: switch ($resolved->getType()) { @@ -577,7 +572,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression ); } - break; + case Types::T_OBJECT: switch ($resolved->getType()) { @@ -638,7 +633,7 @@ public function compile(array $expression, CompilationContext $compilationContex $expression ); } - break; + default: throw new CompilerException( diff --git a/src/Operators/Other/FetchOperator.php b/src/Operators/Other/FetchOperator.php index a22b55a74..eb4e11896 100644 --- a/src/Operators/Other/FetchOperator.php +++ b/src/Operators/Other/FetchOperator.php @@ -134,7 +134,6 @@ public function compile(array $expression, CompilationContext $compilationContex $expression, $compilationContext ); - break; case 'property-access': $exprVariable = new Expression($expression['right']['left']); diff --git a/src/Operators/Other/IssetOperator.php b/src/Operators/Other/IssetOperator.php index 43a31afd6..4c96265ba 100644 --- a/src/Operators/Other/IssetOperator.php +++ b/src/Operators/Other/IssetOperator.php @@ -72,7 +72,6 @@ public function compile(array $expression, CompilationContext $compilationContex 'Variable type: ' . $variable->getType() . ' cannot be used as array', $left['left'] ); - break; } if ('variable' === $variable->getType()) { @@ -114,12 +113,12 @@ public function compile(array $expression, CompilationContext $compilationContex $left['right'], $compilationContext ); - break; + default: throw new CompilerException('[' . $left['right']['type'] . ']', $expression); } - break; + case 'property-access': case 'property-dynamic-access': @@ -187,12 +186,12 @@ public function compile(array $expression, CompilationContext $compilationContex default: throw new CompilerException('[' . $indexVariable->getType() . ']', $expression); } - break; + default: throw new CompilerException('[' . $expression['left']['right']['type'] . ']', $expression); } - break; + case 'property-string-access': case 'static-property-access': diff --git a/src/Operators/Unary/MinusOperator.php b/src/Operators/Unary/MinusOperator.php index 68706cd46..1de04b35a 100644 --- a/src/Operators/Unary/MinusOperator.php +++ b/src/Operators/Unary/MinusOperator.php @@ -73,7 +73,6 @@ public function compile($expression, CompilationContext $compilationContext): Co "Cannot operate minus with variable of '" . $left->getType() . "' type" ); } - break; default: throw new CompilerException("Cannot operate minus with '" . $left->getType() . "' type"); diff --git a/src/Operators/Unary/NotOperator.php b/src/Operators/Unary/NotOperator.php index 780b3fd25..2d4078714 100644 --- a/src/Operators/Unary/NotOperator.php +++ b/src/Operators/Unary/NotOperator.php @@ -71,7 +71,6 @@ public function compile($expression, CompilationContext $compilationContext): Co default: throw new CompilerException('Unknown type: ' . $variable->getType(), $expression); } - break; default: throw new CompilerException('Unknown type: ' . $left->getType(), $expression);