diff --git a/src/Statements/BreakStatement.php b/src/Statements/BreakStatement.php index 3f6ea3d9f..ba26bccef 100644 --- a/src/Statements/BreakStatement.php +++ b/src/Statements/BreakStatement.php @@ -19,8 +19,6 @@ class BreakStatement extends StatementAbstract { /** - * @param CompilationContext $compilationContext - * * @throws CompilerException */ public function compile(CompilationContext $compilationContext): void diff --git a/src/Statements/DeclareStatement.php b/src/Statements/DeclareStatement.php index b0ec7bb6c..57e7424e0 100644 --- a/src/Statements/DeclareStatement.php +++ b/src/Statements/DeclareStatement.php @@ -13,7 +13,9 @@ namespace Zephir\Statements; +use ReflectionException; use Zephir\CompilationContext; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression\Builder\BuilderFactory; @@ -25,28 +27,25 @@ class DeclareStatement extends StatementAbstract { /** - * @param CompilationContext $compilationContext - * - * @throws CompilerException + * @throws ReflectionException + * @throws Exception */ public function compile(CompilationContext $compilationContext): void { - $statement = $this->statement; - - if (!isset($statement['data-type'])) { + if (!isset($this->statement['data-type'])) { throw new CompilerException('Data type is required', $this->statement); } $typeInference = $compilationContext->typeInference; $symbolTable = $compilationContext->symbolTable; - foreach ($statement['variables'] as $variable) { + foreach ($this->statement['variables'] as $variable) { $varName = $variable['variable']; if ($symbolTable->hasVariableInBranch($varName, $compilationContext->branchManager->getCurrentBranch())) { throw new CompilerException("Variable '" . $varName . "' is already defined", $variable); } - $currentType = $statement['data-type']; + $currentType = $this->statement['data-type']; /** * Replace original data type by the pre-processed infered type diff --git a/src/Statements/DoWhileStatement.php b/src/Statements/DoWhileStatement.php index 5f3838084..1cedab593 100644 --- a/src/Statements/DoWhileStatement.php +++ b/src/Statements/DoWhileStatement.php @@ -25,8 +25,6 @@ class DoWhileStatement extends StatementAbstract { /** - * @param CompilationContext $compilationContext - * * @throws ReflectionException * @throws Exception */ diff --git a/src/Statements/EchoStatement.php b/src/Statements/EchoStatement.php index df203af1e..087cb9b89 100644 --- a/src/Statements/EchoStatement.php +++ b/src/Statements/EchoStatement.php @@ -26,8 +26,6 @@ class EchoStatement extends StatementAbstract { /** - * @param CompilationContext $compilationContext - * * @throws ReflectionException * @throws Exception */ diff --git a/src/Statements/ForStatement.php b/src/Statements/ForStatement.php index 57bd6a11c..e9ef2d638 100644 --- a/src/Statements/ForStatement.php +++ b/src/Statements/ForStatement.php @@ -34,8 +34,6 @@ class ForStatement extends StatementAbstract { /** - * @param CompilationContext $compilationContext - * * @throws Exception * @throws ReflectionException */ @@ -105,9 +103,6 @@ public function compile(CompilationContext $compilationContext): void * - Evaluated expression must be a zval * - A key must be a zval * - A value must be a zval - * - * @param CompilationContext $compilationContext - * @param Variable $exprVariable */ public function compileHashTraverse( CompilationContext $compilationContext, @@ -231,11 +226,6 @@ public function compileHashTraverse( /** * Compiles a 'for' statement that use an 'iterator' as expression. * - * @param array $exprRaw - * @param CompilationContext $compilationContext - * - * @return void - * * @throws Exception * @throws ReflectionException */ @@ -399,11 +389,6 @@ public function compileIterator(array $exprRaw, CompilationContext $compilationC /** * Compiles a for statement that use a 'range' as expression. * - * @param array $exprRaw - * @param CompilationContext $compilationContext - * - * @return bool - * * @throws ReflectionException * @throws Exception */ @@ -908,10 +893,6 @@ public function compileStringTraverse( } /** - * @param CompilationContext $compilationContext - * @param Printer|null $codePrinter - * - * @return void * @throws Exception * @throws ReflectionException */ @@ -938,11 +919,8 @@ private function compileStatementsForBlock( } /** - * @param mixed $keyVariableName - * @param Variable $keyVariable - * @param CompilationContext $compilationContext - * - * @return void + * @throws Exception + * @throws ReflectionException */ private function getLetStatement( mixed $keyVariableName, diff --git a/src/Statements/IfStatement.php b/src/Statements/IfStatement.php index 3e6574848..82c8bc40d 100644 --- a/src/Statements/IfStatement.php +++ b/src/Statements/IfStatement.php @@ -30,8 +30,6 @@ class IfStatement extends StatementAbstract { /** - * @param CompilationContext $compilationContext - * * @throws ReflectionException * @throws Exception */ diff --git a/src/Statements/Let/ArrayIndex.php b/src/Statements/Let/ArrayIndex.php index 0aa4c4eb1..6403aa79e 100644 --- a/src/Statements/Let/ArrayIndex.php +++ b/src/Statements/Let/ArrayIndex.php @@ -13,6 +13,7 @@ namespace Zephir\Statements\Let; +use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; @@ -26,8 +27,6 @@ use function sprintf; /** - * ArrayIndex. - * * Adds/Updates an array index */ class ArrayIndex @@ -37,13 +36,8 @@ class ArrayIndex /** * Compiles foo[y] = {expr}. * - * @param string $variable - * @param ZephirVariable $symbolVariable - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext - * @param array $statement - * - * @throws CompilerException + * @throws Exception + * @throws ReflectionException */ public function assign( $variable, @@ -52,14 +46,14 @@ public function assign( CompilationContext $compilationContext, $statement ): void { - /* + /** * Arrays must be stored in the HEAP */ $this->checkVariableInitialized($variable, $symbolVariable, $statement); $this->checkVariableReadOnly($variable, $symbolVariable, $statement); $this->checkVariableLocalOnly($variable, $symbolVariable, $statement); - /* + /** * Only dynamic variables can be used as arrays */ if ($symbolVariable->isNotVariableAndArray()) { @@ -74,7 +68,7 @@ public function assign( throw CompilerException::cannotUseNonInitializedVariableAsObject($statement); } - /* + /** * Trying to use a non-object dynamic variable as object */ if ($symbolVariable->hasDifferentDynamicType(['undefined', 'array', 'null'])) { @@ -85,15 +79,14 @@ public function assign( } } - /* + /** * Choose one-offset or multiple-offset functions */ - if (1 == count($statement['index-expr'])) { + if (1 === count($statement['index-expr'])) { $this->_assignArrayIndexSingle($symbolVariable, $resolvedExpr, $compilationContext, $statement); } else { - $this->_assignArrayIndexMultiple( + $this->assignArrayIndexMultiple( $variable, - $symbolVariable, $resolvedExpr, $compilationContext, $statement @@ -104,21 +97,14 @@ public function assign( /** * Compiles foo[y][x] = {expr} (multiple offset). * - * @param string $variable - * @param ZephirVariable $symbolVariable - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext - * @param array $statement - * - * @throws CompilerException * @throws Exception + * @throws ReflectionException */ - protected function _assignArrayIndexMultiple( + protected function assignArrayIndexMultiple( $variable, - ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, - $statement + $statement, ): void { $offsetExprs = []; @@ -174,12 +160,8 @@ protected function _assignArrayIndexMultiple( /** * Compiles foo[y] = {expr} (one offset). * - * @param ZephirVariable $symbolVariable - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext - * @param array $statement - * - * @throws CompilerException + * @throws Exception + * @throws ReflectionException */ protected function _assignArrayIndexSingle( ZephirVariable $symbolVariable, diff --git a/src/Statements/Let/ArrayIndexAppend.php b/src/Statements/Let/ArrayIndexAppend.php index 4aca7cbbc..648e02c46 100644 --- a/src/Statements/Let/ArrayIndexAppend.php +++ b/src/Statements/Let/ArrayIndexAppend.php @@ -13,15 +13,15 @@ namespace Zephir\Statements\Let; +use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Variable\Variable as ZephirVariable; /** - * ArrayIndexAppend. - * * Adds/Updates an array index */ class ArrayIndexAppend extends ArrayIndex @@ -29,13 +29,8 @@ class ArrayIndexAppend extends ArrayIndex /** * Compiles foo[y][] = {expr}. * - * @param string $variable - * @param ZephirVariable $symbolVariable - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext - * @param array $statement - * - * @throws CompilerException + * @throws Exception + * @throws ReflectionException */ public function assign( $variable, @@ -44,14 +39,14 @@ public function assign( CompilationContext $compilationContext, $statement ): void { - /* + /** * Arrays must be stored in the HEAP */ $this->checkVariableInitialized($variable, $symbolVariable, $statement); $this->checkVariableReadOnly($variable, $symbolVariable, $statement); $this->checkVariableLocalOnly($variable, $symbolVariable, $statement); - /* + /** * Only dynamic variables and arrays can be used as arrays */ if ($symbolVariable->isNotVariableAndArray()) { @@ -65,7 +60,7 @@ public function assign( throw CompilerException::cannotUseNonInitializedVariableAsObject($statement); } - /* + /** * Trying to use a non-object dynamic variable as object */ if ($symbolVariable->hasDifferentDynamicType(['undefined', 'array', 'null'])) { @@ -75,46 +70,35 @@ public function assign( ); } - $this->_assignArrayIndexMultiple($variable, $symbolVariable, $resolvedExpr, $compilationContext, $statement); + $this->assignArrayIndexMultiple($variable, $resolvedExpr, $compilationContext, $statement); } /** * Compiles foo[y][x][] = {expr} (multiple offset). * - * @param string $variable - * @param ZephirVariable $symbolVariable - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext - * @param array $statement + * @throws Exception + * @throws ReflectionException */ - protected function _assignArrayIndexMultiple( + protected function assignArrayIndexMultiple( $variable, - ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, $statement ): void { $offsetExprs = []; + $types = ['int', 'uint', 'long', 'ulong', 'string', 'variable']; foreach ($statement['index-expr'] as $indexExpr) { $expression = new Expression($indexExpr); $expression->setReadOnly(true); $exprIndex = $expression->compile($compilationContext); - switch ($exprIndex->getType()) { - case 'int': - case 'uint': - case 'long': - case 'ulong': - case 'string': - case 'variable': - break; - default: - throw new CompilerException( - 'Index: ' - . $exprIndex->getType() - . ' cannot be used as array index in assignment without cast', - $indexExpr - ); + if (!in_array($exprIndex->getType(), $types)) { + throw new CompilerException( + 'Index: ' + . $exprIndex->getType() + . ' cannot be used as array index in assignment without cast', + $indexExpr + ); } $offsetExprs[] = $exprIndex; diff --git a/src/Statements/Let/ExportSymbolString.php b/src/Statements/Let/ExportSymbolString.php index 2d7cbb28c..4fda2a614 100644 --- a/src/Statements/Let/ExportSymbolString.php +++ b/src/Statements/Let/ExportSymbolString.php @@ -18,8 +18,6 @@ use Zephir\Variable\Variable as ZephirVariable; /** - * ExportSymbolString. - * * Exports a symbol to the current PHP symbol table using a variable as parameter */ class ExportSymbolString extends ExportSymbol @@ -27,16 +25,6 @@ class ExportSymbolString extends ExportSymbol /** * Compiles {"var"} = {expr}. */ - - /** - * @param CompilationContext|null $compilationContext - * @param ZephirVariable|null $symbolVariable - * @param ZephirVariable $variable - * @param Printer|null $codePrinter - * @param array|null $statement - * - * @return void - */ protected function getOutput( ?CompilationContext $compilationContext, ?ZephirVariable $symbolVariable, diff --git a/src/Statements/Let/Incr.php b/src/Statements/Let/Incr.php index 801c3fc30..b63f04ccd 100644 --- a/src/Statements/Let/Incr.php +++ b/src/Statements/Let/Incr.php @@ -14,8 +14,6 @@ namespace Zephir\Statements\Let; /** - * Incr. - * * Increments a variable */ class Incr extends Decr diff --git a/src/Statements/Let/ObjectDynamicProperty.php b/src/Statements/Let/ObjectDynamicProperty.php index 798727b70..c9a3f2c71 100644 --- a/src/Statements/Let/ObjectDynamicProperty.php +++ b/src/Statements/Let/ObjectDynamicProperty.php @@ -30,12 +30,6 @@ class ObjectDynamicProperty /** * Compiles foo->{x} = {expr}. * - * @param string $variable - * @param ZephirVariable $symbolVariable - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext - * @param array $statement - * * @throws CompilerException * @throws Exception */ diff --git a/src/Statements/Let/ObjectDynamicStringProperty.php b/src/Statements/Let/ObjectDynamicStringProperty.php index 4ec9aff49..069f31729 100644 --- a/src/Statements/Let/ObjectDynamicStringProperty.php +++ b/src/Statements/Let/ObjectDynamicStringProperty.php @@ -33,12 +33,6 @@ class ObjectDynamicStringProperty /** * Compiles foo->{"x"} = {expr}. * - * @param string $variable - * @param ZephirVariable $symbolVariable - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext - * @param array $statement - * * @throws CompilerException * @throws Exception */ @@ -75,14 +69,6 @@ public function assign( ); } - if ('variable' != $symbolVariable->getType()) { - throw CompilerException::cannotUseVariableTypeAs( - $symbolVariable, - 'as an object', - $statement - ); - } - if ($symbolVariable->hasAnyDynamicType('unknown')) { throw CompilerException::cannotUseNonInitializedVariableAsObject($statement); } diff --git a/src/Statements/Let/ObjectProperty.php b/src/Statements/Let/ObjectProperty.php index 482e21b13..2180d882e 100644 --- a/src/Statements/Let/ObjectProperty.php +++ b/src/Statements/Let/ObjectProperty.php @@ -31,14 +31,6 @@ class ObjectProperty /** * Compiles foo->x = {expr}. - * - * @param string $variable - * @param ZephirVariable $symbolVariable - * @param Expression $expression - * @param Context $context - * @param array $statement - * - * @return void */ public function assign( string $variable, @@ -86,7 +78,7 @@ public function assign( throw CompilerException::cannotUseNonInitializedVariableAsObject($statement); } - /* + /** * Trying to use a non-object dynamic variable as object */ if ($symbolVariable->hasDifferentDynamicType(['undefined', 'object'])) { @@ -96,7 +88,7 @@ public function assign( ); } - /* + /** * Try to check if property is implemented on related object */ if ('this' == $variable) { diff --git a/src/Statements/Let/ObjectPropertyAppend.php b/src/Statements/Let/ObjectPropertyAppend.php index b63edad37..807d90c48 100644 --- a/src/Statements/Let/ObjectPropertyAppend.php +++ b/src/Statements/Let/ObjectPropertyAppend.php @@ -22,8 +22,6 @@ use function current; /** - * ObjectPropertyAppend. - * * Appends a value to a property */ class ObjectPropertyAppend @@ -33,12 +31,6 @@ class ObjectPropertyAppend /** * Compiles x->y[] = foo. * - * @param string $variable - * @param ZephirVariable $symbolVariable - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext - * @param array $statement - * * @throws CompilerException */ public function assign( @@ -63,7 +55,7 @@ public function assign( $compilationContext->headersManager->add('kernel/object'); - /* + /** * Check if the variable to update is defined */ if ('this' == $symbolVariable->getRealName()) { @@ -74,7 +66,7 @@ public function assign( $statement ); } else { - /* + /** * If we know the class related to a variable we could check if the property * is defined on that class */ diff --git a/src/Statements/Let/ObjectPropertyArrayIndex.php b/src/Statements/Let/ObjectPropertyArrayIndex.php index ffdce4f36..f9054660b 100644 --- a/src/Statements/Let/ObjectPropertyArrayIndex.php +++ b/src/Statements/Let/ObjectPropertyArrayIndex.php @@ -13,8 +13,10 @@ namespace Zephir\Statements\Let; +use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Variable\Variable as ZephirVariable; @@ -23,8 +25,6 @@ use function current; /** - * ObjectPropertyArrayIndex. - * * Updates object properties dynamically */ class ObjectPropertyArrayIndex extends ArrayIndex @@ -32,12 +32,6 @@ class ObjectPropertyArrayIndex extends ArrayIndex /** * Compiles x->y[z] = foo. * - * @param string $variable - * @param ZephirVariable $symbolVariable - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext , - * @param array $statement - * * @throws CompilerException */ public function assign( @@ -70,16 +64,14 @@ public function assign( */ $symbolVariable->setUsed(true); if (1 == count($statement['index-expr'])) { - $this->_assignPropertyArraySingleIndex( - $variable, + $this->assignPropertyArraySingleIndex( $symbolVariable, $resolvedExpr, $compilationContext, $statement ); } else { - $this->_assignPropertyArrayMultipleIndex( - $variable, + $this->assignPropertyArrayMultipleIndex( $symbolVariable, $resolvedExpr, $compilationContext, @@ -91,16 +83,15 @@ public function assign( /** * Compiles x->y[a][b] = {expr} (multiple offset assignment). * - * @param string $variable - * @param ZephirVariable $symbolVariable + * @param ZephirVariable $symbolVariable * @param CompiledExpression $resolvedExpr * @param CompilationContext $compilationContext - * @param array $statement + * @param array $statement * - * @throws CompilerException + * @throws ReflectionException + * @throws Exception */ - protected function _assignPropertyArrayMultipleIndex( - $variable, + protected function assignPropertyArrayMultipleIndex( ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, @@ -156,16 +147,10 @@ protected function _assignPropertyArrayMultipleIndex( /** * Compiles x->y[z] = {expr} (single offset assignment). * - * @param string $variable - * @param ZephirVariable $symbolVariable - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext - * @param array $statement - * - * @throws CompilerException + * @throws Exception + * @throws ReflectionException */ - protected function _assignPropertyArraySingleIndex( - $variable, + protected function assignPropertyArraySingleIndex( ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, @@ -281,7 +266,7 @@ protected function _assignPropertyArraySingleIndex( break; } - /* + /** * Check if the variable to update is defined */ if ('this' == $symbolVariable->getRealName()) { diff --git a/src/Statements/Let/ObjectPropertyArrayIndexAppend.php b/src/Statements/Let/ObjectPropertyArrayIndexAppend.php index e0b1fccbe..be23e6615 100644 --- a/src/Statements/Let/ObjectPropertyArrayIndexAppend.php +++ b/src/Statements/Let/ObjectPropertyArrayIndexAppend.php @@ -32,11 +32,8 @@ class ObjectPropertyArrayIndexAppend extends ArrayIndex /** * Compiles x->y[z][] = foo. * - * @param string $variable - * @param ZephirVariable $symbolVariable - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext , - * @param array $statement + * @throws Exception + * @throws ReflectionException */ public function assign( $variable, @@ -60,11 +57,6 @@ public function assign( /** * Compiles x->y[a][b][] = {expr} (multiple offset assignment). * - * @param ZephirVariable $symbolVariable - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext - * @param array $statement - * * @throws ReflectionException * @throws Exception */ diff --git a/src/Statements/Let/ObjectPropertyIncr.php b/src/Statements/Let/ObjectPropertyIncr.php index 94a2623a7..b2b4aa44d 100644 --- a/src/Statements/Let/ObjectPropertyIncr.php +++ b/src/Statements/Let/ObjectPropertyIncr.php @@ -14,8 +14,6 @@ namespace Zephir\Statements\Let; /** - * ObjectPropertyIncr. - * * Increments an object property */ class ObjectPropertyIncr extends ObjectPropertyDecr diff --git a/src/Statements/Let/StaticProperty.php b/src/Statements/Let/StaticProperty.php index 20f230068..d2bcaa434 100644 --- a/src/Statements/Let/StaticProperty.php +++ b/src/Statements/Let/StaticProperty.php @@ -32,13 +32,6 @@ class StaticProperty extends StaticPropertySub protected string $methodName = 'updateStaticProperty'; /** - * @param CompilationContext $compilationContext - * @param array $statement - * @param string $classEntry - * @param string $property - * @param Variable $variableVariable - * - * @return void * @throws ReflectionException */ protected function processDefaultType( @@ -51,7 +44,6 @@ protected function processDefaultType( switch ($variableVariable->getType()) { case 'string': switch ($statement['operator']) { - /* @noinspection PhpMissingBreakStatementInspection */ case 'concat-assign': $tempVariable = $compilationContext->symbolTable->getTempVariableForObserveOrNullify( 'variable', @@ -121,14 +113,6 @@ protected function processDefaultType( } } - - /** - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext - * @param array $statement - * - * @return Variable - */ protected function processStringType( CompiledExpression $resolvedExpr, CompilationContext $compilationContext, @@ -150,12 +134,6 @@ protected function processStringType( ); } - /** - * @param array $statement - * @param Variable $variableVariable - * - * @return void - */ protected function processVariableDoubleType( array $statement, Variable $variableVariable @@ -170,12 +148,6 @@ protected function processVariableDoubleType( } } - /** - * @param array $statement - * @param Variable $variableVariable - * - * @return void - */ protected function processVariableIntType( array $statement, Variable $variableVariable diff --git a/src/Statements/Let/StaticPropertyAdd.php b/src/Statements/Let/StaticPropertyAdd.php index a4ac55b29..4ed7afb88 100644 --- a/src/Statements/Let/StaticPropertyAdd.php +++ b/src/Statements/Let/StaticPropertyAdd.php @@ -14,8 +14,6 @@ namespace Zephir\Statements\Let; /** - * StaticPropertyAdd. - * * Updates static properties */ class StaticPropertyAdd extends StaticPropertySub diff --git a/src/Statements/Let/StaticPropertyAppend.php b/src/Statements/Let/StaticPropertyAppend.php index 9db9e8eb2..4db0003ec 100644 --- a/src/Statements/Let/StaticPropertyAppend.php +++ b/src/Statements/Let/StaticPropertyAppend.php @@ -23,8 +23,6 @@ use function in_array; /** - * StaticPropertyAppend. - * * Updates object properties dynamically */ class StaticPropertyAppend extends ArrayIndex @@ -32,14 +30,8 @@ class StaticPropertyAppend extends ArrayIndex /** * Compiles ClassName::foo[index] = {expr}. * - * @param string $className - * @param string $property - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext - * @param array $statement - * * @throws Exception - * @throws CompilerException + * @throws ReflectionException */ public function assignStatic( $className, @@ -113,30 +105,22 @@ public function assignStatic( $compilationContext->headersManager->add('kernel/object'); $classEntry = $classDefinition->getClassEntry($compilationContext); - $this->_assignStaticPropertyArrayMultipleIndex( + $this->assignStaticPropertyArrayMultipleIndex( $classEntry, - $property, $resolvedExpr, $compilationContext, - $statement + $statement, ); } /** * Compiles x::y[a][b][] = {expr} (multiple offset assignment). - * - * @param string $classEntry - * @param string $property - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext - * @param array $statement */ - protected function _assignStaticPropertyArrayMultipleIndex( + protected function assignStaticPropertyArrayMultipleIndex( $classEntry, - string $property, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, - array $statement + array $statement, ): void { $property = $statement['property']; $compilationContext->headersManager->add('kernel/object'); @@ -158,18 +142,8 @@ protected function _assignStaticPropertyArrayMultipleIndex( $this->checkVariableTemporal($variableExpr); } - /** - * @param array $statement - * @param CompilationContext $compilationContext - * - * @return array - * @throws ReflectionException - * @throws Exception - */ - protected function getOffsetExpressions( - array $statement, - CompilationContext $compilationContext - ): array { + protected function getOffsetExpressions(array $statement, CompilationContext $compilationContext): array + { $offsetExpressions[] = 'a'; return $offsetExpressions; diff --git a/src/Statements/Let/StaticPropertyArrayIndex.php b/src/Statements/Let/StaticPropertyArrayIndex.php index 7215dc0e2..74c7182c3 100644 --- a/src/Statements/Let/StaticPropertyArrayIndex.php +++ b/src/Statements/Let/StaticPropertyArrayIndex.php @@ -20,17 +20,11 @@ use Zephir\Expression; /** - * Zephir\Statements\Let\StaticPropertyArrayIndex. - * * Updates object properties dynamically. */ class StaticPropertyArrayIndex extends StaticPropertyAppend { /** - * @param array $statement - * @param CompilationContext $compilationContext - * - * @return array * @throws ReflectionException * @throws Exception */ @@ -38,30 +32,19 @@ protected function getOffsetExpressions( array $statement, CompilationContext $compilationContext ): array { - /** - * Only string/variable/int. - */ + $types = ['string', 'int', 'uint', 'ulong', 'long', 'variable']; $offsetExpressions = []; foreach ($statement['index-expr'] as $indexExpr) { $indexExpression = new Expression($indexExpr); - $resolvedIndex = $indexExpression->compile($compilationContext); - switch ($resolvedIndex->getType()) { - case 'string': - case 'int': - case 'uint': - case 'ulong': - case 'long': - case 'variable': - break; - default: - throw new CompilerException( - sprintf( - 'Expression: %s cannot be used as index without cast', - $resolvedIndex->getType() - ), - $statement['index-expr'] - ); + if (!in_array($resolvedIndex->getType(), $types, true)) { + throw new CompilerException( + sprintf( + 'Expression: %s cannot be used as index without cast', + $resolvedIndex->getType() + ), + $statement['index-expr'] + ); } $offsetExpressions[] = $resolvedIndex; diff --git a/src/Statements/Let/StaticPropertyArrayIndexAppend.php b/src/Statements/Let/StaticPropertyArrayIndexAppend.php index 3553faf06..2e1fd19b1 100644 --- a/src/Statements/Let/StaticPropertyArrayIndexAppend.php +++ b/src/Statements/Let/StaticPropertyArrayIndexAppend.php @@ -18,17 +18,11 @@ use Zephir\Exception; /** - * StaticPropertyArrayIndexAppend. - * * Updates object properties dynamically */ class StaticPropertyArrayIndexAppend extends StaticPropertyArrayIndex { /** - * @param array $statement - * @param CompilationContext $compilationContext - * - * @return array * @throws Exception * @throws ReflectionException */ @@ -39,10 +33,7 @@ protected function getOffsetExpressions( /** * Only string/variable/int. */ - $offsetExpressions = parent::getOffsetExpressions( - $statement, - $compilationContext - ); + $offsetExpressions = parent::getOffsetExpressions($statement, $compilationContext); $offsetExpressions[] = 'a'; return $offsetExpressions; diff --git a/src/Statements/Let/StaticPropertySub.php b/src/Statements/Let/StaticPropertySub.php index d3aeda75c..3aa883078 100644 --- a/src/Statements/Let/StaticPropertySub.php +++ b/src/Statements/Let/StaticPropertySub.php @@ -24,8 +24,6 @@ use function sprintf; /** - * StaticPropertySub. - * * Updates static properties */ class StaticPropertySub @@ -37,12 +35,6 @@ class StaticPropertySub /** * Compiles ClassName::foo = {expr}. * - * @param string $className - * @param string $property - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext - * @param array $statement - * * @throws CompilerException * @throws IllegalOperationException */ @@ -350,15 +342,6 @@ public function assignStatic( } } - /** - * @param CompilationContext $compilationContext - * @param array $statement - * @param string $classEntry - * @param string $property - * @param Variable $variableVariable - * - * @return void - */ protected function processDefaultType( CompilationContext $compilationContext, array $statement, @@ -376,17 +359,10 @@ protected function processDefaultType( $this->checkVariableTemporal($variableVariable); } - /** - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext - * @param array $statement - * - * @return Variable - */ protected function processStringType( CompiledExpression $resolvedExpr, CompilationContext $compilationContext, - array $statement + array $statement, ): Variable { return $compilationContext->symbolTable->getTempVariableForWrite( 'variable', @@ -394,29 +370,13 @@ protected function processStringType( ); } - /** - * @param array $statement - * @param Variable $variableVariable - * - * @return void - */ - protected function processVariableDoubleType( - array $statement, - Variable $variableVariable - ): void { + protected function processVariableDoubleType(array $statement, Variable $variableVariable): void + { // Nothing } - /** - * @param array $statement - * @param Variable $variableVariable - * - * @return void - */ - protected function processVariableIntType( - array $statement, - Variable $variableVariable - ): void { + protected function processVariableIntType(array $statement, Variable $variableVariable): void + { // Nothing } } diff --git a/src/Statements/Let/Variable.php b/src/Statements/Let/Variable.php index 3dbc8e49b..296a8c615 100644 --- a/src/Statements/Let/Variable.php +++ b/src/Statements/Let/Variable.php @@ -26,8 +26,6 @@ use function array_keys; /** - * Zephir\Statements\Let\Variable. - * * Assign a value to a variable. */ class Variable @@ -38,13 +36,6 @@ class Variable * Compiles foo = {expr} * Changes the value of a mutable variable. * - * @param string $variable - * @param ZephirVariable $symbolVariable - * @param CompiledExpression $resolvedExpr - * @param ReadDetector $readDetector - * @param CompilationContext $compilationContext - * @param array $statement - * * @throws CompilerException */ public function assign( @@ -59,7 +50,7 @@ public function assign( $codePrinter = $compilationContext->codePrinter; - /* + /** * Only initialize variables if it's direct assignment */ if ('assign' == $statement['operator']) { @@ -68,7 +59,7 @@ public function assign( $this->checkVariableInitialized($variable, $symbolVariable, $statement); } - /* + /** * Set the assigned value to the variable as a CompiledExpression * We could use this expression for further analysis */ @@ -154,13 +145,6 @@ public function assign( /** * Performs array assignment. * - * @param Printer $codePrinter - * @param CompiledExpression $resolvedExpr - * @param ZephirVariable $symbolVariable - * @param string $variable - * @param array $statement - * @param CompilationContext $compilationContext - * * @throws CompilerException * @throws IllegalOperationException */ @@ -193,16 +177,6 @@ private function doArrayAssignment( } } - /** - * @param array $statement - * @param CompiledExpression $resolvedExpr - * @param string $variable - * @param ZephirVariable $symbolVariable - * @param CompilationContext $compilationContext - * @param Printer $codePrinter - * - * @return void - */ private function doArrayAssignmentProcess( array $statement, CompiledExpression $resolvedExpr, @@ -727,15 +701,6 @@ private function doNumericAssignmentLong( } } - /** - * @param array $statement - * @param Printer $codePrinter - * @param string $variable - * @param ZephirVariable|bool $itemVariable - * @param string $cast - * - * @return void - */ private function doNumericAssignmentVar( array $statement, Printer $codePrinter, @@ -1004,14 +969,6 @@ private function doStringAssignment( /** * Performs variable assignment. * - * @param Printer $codePrinter - * @param CompiledExpression $resolvedExpr - * @param ZephirVariable $symbolVariable - * @param string $variable - * @param array $statement - * @param CompilationContext $compilationContext - * @param ReadDetector $readDetector - * * @throws CompilerException * @throws IllegalOperationException */ @@ -1476,16 +1433,6 @@ private function doVariableAssignment( } } - /** - * @param CompilationContext $compilationContext - * @param ZephirVariable|bool $exprVariable - * @param array $statement - * @param Printer $codePrinter - * @param string $variable - * @param ZephirVariable|bool $itemVariable - * - * @return void - */ private function processDoNumericAssignmentMixed( CompilationContext $compilationContext, ZephirVariable | bool $exprVariable, @@ -1523,16 +1470,6 @@ private function processDoNumericAssignmentMixed( } } - /** - * @param ZephirVariable $symbolVariable - * @param ReadDetector $readDetector - * @param string $variable - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext - * @param Printer $codePrinter - * - * @return void - */ private function processDoVariableAssignmentAssign( ZephirVariable $symbolVariable, ReadDetector $readDetector, @@ -1564,14 +1501,6 @@ private function processDoVariableAssignmentAssign( } } - /** - * @param ZephirVariable|bool $itemVariable - * @param string $variable - * @param ZephirVariable $symbolVariable - * @param CompilationContext $compilationContext - * - * @return void - */ private function processDoVariableAssignmentVariableString( ZephirVariable | bool $itemVariable, string $variable, diff --git a/src/Statements/Let/VariableAppend.php b/src/Statements/Let/VariableAppend.php index 8771fa0e0..7556ec6d7 100644 --- a/src/Statements/Let/VariableAppend.php +++ b/src/Statements/Let/VariableAppend.php @@ -20,7 +20,6 @@ use Zephir\Variable\Variable as ZephirVariable; /** - * VariableAppend. * * Append a value to a variable */ @@ -31,12 +30,6 @@ class VariableAppend /** * Compiles foo[] = {expr}. * - * @param $variable - * @param ZephirVariable $symbolVariable - * @param CompiledExpression $resolvedExpr - * @param CompilationContext $compilationContext - * @param $statement - * * @throws CompilerException */ public function assign( @@ -50,7 +43,7 @@ public function assign( $this->checkVariableReadOnly($variable, $symbolVariable, $statement); $this->checkVariableLocalOnly($variable, $symbolVariable, $statement); - /* + /** * Only dynamic variables and arrays can be used as arrays */ if ($symbolVariable->isNotVariableAndArray()) { diff --git a/src/Statements/LoopStatement.php b/src/Statements/LoopStatement.php index 5d5f361b2..70d6b4494 100644 --- a/src/Statements/LoopStatement.php +++ b/src/Statements/LoopStatement.php @@ -27,8 +27,6 @@ class LoopStatement extends StatementAbstract { /** - * @param CompilationContext $compilationContext - * * @throws ReflectionException * @throws Exception */ diff --git a/src/Statements/RequireOnceStatement.php b/src/Statements/RequireOnceStatement.php index 35f03b4d5..9b122cce1 100644 --- a/src/Statements/RequireOnceStatement.php +++ b/src/Statements/RequireOnceStatement.php @@ -14,8 +14,6 @@ namespace Zephir\Statements; /** - * RequireOnceStatement. - * * Require once statement is used to execute PHP scripts in a given path */ class RequireOnceStatement extends RequireStatement diff --git a/src/Statements/RequireStatement.php b/src/Statements/RequireStatement.php index 84c103610..c1592acc5 100644 --- a/src/Statements/RequireStatement.php +++ b/src/Statements/RequireStatement.php @@ -13,13 +13,12 @@ namespace Zephir\Statements; +use ReflectionException; use Zephir\CompilationContext; -use Zephir\Exception\CompilerException; +use Zephir\Exception; use Zephir\Expression; /** - * RequireStatement. - * * Require statement is used to execute PHP scripts in a given path */ class RequireStatement extends StatementAbstract @@ -27,21 +26,18 @@ class RequireStatement extends StatementAbstract protected string $methodName = 'require'; /** - * @param CompilationContext $compilationContext - * - * @throws CompilerException + * @throws ReflectionException + * @throws Exception */ public function compile(CompilationContext $compilationContext): void { - $expression = [ + $expr = new Expression([ 'type' => $this->methodName, 'left' => $this->statement['expr'], 'file' => $this->statement['file'], 'line' => $this->statement['line'], 'char' => $this->statement['char'], - ]; - - $expr = new Expression($expression); + ]); $expr->setExpectReturn(false); $expr->compile($compilationContext); } diff --git a/src/Statements/ReturnStatement.php b/src/Statements/ReturnStatement.php index 90898c124..a97d27bb4 100644 --- a/src/Statements/ReturnStatement.php +++ b/src/Statements/ReturnStatement.php @@ -35,8 +35,6 @@ final class ReturnStatement extends StatementAbstract private const RETURN_RETURN = 'RETURN_MM();'; /** - * @param CompilationContext $compilationContext - * * @throws Exception * @throws ReflectionException */ diff --git a/src/Statements/SwitchStatement.php b/src/Statements/SwitchStatement.php index 70430b067..3df166009 100644 --- a/src/Statements/SwitchStatement.php +++ b/src/Statements/SwitchStatement.php @@ -30,8 +30,6 @@ class SwitchStatement extends StatementAbstract { /** - * @param CompilationContext $compilationContext - * * @throws ReflectionException * @throws Exception */ diff --git a/src/Statements/ThrowStatement.php b/src/Statements/ThrowStatement.php index 7da50b81c..5d76ece13 100644 --- a/src/Statements/ThrowStatement.php +++ b/src/Statements/ThrowStatement.php @@ -33,8 +33,6 @@ class ThrowStatement extends StatementAbstract { /** - * @param CompilationContext $compilationContext - * * @throws Exception * @throws ReflectionException */ @@ -141,11 +139,6 @@ public function compile(CompilationContext $compilationContext): void /** * Throws an exception escaping the data. - * - * @param Printer $printer - * @param string $class - * @param string $message - * @param array $expression */ private function throwStringException(Printer $printer, string $class, string $message, array $expression): void { diff --git a/src/Statements/UnsetStatement.php b/src/Statements/UnsetStatement.php index 7acb07cfc..5b49b15ab 100644 --- a/src/Statements/UnsetStatement.php +++ b/src/Statements/UnsetStatement.php @@ -27,8 +27,6 @@ class UnsetStatement extends StatementAbstract { /** - * @param CompilationContext $compilationContext - * * @throws Exception * @throws ReflectionException */ @@ -111,11 +109,6 @@ public function compile(CompilationContext $compilationContext): void } /** - * @param array $expression - * @param CompilationContext $compilationContext - * - * @return CompilationContext - * * @throws Exception * @throws ReflectionException */ diff --git a/src/Statements/WhileStatement.php b/src/Statements/WhileStatement.php index 7eebf11db..aa956331b 100644 --- a/src/Statements/WhileStatement.php +++ b/src/Statements/WhileStatement.php @@ -13,48 +13,44 @@ namespace Zephir\Statements; +use ReflectionException; use Zephir\CompilationContext; +use Zephir\Exception; use Zephir\Optimizers\EvalExpression; use Zephir\StatementsBlock; /** - * WhileStatement. - * * While statement, the same as in PHP/C */ class WhileStatement extends StatementAbstract { /** - * @param CompilationContext $compilationContext + * @throws ReflectionException + * @throws Exception */ public function compile(CompilationContext $compilationContext): void { - $exprRaw = $this->statement['expr']; - $codePrinter = $compilationContext->codePrinter; - - /* + /** * Compound conditions can be evaluated in a single line of the C-code */ - $codePrinter->output('while (1) {'); + $compilationContext->codePrinter->output('while (1) {'); + $compilationContext->codePrinter->increaseLevel(); - $codePrinter->increaseLevel(); - - /* + /** * Variables are initialized in a different way inside loops */ ++$compilationContext->insideCycle; $expr = new EvalExpression(); - $condition = $expr->optimize($exprRaw, $compilationContext); + $condition = $expr->optimize($this->statement['expr'], $compilationContext); $this->evalExpression = $expr; - $codePrinter->output('if (!(' . $condition . ')) {'); - $codePrinter->output("\t" . 'break;'); - $codePrinter->output('}'); - - $codePrinter->decreaseLevel(); + $compilationContext->codePrinter->output('if (!(' . $condition . ')) {'); + $compilationContext->codePrinter->output("\t" . 'break;'); + $compilationContext->codePrinter->output('}'); + $compilationContext->codePrinter->decreaseLevel(); - /* + /** * Compile statements in the 'while' block */ if (isset($this->statement['statements'])) { @@ -63,11 +59,11 @@ public function compile(CompilationContext $compilationContext): void $st->compile($compilationContext); } - /* + /** * Restore the cycle counter */ --$compilationContext->insideCycle; - $codePrinter->output('}'); + $compilationContext->codePrinter->output('}'); } }