From bd7c643a0bb58e49c6db10fd41d082fbf610e716 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev <1695147@gmail.com> Date: Sun, 10 Sep 2023 19:24:01 +0100 Subject: [PATCH] #2407 - Fix CS --- Library/AliasManager.php | 4 +- Library/Backend/Backend.php | 79 +++++----- Library/Backend/FcallManager.php | 7 +- Library/Backend/FcallManagerInterface.php | 4 +- Library/Backend/StringsManager.php | 3 +- Library/Backend/VariablesManager.php | 5 +- .../Builder/Operators/CastOperatorBuilder.php | 2 +- .../Operators/UnaryOperatorBuilder.php | 6 +- Library/Cache/Manager.php | 2 +- Library/Cache/MethodCache.php | 14 +- Library/Cache/StaticMethodCache.php | 5 +- Library/Call.php | 4 +- Library/Class/Constant.php | 5 +- Library/Class/Definition/Definition.php | 42 +++--- Library/Class/Entry.php | 3 +- Library/Class/Method/Method.php | 141 +++++++++--------- Library/Class/Method/Parameters.php | 12 +- Library/Class/Property.php | 38 +++-- Library/Code/ArgInfoDefinition.php | 26 ++-- Library/Code/Builder/Struct.php | 7 +- Library/CompilationContext.php | 5 +- Library/CompiledExpression.php | 4 +- Library/Compiler.php | 137 ++++++++--------- Library/CompilerFile.php | 17 +-- Library/CompilerFileAnonymous.php | 12 +- Library/Config.php | 5 +- Library/ConfigException.php | 6 +- Library/Console/Application.php | 6 +- Library/Console/Command/ApiCommand.php | 4 +- Library/Console/Command/CleanCommand.php | 4 +- .../Command/DevelopmentModeAwareTrait.php | 4 +- Library/Console/Command/GenerateCommand.php | 4 +- Library/Console/Command/InitCommand.php | 37 ++--- Library/Console/Command/InstallCommand.php | 4 +- .../Console/Command/RemoveOptionsTrait.php | 7 +- Library/Detectors/ReadDetector.php | 7 +- Library/Documentation.php | 8 +- Library/Documentation/DocblockParser.php | 6 +- Library/Documentation/Template.php | 2 +- Library/Exception/CompilerException.php | 2 +- Library/Expression.php | 6 +- .../Expression/Builder/AbstractBuilder.php | 6 +- Library/Expression/Builder/BuilderFactory.php | 2 +- .../Builder/Factory/OperatorsFactory.php | 4 +- .../Statements/CallFunctionStatement.php | 2 +- Library/Expression/Closure.php | 5 +- Library/Expression/ClosureArrow.php | 6 +- Library/Expression/Constants.php | 24 ++- Library/Expression/NativeArray.php | 9 +- Library/Expression/NativeArrayAccess.php | 17 ++- Library/Expression/PropertyAccess.php | 2 +- Library/Expression/PropertyDynamicAccess.php | 1 + Library/Expression/Reference.php | 5 +- Library/Expression/StaticConstantAccess.php | 16 +- Library/Expression/StaticPropertyAccess.php | 8 +- Library/FileSystem/HardDisk.php | 20 +-- Library/FunctionCall.php | 26 ++-- Library/FunctionDefinition.php | 12 +- .../Logger/Formatter/CompilerFormatter.php | 12 +- Library/MethodCall.php | 44 +++--- Library/Operators/AbstractOperator.php | 6 +- .../Arithmetical/ArithmeticalBaseOperator.php | 10 +- .../Operators/Arithmetical/DivOperator.php | 6 +- .../Operators/Arithmetical/ModOperator.php | 6 +- .../Operators/Bitwise/BitwiseBaseOperator.php | 12 +- .../Operators/Bitwise/BitwiseNotOperator.php | 6 +- .../Comparison/ComparisonBaseOperator.php | 5 +- Library/Operators/Logical/AndOperator.php | 10 +- .../Operators/Logical/LogicalBaseOperator.php | 6 +- Library/Operators/Logical/OrOperator.php | 5 +- Library/Operators/Other/CastOperator.php | 3 +- Library/Operators/Other/ConcatOperator.php | 1 + .../Operators/Other/InstanceOfOperator.php | 5 +- Library/Operators/Other/IssetOperator.php | 3 +- Library/Operators/Other/LikelyOperator.php | 5 +- .../Operators/Other/NewInstanceOperator.php | 6 +- Library/Operators/Other/RequireOperator.php | 5 +- .../Operators/Other/ShortTernaryOperator.php | 2 +- Library/Operators/Other/TernaryOperator.php | 2 +- Library/Operators/Other/TypeHintOperator.php | 5 +- Library/Operators/Other/TypeOfOperator.php | 5 +- Library/Operators/Other/UnlikelyOperator.php | 5 +- Library/Operators/Unary/MinusOperator.php | 5 +- Library/Operators/Unary/NotOperator.php | 5 +- Library/Optimizers/EvalExpression.php | 8 +- .../FunctionCall/AddslashesOptimizer.php | 4 +- .../FunctionCall/ArrayKeyExistsOptimizer.php | 6 +- .../FunctionCall/ArrayKeysOptimizer.php | 4 +- .../FunctionCall/ArrayMergeOptimizer.php | 4 +- .../FunctionCall/BasenameOptimizer.php | 4 +- .../FunctionCall/CamelizeOptimizer.php | 4 +- .../Optimizers/FunctionCall/CeilOptimizer.php | 4 +- .../FunctionCall/ClassExistsOptimizer.php | 4 +- .../FunctionCall/CompareMtimeOptimizer.php | 4 +- .../FunctionCall/Crc32Optimizer.php | 4 +- .../FunctionCall/CreateArrayOptimizer.php | 4 +- .../FunctionCall/CreateInstanceOptimizer.php | 4 +- .../CreateSymbolTableOptimizer.php | 4 +- .../FunctionCall/DoublevalOptimizer.php | 4 +- .../Optimizers/FunctionCall/EvalOptimizer.php | 4 +- .../Optimizers/FunctionCall/ExitOptimizer.php | 6 +- .../FunctionCall/ExplodeOptimizer.php | 4 +- .../FunctionCall/FcloseOptimizer.php | 4 +- .../FunctionCall/FileExistsOptimizer.php | 4 +- .../FunctionCall/FileGetContentsOptimizer.php | 4 +- .../FunctionCall/FilePutContentsOptimizer.php | 4 +- .../FunctionCall/FilemtimeOptimizer.php | 4 +- .../FunctionCall/FloorOptimizer.php | 4 +- .../FunctionCall/FuncGetArgOptimizer.php | 4 +- .../FunctionCall/FuncGetArgsOptimizer.php | 4 +- .../FunctionCall/FunctionExistsOptimizer.php | 3 +- .../FunctionCall/FwriteOptimizer.php | 4 +- .../FunctionCall/GetCalledClassOptimizer.php | 4 +- .../FunctionCall/GetClassLowerOptimizer.php | 4 +- .../FunctionCall/GetClassNsOptimizer.php | 4 +- .../FunctionCall/GetClassOptimizer.php | 4 +- .../FunctionCall/GetNsClassOptimizer.php | 4 +- .../FunctionCall/GettypeOptimizer.php | 4 +- .../FunctionCall/GlobalsGetOptimizer.php | 6 +- .../FunctionCall/GlobalsSetOptimizer.php | 8 +- .../FunctionCall/HashEqualsOptimizer.php | 4 +- .../FunctionCall/ImplodeOptimizer.php | 4 +- .../FunctionCall/InArrayOptimizer.php | 4 +- .../FunctionCall/InterfaceExistsOptimizer.php | 4 +- .../FunctionCall/IntvalOptimizer.php | 4 +- .../IsPrivatePropertyOptimizer.php | 4 +- .../FunctionCall/LdexpOptimizer.php | 4 +- .../Optimizers/FunctionCall/Md5Optimizer.php | 4 +- .../FunctionCall/MergeAppendOptimizer.php | 4 +- .../FunctionCall/MicrotimeOptimizer.php | 4 +- .../Optimizers/FunctionCall/PowOptimizer.php | 4 +- .../FunctionCall/PregMatchOptimizer.php | 8 +- .../PrepareVirtualPathOptimizer.php | 4 +- .../FunctionCall/RoundOptimizer.php | 10 +- .../FunctionCall/StrReplaceOptimizer.php | 4 +- .../FunctionCall/StripcslashesOptimizer.php | 4 +- .../FunctionCall/StripslashesOptimizer.php | 4 +- .../FunctionCall/StrposOptimizer.php | 4 +- .../FunctionCall/StrtokOptimizer.php | 4 +- .../FunctionCall/StrtolowerOptimizer.php | 4 +- .../FunctionCall/StrtoupperOptimizer.php | 4 +- .../FunctionCall/SubstrOptimizer.php | 4 +- .../Optimizers/FunctionCall/TimeOptimizer.php | 4 +- .../Optimizers/FunctionCall/TrimOptimizer.php | 4 +- .../FunctionCall/UcfirstOptimizer.php | 4 +- .../FunctionCall/UncamelizeOptimizer.php | 4 +- .../FunctionCall/UniqueKeyOptimizer.php | 4 +- .../FunctionCall/UniquePathKeyOptimizer.php | 4 +- .../FunctionCall/VarExportOptimizer.php | 4 +- .../ZephirStringToHexOptimizer.php | 4 +- .../Optimizers/IsTypeOptimizerAbstract.php | 4 +- Library/Optimizers/MathOptimizer.php | 4 +- Library/Parser/Manager.php | 4 +- Library/Parser/Parser.php | 4 +- Library/Passes/LocalContextPass.php | 16 +- Library/Passes/SkipVariantInit.php | 10 +- Library/Passes/StaticTypeInference.php | 8 +- Library/Statements/DoWhileStatement.php | 4 +- Library/Statements/EchoStatement.php | 3 +- Library/Statements/ForStatement.php | 21 +-- Library/Statements/IfStatement.php | 4 +- Library/Statements/Let/ArrayIndex.php | 4 +- .../Statements/Let/ObjectDynamicProperty.php | 5 +- Library/Statements/Let/ObjectProperty.php | 2 +- .../Let/ObjectPropertyArrayIndexAppend.php | 4 +- Library/Statements/Let/StaticProperty.php | 9 +- Library/Statements/Let/Variable.php | 51 +++---- Library/Statements/Let/VariableAppend.php | 4 +- Library/Statements/ReturnStatement.php | 4 +- Library/Statements/SwitchStatement.php | 6 +- Library/Statements/ThrowStatement.php | 25 ++-- Library/Statements/UnsetStatement.php | 9 +- Library/StatementsBlock.php | 8 +- Library/StaticCall.php | 95 ++++++------ Library/Stubs/DocBlock.php | 8 +- Library/Stubs/Generator.php | 37 +++-- Library/Stubs/MethodDocBlock.php | 6 +- Library/SymbolTable.php | 32 ++-- Library/Types/AbstractType.php | 11 +- Library/Types/ArrayType.php | 10 +- Library/Types/CharType.php | 10 +- Library/Types/Types.php | 15 +- Library/Variable/Variable.php | 33 ++-- Library/functions.php | 18 +-- prototypes/apc.php | 30 ++-- prototypes/gd.php | 2 +- tests/Extension/ArrayAccessTest.php | 6 +- tests/Extension/ExitDieTest.php | 7 +- tests/Extension/FunctionExistsTest.php | 1 + tests/Extension/Globals/EnvTest.php | 2 +- tests/Extension/Integral/RegexDNATest.php | 5 +- tests/Extension/Issue1134Test.php | 6 +- tests/Extension/MCallTest.php | 10 +- tests/Extension/NewInstanceOperatorTest.php | 3 +- tests/Extension/Oo/ExtendClassTest.php | 7 +- .../Extension/Oo/Scopes/PrivateScopeTest.php | 63 ++++---- .../Extension/Optimizers/IsPhpVersionTest.php | 24 ++- .../Properties/StaticPublicPropertiesTest.php | 6 +- tests/Extension/ReflectionTest.php | 11 +- tests/Extension/RequiresTest.php | 12 +- tests/Extension/TypeHinting/AbstractTest.php | 7 +- tests/Extension/Types/MixedTypeTest.php | 14 +- tests/Extension/Types/ObjTypeTest.php | 5 +- tests/Extension/UnsetTest.php | 2 +- .../CompilerFile/CheckDependenciesTest.php | 3 +- .../CompilerFile/CheckPathSeparatorTest.php | 2 +- tests/Zephir/ConfigTest.php | 1 + tests/Zephir/Stubs/GeneratorTest.php | 17 ++- tests/Zephir/Stubs/MethodDocBlockTest.php | 18 +-- tests/Zephir/TypesTest.php | 2 +- 210 files changed, 959 insertions(+), 1128 deletions(-) diff --git a/Library/AliasManager.php b/Library/AliasManager.php index 4d82afe664..742d5bcaec 100644 --- a/Library/AliasManager.php +++ b/Library/AliasManager.php @@ -13,8 +13,6 @@ namespace Zephir; -use function in_array; - /** * Manage aliases in a file */ @@ -117,7 +115,7 @@ public function isAliasPresentFor(string $className): bool { $extractAlias = $this->implicitAlias($className); - $isClassDeclared = in_array($className, $this->aliases); + $isClassDeclared = \in_array($className, $this->aliases); $classAlias = array_flip($this->aliases)[$className] ?? null; return $isClassDeclared && $classAlias !== $extractAlias; diff --git a/Library/Backend/Backend.php b/Library/Backend/Backend.php index 13a64161cb..9a28076e28 100644 --- a/Library/Backend/Backend.php +++ b/Library/Backend/Backend.php @@ -26,8 +26,7 @@ use Zephir\GlobalConstant; use Zephir\Variable\Globals; use Zephir\Variable\Variable; -use function in_array; -use function strlen; + use function Zephir\add_slashes; class Backend @@ -121,9 +120,9 @@ public function initVar(Variable $variable, CompilationContext $context, $useCod public function getVariableCode(Variable $variable): string { - if ($variable->isDoublePointer() || - in_array($variable->getName(), ['this_ptr', 'return_value']) || - in_array($variable->getType(), ['int', 'long'])) { + if ($variable->isDoublePointer() + || \in_array($variable->getName(), ['this_ptr', 'return_value']) + || \in_array($variable->getType(), ['int', 'long'])) { return $variable->getName(); } @@ -243,13 +242,13 @@ public function getTypeDefinition($type): array } /** - * @param Variable $variableVariable - * @param string $operator - * @param string $value - * - * @throws CompilerException + * @param Variable $variableVariable + * @param string $operator + * @param string $value * * @return string + * + * @throws CompilerException */ public function getTypeofCondition( Variable $variableVariable, @@ -309,7 +308,7 @@ public function getTypeofCondition( public function onPreInitVar(Method $method): string { if (!$method instanceof FunctionDefinition && !$method->isInternal()) { - return "zval *this_ptr = getThis();\n"; //TODO: think about a better way to solve this. + return "zval *this_ptr = getThis();\n"; // TODO: think about a better way to solve this. } return ''; @@ -343,7 +342,7 @@ public function onPostCompile(Method $method, CompilationContext $context): void public function generateInitCode(&$groupVariables, $type, $pointer, Variable $variable) { - $isComplex = in_array($type, ['variable', 'string', 'array', 'resource', 'callable', 'object', 'mixed'], true); + $isComplex = \in_array($type, ['variable', 'string', 'array', 'resource', 'callable', 'object', 'mixed'], true); if ($isComplex && !$variable->isDoublePointer()) { $groupVariables[] = $variable->getName(); @@ -397,9 +396,9 @@ public function generateInitCode(&$groupVariables, $type, $pointer, Variable $va break; case 'char': - $defaultValue = (string)$defaultValue; - if (strlen($defaultValue) > 4) { - if (strlen($defaultValue) > 10) { + $defaultValue = (string) $defaultValue; + if (\strlen($defaultValue) > 4) { + if (\strlen($defaultValue) > 10) { throw new CompilerException("Invalid char literal: '".substr($defaultValue, 0, 10)."...'", $variable->getOriginal()); } else { throw new CompilerException("Invalid char literal: '".$defaultValue."'", $variable->getOriginal()); @@ -428,9 +427,9 @@ public function generateInitCode(&$groupVariables, $type, $pointer, Variable $va * @param Variable[] $variables * @param CompilationContext $context * - * @throws CompilerException - * * @return string + * + * @throws CompilerException */ public function initializeVariableDefaults(array $variables, CompilationContext $context): string { @@ -504,7 +503,7 @@ public function declareConstant($type, $name, $value, CompilationContext $contex } /** - * @param Method $method + * @param Method $method * @param CompilationContext $context * * @return string @@ -646,7 +645,7 @@ public function addArrayEntry(Variable $variable, $key, $value, CompilationConte $var = $context->symbolTable->getVariableForRead($key->getCode(), $context); $typeKey = $var->getType(); } - if (in_array($typeKey, ['int', 'uint', 'long', 'ulong'])) { + if (\in_array($typeKey, ['int', 'uint', 'long', 'ulong'])) { $keyType = 'index'; } } @@ -771,16 +770,16 @@ public function arrayIssetFetch2(Variable $target, Variable $var, $resolvedExpr, if (!($resolvedExpr instanceof Variable)) { if ('string' === $resolvedExpr->getType()) { return new CompiledExpression('bool', 'zephir_array_isset_string_fetch('.$code.', SS("'.$resolvedExpr->getCode().'"), '.$flags.')', $expression); - } elseif (in_array($resolvedExpr->getType(), ['int', 'uint', 'long'])) { + } elseif (\in_array($resolvedExpr->getType(), ['int', 'uint', 'long'])) { return new CompiledExpression('bool', 'zephir_array_isset_long_fetch('.$code.', '.$resolvedExpr->getCode().', '.$flags.')', $expression); } else { $resolvedExpr = $context->symbolTable->getVariableForRead($resolvedExpr->getCode(), $context); } } - if (in_array($resolvedExpr->getType(), ['int', 'long'])) { + if (\in_array($resolvedExpr->getType(), ['int', 'long'])) { return new CompiledExpression('bool', 'zephir_array_isset_long_fetch('.$code.', '.$this->getVariableCode($resolvedExpr).', '.$flags.')', $expression); - } elseif (in_array($resolvedExpr->getType(), ['variable', 'mixed', 'string'])) { + } elseif (\in_array($resolvedExpr->getType(), ['variable', 'mixed', 'string'])) { return new CompiledExpression('bool', 'zephir_array_isset_fetch('.$code.', '.$this->getVariableCode($resolvedExpr).', '.$flags.')', $expression); } @@ -920,11 +919,12 @@ public function fetchProperty( } /** - * @param Variable $symbolVariable - * @param Definition $classDefinition - * @param $property - * @param bool $readOnly + * @param Variable $symbolVariable + * @param Definition $classDefinition + * @param $property + * @param bool $readOnly * @param CompilationContext $context + * * @throws Exception */ public function fetchStaticProperty(Variable $symbolVariable, $classDefinition, $property, $readOnly, CompilationContext $context): void @@ -943,14 +943,14 @@ public function fetchStaticProperty(Variable $symbolVariable, $classDefinition, } /** - * @param $value + * @param $value * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|string|Variable + * + * @throws CompilerException */ - public function resolveValue($value, CompilationContext $context): Variable|bool|string + public function resolveValue($value, CompilationContext $context): Variable | bool | string { if ($value instanceof GlobalConstant) { switch ($value->getName()) { @@ -988,7 +988,7 @@ public function resolveValue($value, CompilationContext $context): Variable|bool $value = $this->getVariableCode($tempVariable); } else { if ($value instanceof CompiledExpression) { - if (in_array($value->getType(), ['array', 'variable', 'mixed'])) { + if (\in_array($value->getType(), ['array', 'variable', 'mixed'])) { $value = $context->symbolTable->getVariableForWrite($value->getCode(), $context); } else { return $value->getCode(); @@ -1313,7 +1313,7 @@ public function getScalarTempVariable( * * @return void */ - public function initArray(Variable $variable, CompilationContext $context, ?int $size = null): void + public function initArray(Variable $variable, CompilationContext $context, int $size = null): void { $code = $this->getVariableCode($variable); @@ -1406,7 +1406,7 @@ public function arrayFetch(Variable $var, Variable $src, $index, $flags, $arrayA $type = 'long'; break; - /* Types which map to the same */ + /* Types which map to the same */ case 'variable': case 'mixed': case 'string': @@ -1419,7 +1419,7 @@ public function arrayFetch(Variable $var, Variable $src, $index, $flags, $arrayA $arrayAccess['right'] ); } - if ($isVariable && in_array($index->getType(), ['variable', 'string', 'mixed'])) { + if ($isVariable && \in_array($index->getType(), ['variable', 'string', 'mixed'])) { $output = 'zephir_array_fetch('.$this->getVariableCode($var).', '.$this->getVariableCode($src).', '.$this->getVariableCode($index).', '.$flags.', "'.Compiler::getShortUserPath($arrayAccess['file']).'", '.$arrayAccess['line'].');'; } else { if ($isVariable) { @@ -1630,19 +1630,11 @@ public function checkStrictType($type, $var, CompilationContext $context) /** * Assign value to variable helper. - * - * @param string $macro - * @param string $variableName - * @param string|Variable|null $value - * @param CompilationContext $context - * @param bool $useCodePrinter - * - * @return string */ protected function assignHelper( string $macro, string $variableName, - $value, + $value, CompilationContext $context, bool $useCodePrinter ): string { @@ -1696,6 +1688,7 @@ protected function returnHelper(string $macro, $value, CompilationContext $conte * @param CompilationContext $compilationContext * * @return array + * * @throws CompilerException */ private function resolveOffsetExprs(array $offsetExprs, CompilationContext $compilationContext): array diff --git a/Library/Backend/FcallManager.php b/Library/Backend/FcallManager.php index 1c751f4590..ffa27b55c6 100644 --- a/Library/Backend/FcallManager.php +++ b/Library/Backend/FcallManager.php @@ -14,6 +14,7 @@ namespace Zephir\Backend; use Zephir\Code\Printer; + use function Zephir\file_put_contents_ex; class FcallManager implements FcallManagerInterface @@ -24,8 +25,8 @@ class FcallManager implements FcallManagerInterface * {@inheritdoc} * * @param bool $static - * @param int $doReturn tri-state: 0 -> no return value, 1 -> do return, 2 -> do return to given variable - * @param int $paramCount + * @param int $doReturn tri-state: 0 -> no return value, 1 -> do return, 2 -> do return to given variable + * @param int $paramCount * * @return string */ @@ -133,7 +134,7 @@ public function genFcallCode(): void sprintf( 'method(0, execute_data, %s, %s%s%s); \\', $retParam, - ($scope ? 'NULL, ' : $objParam), + $scope ? 'NULL, ' : $objParam, $retValueUsed, $i ? ', &'.implode(', &', $zvals) : '' ) diff --git a/Library/Backend/FcallManagerInterface.php b/Library/Backend/FcallManagerInterface.php index 4adc7dc851..8c136055b3 100644 --- a/Library/Backend/FcallManagerInterface.php +++ b/Library/Backend/FcallManagerInterface.php @@ -17,8 +17,8 @@ interface FcallManagerInterface * Resolve internal fcall attributes to a suitable macro and ensure that it's generated during compilation. * * @param bool $static - * @param int $doReturn tri-state: 0 -> no return value, 1 -> do return, 2 -> do return to given variable - * @param int $paramCount + * @param int $doReturn tri-state: 0 -> no return value, 1 -> do return, 2 -> do return to given variable + * @param int $paramCount * * @return string */ diff --git a/Library/Backend/StringsManager.php b/Library/Backend/StringsManager.php index 70ef092ebd..92f964d107 100644 --- a/Library/Backend/StringsManager.php +++ b/Library/Backend/StringsManager.php @@ -15,7 +15,6 @@ use Zephir\StringsManager as BaseStringsManager; -use function strlen; use function Zephir\file_put_contents_ex; /** @@ -61,7 +60,7 @@ public function genConcatCode(): void $macros = []; ksort($this->concatKeys, SORT_STRING); foreach ($this->concatKeys as $key => $one) { - $len = strlen($key); + $len = \strlen($key); $params = []; $zvalCopy = []; $useCopy = []; diff --git a/Library/Backend/VariablesManager.php b/Library/Backend/VariablesManager.php index 55b5d832e4..bd3817be47 100644 --- a/Library/Backend/VariablesManager.php +++ b/Library/Backend/VariablesManager.php @@ -17,6 +17,7 @@ use Zephir\Exception\CompilerException as Exception; use Zephir\Types\Types; use Zephir\Variable\Variable; + use function Zephir\Backend\ZendEngine3\add_slashes; class VariablesManager @@ -174,9 +175,9 @@ private function initArrayVar(Variable $variable, array $value, Context $context * * @param array $value * - * @throws Exception - * * @return void + * + * @throws Exception */ private function validateCharValue(array $value): void { diff --git a/Library/Builder/Operators/CastOperatorBuilder.php b/Library/Builder/Operators/CastOperatorBuilder.php index a67aa4a32b..e57e855e6d 100644 --- a/Library/Builder/Operators/CastOperatorBuilder.php +++ b/Library/Builder/Operators/CastOperatorBuilder.php @@ -27,7 +27,7 @@ class CastOperatorBuilder extends AbstractOperatorBuilder public function __construct( string $left, FunctionCallBuilder $right, - ?string $file = null, + string $file = null, int $line = 0, int $char = 0 ) { diff --git a/Library/Builder/Operators/UnaryOperatorBuilder.php b/Library/Builder/Operators/UnaryOperatorBuilder.php index b893e9904f..e68231881e 100644 --- a/Library/Builder/Operators/UnaryOperatorBuilder.php +++ b/Library/Builder/Operators/UnaryOperatorBuilder.php @@ -13,8 +13,6 @@ namespace Zephir\Builder\Operators; -use function is_object; - /** * Allows to manually build a unary operator AST node */ @@ -34,7 +32,7 @@ class UnaryOperatorBuilder extends AbstractOperatorBuilder */ protected $leftExpression; - public function __construct(string $operator, $leftExpression, ?string $file = null, int $line = 0, int $char = 0) + public function __construct(string $operator, $leftExpression, string $file = null, int $line = 0, int $char = 0) { $this->operator = $operator; $this->leftExpression = $leftExpression; @@ -50,7 +48,7 @@ public function __construct(string $operator, $leftExpression, ?string $file = n */ public function get(): array { - if (is_object($this->leftExpression) && method_exists($this->leftExpression, 'get')) { + if (\is_object($this->leftExpression) && method_exists($this->leftExpression, 'get')) { $expr = $this->leftExpression->get(); } else { $expr = $this->leftExpression; diff --git a/Library/Cache/Manager.php b/Library/Cache/Manager.php index da15216156..16b6b70824 100644 --- a/Library/Cache/Manager.php +++ b/Library/Cache/Manager.php @@ -50,7 +50,7 @@ class Manager * * @param CallGathererPass|null $gatherer */ - public function setGatherer(?CallGathererPass $gatherer = null): void + public function setGatherer(CallGathererPass $gatherer = null): void { $this->gatherer = $gatherer; } diff --git a/Library/Cache/MethodCache.php b/Library/Cache/MethodCache.php index 5a1e497f40..b5116d7e82 100644 --- a/Library/Cache/MethodCache.php +++ b/Library/Cache/MethodCache.php @@ -13,8 +13,6 @@ namespace Zephir\Cache; -use ReflectionClass; -use ReflectionException; use Zephir\Class\Definition\Definition; use Zephir\CompilationContext; use Zephir\Passes\CallGathererPass; @@ -48,7 +46,7 @@ public function __construct(protected ?CallGathererPass $gatherer = null) /** * Retrieves/Creates a function cache for a method call. * - * @throws ReflectionException + * @throws \ReflectionException */ public function get(CompilationContext $compilationContext, string $methodName, Variable $caller): string { @@ -167,7 +165,7 @@ public function get(CompilationContext $compilationContext, string $methodName, /** * Checks if the class is suitable for caching. * - * @param Definition|ReflectionClass|null $classDefinition + * @param Definition|\ReflectionClass|null $classDefinition * * @return bool */ @@ -177,12 +175,12 @@ private function isClassCacheable($classDefinition = null): bool return true; } - if (!($classDefinition instanceof ReflectionClass)) { + if (!($classDefinition instanceof \ReflectionClass)) { return false; } - return $classDefinition->isInternal() && - $classDefinition->isInstantiable() && - in_array($classDefinition->getExtension()->getName(), ['Reflection', 'Core', 'SPL']); + return $classDefinition->isInternal() + && $classDefinition->isInstantiable() + && in_array($classDefinition->getExtension()->getName(), ['Reflection', 'Core', 'SPL']); } } diff --git a/Library/Cache/StaticMethodCache.php b/Library/Cache/StaticMethodCache.php index faf119048f..d22f1c07f5 100644 --- a/Library/Cache/StaticMethodCache.php +++ b/Library/Cache/StaticMethodCache.php @@ -11,7 +11,6 @@ namespace Zephir\Cache; -use ReflectionMethod; use Zephir\CompilationContext; /** @@ -41,7 +40,7 @@ public function get(CompilationContext $compilationContext, $method): string return 'NULL, 0'; } - if (!($method instanceof ReflectionMethod)) { + if (!($method instanceof \ReflectionMethod)) { $completeName = $method->getClassDefinition()->getCompleteName(); /** @@ -71,7 +70,7 @@ public function get(CompilationContext $compilationContext, $method): string $functionCache->setMustInitNull(true); $functionCache->setReusable(false); - if (!($method instanceof ReflectionMethod)) { + if (!($method instanceof \ReflectionMethod)) { $this->cache[$completeName][$method->getName()] = $functionCache; } diff --git a/Library/Call.php b/Library/Call.php index 0d8720c9e0..24aac202cc 100644 --- a/Library/Call.php +++ b/Library/Call.php @@ -52,7 +52,7 @@ class Call /** * @var mixed|null */ - protected $reflection = null; + protected $reflection; /** * @var array @@ -382,7 +382,7 @@ public function getResolvedParams(array $parameters, CompilationContext $compila case 'int': case 'uint': case 'long': - /* ulong must be stored in string */ + /* ulong must be stored in string */ case 'ulong': $parameterTempVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext); $params[] = $compilationContext->backend->getVariableCode($parameterTempVariable); diff --git a/Library/Class/Constant.php b/Library/Class/Constant.php index 1b96b66132..e7dd91a074 100644 --- a/Library/Class/Constant.php +++ b/Library/Class/Constant.php @@ -13,7 +13,6 @@ namespace Zephir\Class; -use ReflectionException; use Zephir\CompilationContext; use Zephir\Exception; use Zephir\Expression\Constants; @@ -83,7 +82,7 @@ public function getType(): string * Process the value of the class constant if needed. * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function processValue(CompilationContext $compilationContext): void { @@ -112,7 +111,7 @@ public function processValue(CompilationContext $compilationContext): void * Produce the code to register a class constant. * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(CompilationContext $compilationContext): void { diff --git a/Library/Class/Definition/Definition.php b/Library/Class/Definition/Definition.php index 306573d06f..5fb1eb30b3 100644 --- a/Library/Class/Definition/Definition.php +++ b/Library/Class/Definition/Definition.php @@ -13,8 +13,6 @@ namespace Zephir\Class\Definition; -use ReflectionClass; -use ReflectionException; use Zephir\AliasManager; use Zephir\Class\Constant; use Zephir\Class\Entry; @@ -32,10 +30,6 @@ use Zephir\Exception\InvalidArgumentException; use Zephir\HeadersManager; use Zephir\StatementsBlock; -use function count; -use function gettype; -use function is_array; -use const DIRECTORY_SEPARATOR; /** * Represents a class/interface and their properties and methods. @@ -120,7 +114,7 @@ final class Definition extends AbstractDefinition protected Compiler $compiler; - public function __construct(protected string $namespace, string $name, ?string $shortName = null) + public function __construct(protected string $namespace, string $name, string $shortName = null) { $this->name = $name; $this->shortName = $shortName ?: $name; @@ -498,7 +492,7 @@ public function getConstant(string $constantName): ?Constant * * @throws CompilerException */ - public function addMethod(Method $method, ?array $statement = null): void + public function addMethod(Method $method, array $statement = null): void { $methodName = strtolower($method->getName()); if (isset($this->methods[$methodName])) { @@ -513,7 +507,7 @@ public function addMethod(Method $method, ?array $statement = null): void * * @throws CompilerException */ - public function updateMethod(Method $method, ?array $statement = null): void + public function updateMethod(Method $method, array $statement = null): void { $methodName = strtolower($method->getName()); if (!isset($this->methods[$methodName])) { @@ -575,7 +569,7 @@ public function hasMethod(string $methodName): bool $extendsClassDefinition = $this->compiler->getInternalClassDefinition( $extendsClassDefinition->getName() ); - } catch (ReflectionException $e) { + } catch (\ReflectionException $e) { // Do nothing return false; } @@ -651,7 +645,7 @@ public function getPossibleMethodName(string $methodName): ?string * * @throws Exception */ - public function getClassEntry(?CompilationContext $compilationContext = null): string + public function getClassEntry(CompilationContext $compilationContext = null): string { if ($this->external) { if ($compilationContext === null) { @@ -700,7 +694,7 @@ public function getExternalHeader(): string { $parts = explode('\\', $this->namespace); - return 'ext/'.strtolower($parts[0].DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $this->namespace).DIRECTORY_SEPARATOR.$this->name).'.zep'; + return 'ext/'.strtolower($parts[0].\DIRECTORY_SEPARATOR.str_replace('\\', \DIRECTORY_SEPARATOR, $this->namespace).\DIRECTORY_SEPARATOR.$this->name).'.zep'; } /** @@ -727,8 +721,8 @@ public function checkInterfaceImplements(self $classDefinition, self $interfaceD } $implementedMethod = $classDefinition->getMethod($method->getName()); - if ($implementedMethod->getNumberOfRequiredParameters() > $method->getNumberOfRequiredParameters() || - $implementedMethod->getNumberOfParameters() < $method->getNumberOfParameters() + if ($implementedMethod->getNumberOfRequiredParameters() > $method->getNumberOfRequiredParameters() + || $implementedMethod->getNumberOfParameters() < $method->getNumberOfParameters() ) { throw new CompilerException( sprintf( @@ -848,7 +842,7 @@ public function addStaticInitMethod(StatementsBlock $statementsBlock): void * Compiles a class/interface. * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(CompilationContext $compilationContext): void { @@ -878,7 +872,7 @@ public function compile(CompilationContext $compilationContext): void $methods = &$this->methods; $initMethod = $this->getLocalOrParentInitMethod(); - if (count($methods) > 0 || $initMethod) { + if (\count($methods) > 0 || $initMethod) { $methodEntry = strtolower($this->getCNamespace()).'_'.strtolower($this->getName()).'_method_entry'; } else { $methodEntry = 'NULL'; @@ -968,7 +962,7 @@ public function compile(CompilationContext $compilationContext): void $interfaces = $this->interfaces; $compiler = $compilationContext->compiler; - if (is_array($interfaces)) { + if (\is_array($interfaces)) { $codePrinter->outputBlankLine(true); foreach ($interfaces as $interface) { @@ -1097,7 +1091,7 @@ public function compile(CompilationContext $compilationContext): void $codePrinter->output('ZEPHIR_INIT_CLASS('.$this->getCNamespace().'_'.$this->getName().');'); $codePrinter->outputBlankLine(); - if (self::TYPE_CLASS === $this->getType() && count($methods) > 0) { + if (self::TYPE_CLASS === $this->getType() && \count($methods) > 0) { foreach ($methods as $method) { if (!$method->isInternal()) { $codePrinter->output('PHP_METHOD('.$this->getCNamespace().'_'.$this->getName().', '.$method->getName().');'); @@ -1126,7 +1120,7 @@ public function compile(CompilationContext $compilationContext): void $argInfo->render(); } - if (count($methods) > 0) { + if (\count($methods) > 0) { $codePrinter->output( sprintf( 'ZEPHIR_INIT_FUNCS(%s_%s_method_entry) {', @@ -1156,7 +1150,7 @@ public function compile(CompilationContext $compilationContext): void $codePrinter->output('#if PHP_VERSION_ID >= 80000'); $codePrinter->output( sprintf( - // TODO: Rename to ZEND_ME + // TODO: Rename to ZEND_ME "\tPHP_ME(%s_%s, %s, %s, %s)", $this->getCNamespace(), $this->getName(), @@ -1168,7 +1162,7 @@ public function compile(CompilationContext $compilationContext): void $codePrinter->output('#else'); $codePrinter->output( sprintf( - // TODO: Rename to ZEND_ME + // TODO: Rename to ZEND_ME "\tPHP_ME(%s_%s, %s, NULL, %s)", $this->getCNamespace(), $this->getName(), @@ -1244,7 +1238,7 @@ public function setAliasManager(AliasManager $aliasManager): void /** * Builds a class definition from reflection. */ - public static function buildFromReflection(ReflectionClass $class): self + public static function buildFromReflection(\ReflectionClass $class): self { $classDefinition = new self($class->getNamespaceName(), $class->getName(), $class->getShortName()); @@ -1263,7 +1257,7 @@ public static function buildFromReflection(ReflectionClass $class): self if (!$params['mandatory']) { try { $params['default'] = $row->getDefaultValue(); - } catch (ReflectionException $e) { + } catch (\ReflectionException $e) { // TODO: dummy default value $params['default'] = true; } @@ -1284,7 +1278,7 @@ public static function buildFromReflection(ReflectionClass $class): self } foreach ($class->getConstants() as $constantName => $constantValue) { - $type = self::convertPhpConstantType(gettype($constantValue)); + $type = self::convertPhpConstantType(\gettype($constantValue)); $classConstant = new Constant($constantName, ['value' => $constantValue, 'type' => $type], null); $classDefinition->addConstant($classConstant); } diff --git a/Library/Class/Entry.php b/Library/Class/Entry.php index 03a9d56e9c..9aba0a2e22 100644 --- a/Library/Class/Entry.php +++ b/Library/Class/Entry.php @@ -13,7 +13,6 @@ namespace Zephir\Class; -use ReflectionClass; use Zephir\Class\Definition\Definition; use Zephir\CompilationContext; use Zephir\Exception; @@ -73,7 +72,7 @@ public function get(): string } if (class_exists($this->classname) || interface_exists($this->classname)) { - $reflection = new ReflectionClass($this->classname); + $reflection = new \ReflectionClass($this->classname); $className = $reflection->getName(); /** diff --git a/Library/Class/Method/Method.php b/Library/Class/Method/Method.php index 6607734448..00bfe9cd69 100644 --- a/Library/Class/Method/Method.php +++ b/Library/Class/Method/Method.php @@ -13,7 +13,6 @@ namespace Zephir\Class\Method; -use ReflectionException; use Zephir\Branch; use Zephir\BranchManager; use Zephir\Cache\Manager; @@ -33,11 +32,7 @@ use Zephir\StatementsBlock; use Zephir\SymbolTable; use Zephir\Variable\Variable; -use function array_key_exists; -use function count; -use function in_array; -use function is_array; -use function is_object; + use function Zephir\add_slashes; /** @@ -136,15 +131,15 @@ class Method protected ?Definition $classDefinition = null; public function __construct( - Definition $classDefinition, - protected array $visibility, - protected string $name, - protected ?Parameters $parameters = null, + Definition $classDefinition, + protected array $visibility, + protected string $name, + protected ?Parameters $parameters = null, protected ?StatementsBlock $statements = null, - protected ?string $docblock = null, - ?array $returnType = null, - protected ?array $expression = [], - array $staticVariables = [], + protected ?string $docblock = null, + array $returnType = null, + protected ?array $expression = [], + array $staticVariables = [], ) { $this->classDefinition = $classDefinition; $this->staticVariables = $staticVariables; @@ -194,7 +189,7 @@ public function __construct( * * @param array|null $returnType */ - public function setReturnTypes(?array $returnType = null): void + public function setReturnTypes(array $returnType = null): void { $this->returnTypesRaw = $returnType; if (null === $returnType) { @@ -245,12 +240,12 @@ public function setReturnTypes(?array $returnType = null): void } } - if (count($castTypes) > 0) { + if (\count($castTypes) > 0) { $types['object'] = []; $this->returnClassTypes = $castTypes; } - if (count($types) > 0) { + if (\count($types) > 0) { $this->returnTypes = $types; } } @@ -296,47 +291,47 @@ public function isEmpty(): bool */ public function checkVisibility(array $visibility, string $name, array $original = null): void { - if (count($visibility) > 1) { - if (in_array('public', $visibility) && in_array('protected', $visibility)) { + if (\count($visibility) > 1) { + if (\in_array('public', $visibility) && \in_array('protected', $visibility)) { throw new CompilerException("Method '$name' cannot be 'public' and 'protected' at the same time", $original); } - if (in_array('public', $visibility) && in_array('private', $visibility)) { + if (\in_array('public', $visibility) && \in_array('private', $visibility)) { throw new CompilerException("Method '$name' cannot be 'public' and 'private' at the same time", $original); } - if (in_array('private', $visibility) && in_array('protected', $visibility)) { + if (\in_array('private', $visibility) && \in_array('protected', $visibility)) { throw new CompilerException("Method '$name' cannot be 'protected' and 'private' at the same time", $original); } - if (in_array('private', $visibility) && in_array('internal', $visibility)) { + if (\in_array('private', $visibility) && \in_array('internal', $visibility)) { throw new CompilerException("Method '$name' cannot be 'internal' and 'private' at the same time", $original); } - if (in_array('protected', $visibility) && in_array('internal', $visibility)) { + if (\in_array('protected', $visibility) && \in_array('internal', $visibility)) { throw new CompilerException("Method '$name' cannot be 'internal' and 'protected' at the same time", $original); } - if (in_array('public', $visibility) && in_array('internal', $visibility)) { + if (\in_array('public', $visibility) && \in_array('internal', $visibility)) { throw new CompilerException("Method '$name' cannot be 'internal' and 'public' at the same time", $original); } } if ('__construct' === $name) { - if (in_array('static', $visibility)) { + if (\in_array('static', $visibility)) { throw new CompilerException("Constructors cannot be 'static'", $original); } } elseif ('__destruct' === $name) { - if (in_array('static', $visibility)) { + if (\in_array('static', $visibility)) { throw new CompilerException("Destructors cannot be 'static'", $original); } } - $this->isAbstract = in_array('abstract', $visibility); - $this->isStatic = in_array('static', $visibility); - $this->isFinal = in_array('final', $visibility); - $this->isPublic = in_array('public', $visibility); - $this->isInternal = in_array('internal', $visibility); + $this->isAbstract = \in_array('abstract', $visibility); + $this->isStatic = \in_array('static', $visibility); + $this->isFinal = \in_array('final', $visibility); + $this->isPublic = \in_array('public', $visibility); + $this->isInternal = \in_array('internal', $visibility); } /** @@ -502,7 +497,7 @@ public function getParameters(): ?Parameters */ public function hasReturnTypes(): bool { - return count($this->returnTypes) || count($this->returnClassTypes); + return \count($this->returnTypes) || \count($this->returnClassTypes); } /** @@ -521,7 +516,7 @@ public function areReturnTypesIntCompatible(): bool $types = ['int', 'uint', 'char', 'uchar', 'long', 'ulong']; foreach ($this->returnTypes as $returnType => $definition) { - if (in_array($returnType, $types)) { + if (\in_array($returnType, $types)) { return true; } } @@ -626,7 +621,7 @@ public function getNumberOfRequiredParameters(): int */ public function hasModifier(string $modifier): bool { - return in_array($modifier, $this->visibility); + return \in_array($modifier, $this->visibility); } /** @@ -639,7 +634,7 @@ public function getVisibility(): array public function isDeprecated(): bool { - return !empty($this->visibility) && in_array('deprecated', $this->visibility, true); + return !empty($this->visibility) && \in_array('deprecated', $this->visibility, true); } /** @@ -720,7 +715,7 @@ public function isMixed(): bool */ public function isPrivate(): bool { - return in_array('private', $this->visibility); + return \in_array('private', $this->visibility); } /** @@ -728,7 +723,7 @@ public function isPrivate(): bool */ public function isProtected(): bool { - return in_array('protected', $this->visibility); + return \in_array('protected', $this->visibility); } /** @@ -861,7 +856,7 @@ public function removeMemoryStackReferences(SymbolTable $symbolTable, string $co * Assigns a default value. * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function assignDefaultValue(array $parameter, CompilationContext $compilationContext): string { @@ -1221,7 +1216,7 @@ public function assignZvalValue(array $parameter, CompilationContext $compilatio { $dataType = $this->getParamDataType($parameter); - if (in_array($dataType, ['variable', 'callable', 'object', 'resource', 'mixed'])) { + if (\in_array($dataType, ['variable', 'callable', 'object', 'resource', 'mixed'])) { return ''; } @@ -1273,7 +1268,7 @@ public function preCompile(CompilationContext $compilationContext): void $typeInference = null; $callGathererPass = null; - if (is_object($this->statements)) { + if (\is_object($this->statements)) { $compilationContext->currentMethod = $this; /** @@ -1317,7 +1312,7 @@ public function preCompile(CompilationContext $compilationContext): void * Compiles the method. * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(CompilationContext $compilationContext): void { @@ -1452,12 +1447,12 @@ public function compile(CompilationContext $compilationContext): void */ if (!empty($parameter['const'])) { $symbol->setReadOnly(true); - if (is_object($symbolParam)) { + if (\is_object($symbolParam)) { $symbolParam->setReadOnly(true); } } - if (is_object($symbolParam)) { + if (\is_object($symbolParam)) { /** * Parameters are marked as 'external' */ @@ -1527,7 +1522,7 @@ public function compile(CompilationContext $compilationContext): void /** * Compile the block of statements if any */ - if (is_object($this->statements)) { + if (\is_object($this->statements)) { $compilationContext->staticContext = $this->hasModifier('static'); /** @@ -1566,7 +1561,7 @@ public function compile(CompilationContext $compilationContext): void * variable is modified so as do the proper separation. */ $parametersToSeparate = []; - if (is_object($this->statements)) { + if (\is_object($this->statements)) { if (!$this->localContext instanceof LocalContextPass) { $writeDetector = new WriteDetector(); } @@ -1636,7 +1631,7 @@ public function compile(CompilationContext $compilationContext): void $name = match ($dataType) { 'object', 'callable', 'resource', 'variable', 'mixed' => $parameter['name'], - default => $parameter['name'] . '_param', + default => $parameter['name'].'_param', }; /** @@ -1784,7 +1779,7 @@ public function compile(CompilationContext $compilationContext): void if (!$variable->isUsed()) { $node = $variable->getLastUsedNode(); - if (is_array($node)) { + if (\is_array($node)) { $expression = $node['expr'] ?? $node; $compilationContext->logger->warning( 'Variable "'.$variable->getName().'" assigned but not used in '.$completeName.'::'.$this->getName(), @@ -1799,7 +1794,7 @@ public function compile(CompilationContext $compilationContext): void } } - if (count($usedVariables)) { + if (\count($usedVariables)) { $codePrinter->preOutputBlankLine(); } @@ -1818,14 +1813,14 @@ public function compile(CompilationContext $compilationContext): void )); foreach ($requiredParams as $requiredParam) { - $tempCodePrinter->output("\t"."\t".$this->detectParam($requiredParam, $compilationContext)); + $tempCodePrinter->output("\t\t".$this->detectParam($requiredParam, $compilationContext)); } if (!empty($optionalParams)) { - $tempCodePrinter->output("\t"."\t".'Z_PARAM_OPTIONAL'); + $tempCodePrinter->output("\t\t".'Z_PARAM_OPTIONAL'); foreach ($optionalParams as $optionalParam) { - $tempCodePrinter->output("\t"."\t".$this->detectParam($optionalParam, $compilationContext)); + $tempCodePrinter->output("\t\t".$this->detectParam($optionalParam, $compilationContext)); } } @@ -1854,7 +1849,7 @@ public function compile(CompilationContext $compilationContext): void /** * Finalize the method compilation */ - if (is_object($this->statements) && !empty($statement = $this->statements->getLastStatement())) { + if (\is_object($this->statements) && !empty($statement = $this->statements->getLastStatement())) { /** * If the last statement is not a 'return' or 'throw' we need to * restore the memory stack if needed. @@ -1904,7 +1899,7 @@ public function compile(CompilationContext $compilationContext): void */ public function hasChildReturnStatementType(array $statement): bool { - if (!isset($statement['statements']) || !is_array($statement['statements'])) { + if (!isset($statement['statements']) || !\is_array($statement['statements'])) { return false; } @@ -1952,7 +1947,7 @@ public function getInternalName(): string /** * Returns arginfo name for current method. */ - public function getArgInfoName(?Definition $classDefinition = null): string + public function getArgInfoName(Definition $classDefinition = null): string { if ($classDefinition instanceof Definition) { return sprintf( @@ -1990,7 +1985,7 @@ public function isReturnTypesHintDetermined(): bool return true; } - if (0 === count($this->returnTypes)) { + if (0 === \count($this->returnTypes)) { return false; } @@ -2003,14 +1998,14 @@ public function isReturnTypesHintDetermined(): bool } if (isset($definition['type']) && 'return-type-annotation' === $definition['type']) { - if ($this->areReturnTypesBoolCompatible() || - $this->areReturnTypesDoubleCompatible() || - $this->areReturnTypesIntCompatible() || - $this->areReturnTypesNullCompatible() || - $this->areReturnTypesStringCompatible() || - $this->areReturnTypesFalseCompatible() || - $this->areReturnTypesObjectCompatible() || - array_key_exists('array', $this->getReturnTypes()) + if ($this->areReturnTypesBoolCompatible() + || $this->areReturnTypesDoubleCompatible() + || $this->areReturnTypesIntCompatible() + || $this->areReturnTypesNullCompatible() + || $this->areReturnTypesStringCompatible() + || $this->areReturnTypesFalseCompatible() + || $this->areReturnTypesObjectCompatible() + || \array_key_exists('array', $this->getReturnTypes()) ) { continue; } @@ -2032,9 +2027,9 @@ public function isReturnTypesHintDetermined(): bool */ public function isReturnTypeNullableObject(): bool { - return count($this->returnTypes) === 2 && - isset($this->returnTypes['object']) && - isset($this->returnTypes['null']); + return \count($this->returnTypes) === 2 + && isset($this->returnTypes['object']) + && isset($this->returnTypes['null']); } /** @@ -2042,7 +2037,7 @@ public function isReturnTypeNullableObject(): bool */ public function isReturnTypeObject(): bool { - return count($this->returnTypes) === 1 && isset($this->returnTypes['object']); + return \count($this->returnTypes) === 1 && isset($this->returnTypes['object']); } /** @@ -2055,12 +2050,12 @@ public function areReturnTypesCompatible(): bool return true; } - $totalTypes = count($this->returnTypes); + $totalTypes = \count($this->returnTypes); // union types if ($totalTypes > 1) { $diff = array_diff(array_keys($this->returnTypes), array_keys($this->mayBeArgTypes)); - if (count($diff) === 0) { + if (\count($diff) === 0) { return true; } } @@ -2167,10 +2162,10 @@ public function detectParam(array $parameter, CompilationContext $compilationCon break; case 'variable': - if (isset($parameter['cast']) && - $parameter['cast']['type'] === 'variable' && - $parameter['cast']['value'] && - $this->classDefinition !== null + if (isset($parameter['cast']) + && $parameter['cast']['type'] === 'variable' + && $parameter['cast']['value'] + && $this->classDefinition !== null ) { $classEntry = (new ClassEntry($parameter['cast']['value'], $compilationContext))->get(); if ($hasDefaultNull) { diff --git a/Library/Class/Method/Parameters.php b/Library/Class/Method/Parameters.php index 8cc9799363..16b24a8037 100644 --- a/Library/Class/Method/Parameters.php +++ b/Library/Class/Method/Parameters.php @@ -13,16 +13,12 @@ namespace Zephir\Class\Method; -use ArrayAccess; -use Countable; -use Iterator; use Zephir\Exception\CompilerException; -use function count; /** * Represents the parameters defined in a method. */ -class Parameters implements Countable, Iterator, ArrayAccess +class Parameters implements \Countable, \Iterator, \ArrayAccess { private int $position = 0; @@ -67,7 +63,7 @@ public function getRequiredParameters(): array public function countRequiredParameters(): int { - return count($this->requiredParameters); + return \count($this->requiredParameters); } public function getOptionalParameters(): array @@ -77,7 +73,7 @@ public function getOptionalParameters(): array public function countOptionalParameters(): int { - return count($this->optionalParameters); + return \count($this->optionalParameters); } public function fetchParameters(bool $isMethodInternal): array @@ -117,7 +113,7 @@ public function fetchParameters(bool $isMethodInternal): array */ public function count(): int { - return count($this->parameters); + return \count($this->parameters); } public function rewind(): void diff --git a/Library/Class/Property.php b/Library/Class/Property.php index 0c7852af49..051f2d9214 100644 --- a/Library/Class/Property.php +++ b/Library/Class/Property.php @@ -13,7 +13,6 @@ namespace Zephir\Class; -use ReflectionException; use Zephir\Class\Definition\Definition; use Zephir\CompilationContext; use Zephir\Exception; @@ -23,8 +22,7 @@ use Zephir\Expression\Builder\Operators\BinaryOperator; use Zephir\StatementsBlock; use Zephir\Types\Types; -use function in_array; -use function is_array; + use function Zephir\add_slashes; /** @@ -34,15 +32,15 @@ class Property { public function __construct( protected Definition $classDefinition, - protected array $visibility, - protected string $name, - protected ?array $defaultValue, - protected ?string $docBlock = null, - protected ?array $original = null, + protected array $visibility, + protected string $name, + protected ?array $defaultValue, + protected ?string $docBlock = null, + protected ?array $original = null, ) { $this->checkVisibility($visibility, $name, $original); - if (!is_array($this->defaultValue)) { + if (!\is_array($this->defaultValue)) { $this->defaultValue = []; $this->defaultValue['type'] = 'null'; $this->defaultValue['value'] = null; @@ -93,15 +91,15 @@ public function getOriginal(): ?array /** * Checks for visibility congruence. */ - public function checkVisibility(array $visibility, string $name, ?array $original = null): void + public function checkVisibility(array $visibility, string $name, array $original = null): void { - if (in_array('public', $visibility) && in_array('protected', $visibility)) { + if (\in_array('public', $visibility) && \in_array('protected', $visibility)) { throw new CompilerException("Property '$name' cannot be 'public' and 'protected' at the same time", $original); } - if (in_array('public', $visibility) && in_array('private', $visibility)) { + if (\in_array('public', $visibility) && \in_array('private', $visibility)) { throw new CompilerException("Property '$name' cannot be 'public' and 'private' at the same time", $original); } - if (in_array('private', $visibility) && in_array('protected', $visibility)) { + if (\in_array('private', $visibility) && \in_array('protected', $visibility)) { throw new CompilerException("Property '$name' cannot be 'protected' and 'private' at the same time", $original); } } @@ -154,7 +152,7 @@ public function getDocBlock(): ?string */ public function isStatic(): bool { - return in_array('static', $this->visibility); + return \in_array('static', $this->visibility); } /** @@ -162,7 +160,7 @@ public function isStatic(): bool */ public function isPublic(): bool { - return in_array('public', $this->visibility); + return \in_array('public', $this->visibility); } /** @@ -170,7 +168,7 @@ public function isPublic(): bool */ public function isProtected(): bool { - return in_array('protected', $this->visibility); + return \in_array('protected', $this->visibility); } /** @@ -178,14 +176,14 @@ public function isProtected(): bool */ public function isPrivate(): bool { - return in_array('private', $this->visibility); + return \in_array('private', $this->visibility); } /** * Produce the code to register a property. * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(CompilationContext $compilationContext): void { @@ -276,7 +274,7 @@ protected function getLetStatement() ->setStatements($exprBuilder->statements()->block([$lsb])); } - protected function getBooleanCode($value): bool|string + protected function getBooleanCode($value): bool | string { if ('true' == $value || true === $value) { return '1'; @@ -294,7 +292,7 @@ protected function getBooleanCode($value): bool|string * * @param CompilationContext $compilationContext * @param string $type - * @param $value + * @param $value * * @throws Exception * @throws CompilerException diff --git a/Library/Code/ArgInfoDefinition.php b/Library/Code/ArgInfoDefinition.php index 33116ae4d6..de4c4d816c 100644 --- a/Library/Code/ArgInfoDefinition.php +++ b/Library/Code/ArgInfoDefinition.php @@ -17,8 +17,8 @@ use Zephir\Class\Method\Parameters; use Zephir\CompilationContext; use Zephir\Exception; + use function array_key_exists; -use function count; use function Zephir\escape_class; class ArgInfoDefinition @@ -30,11 +30,11 @@ class ArgInfoDefinition private bool $richFormat = true; public function __construct( - private string $name, - private Method $functionLike, - private Printer $codePrinter, + private string $name, + private Method $functionLike, + private Printer $codePrinter, private CompilationContext $compilationContext, - private bool $returnByRef = false + private bool $returnByRef = false ) { $this->parameters = $this->functionLike->getParameters(); } @@ -62,9 +62,9 @@ public function render(): void return; } - if ($this->richFormat && - $this->functionLike->isReturnTypesHintDetermined() && - $this->functionLike->areReturnTypesCompatible() + if ($this->richFormat + && $this->functionLike->isReturnTypesHintDetermined() + && $this->functionLike->areReturnTypesCompatible() ) { $this->richRenderStart(); @@ -124,7 +124,7 @@ public function render(): void private function richRenderStart(): void { - if (array_key_exists('object', $this->functionLike->getReturnTypes()) && 1 === count($this->functionLike->getReturnClassTypes())) { + if (\array_key_exists('object', $this->functionLike->getReturnTypes()) && 1 === \count($this->functionLike->getReturnClassTypes())) { $class = key($this->functionLike->getReturnClassTypes()); $class = escape_class($this->compilationContext->getFullName($class)); @@ -242,7 +242,7 @@ private function richRenderStart(): void return; } - if (count($this->functionLike->getReturnTypes()) > 1) { + if (\count($this->functionLike->getReturnTypes()) > 1) { $types = []; $mayBeTypes = $this->functionLike->getMayBeArgTypes(); foreach ($this->functionLike->getReturnTypes() as $type => $typeInfo) { @@ -253,7 +253,7 @@ private function richRenderStart(): void $types[] = $mayBeTypes[$type]; } - if (count($types) > 1) { + if (\count($types) > 1) { $this->codePrinter->output('#if PHP_VERSION_ID >= 80000'); $this->codePrinter->output( sprintf( @@ -423,7 +423,7 @@ private function renderEnd(): void private function hasParameters(): bool { - return null !== $this->parameters && count($this->parameters->getParameters()) > 0; + return null !== $this->parameters && \count($this->parameters->getParameters()) > 0; } private function defaultArrayValue(array $parameter): string @@ -490,7 +490,7 @@ private function getReturnType(): string return 'IS_VOID'; } - if (array_key_exists('array', $this->functionLike->getReturnTypes())) { + if (\array_key_exists('array', $this->functionLike->getReturnTypes())) { return 'IS_ARRAY'; } diff --git a/Library/Code/Builder/Struct.php b/Library/Code/Builder/Struct.php index b9528f64f2..a5e6ff1fc8 100644 --- a/Library/Code/Builder/Struct.php +++ b/Library/Code/Builder/Struct.php @@ -52,7 +52,7 @@ public function __toString(): string /** * @param string $field - * @param string $type + * @param string $type * * @throws InvalidArgumentException */ @@ -72,10 +72,10 @@ public function addProperty(string $field, string $type): void * @param array $global * @param string $namespace * + * @return string + * * @throws RuntimeException * @throws InvalidArgumentException - * - * @return string */ public function getCDefault(string $name, array $global, string $namespace): string { @@ -155,6 +155,7 @@ public function getInitEntry(string $name, array $global, string $namespace): st /** * Generates the internal c-type according to the php's type. + * * @throws InvalidArgumentException */ protected function convertToCType(string $type): string diff --git a/Library/CompilationContext.php b/Library/CompilationContext.php index 41457c2bad..c2522a6db1 100644 --- a/Library/CompilationContext.php +++ b/Library/CompilationContext.php @@ -23,7 +23,6 @@ use Zephir\Code\Printer; use Zephir\Exception\CompilerException; use Zephir\Passes\StaticTypeInference; -use function in_array; /** * This class encapsulates important entities required during compilation @@ -163,7 +162,7 @@ public function getFullName(string $className): string */ public function classLookup(string $className, array $statement = null): AbstractDefinition { - if (!in_array($className, ['self', 'static', 'parent'])) { + if (!\in_array($className, ['self', 'static', 'parent'])) { $className = $this->getFullName($className); if ($this->compiler->isClass($className)) { return $this->compiler->getClassDefinition($className); @@ -172,7 +171,7 @@ public function classLookup(string $className, array $statement = null): Abstrac throw new CompilerException("Cannot locate class '$className'", $statement); } - if (in_array($className, ['self', 'static'])) { + if (\in_array($className, ['self', 'static'])) { return $this->classDefinition; } diff --git a/Library/CompiledExpression.php b/Library/CompiledExpression.php index dadc5db02c..ec5fc2df58 100644 --- a/Library/CompiledExpression.php +++ b/Library/CompiledExpression.php @@ -13,8 +13,6 @@ namespace Zephir; -use Closure; - /** * This represents a compiled expression, the object can be used to check * if the expression type is able to used in certain types of the application. @@ -97,7 +95,7 @@ public function isIntCompatibleType(): bool */ public function resolve(?string $result, CompilationContext $compilationContext): string { - if (!($this->code instanceof Closure)) { + if (!($this->code instanceof \Closure)) { return $this->code; } diff --git a/Library/Compiler.php b/Library/Compiler.php index 57f49ca5f1..a97056c84c 100644 --- a/Library/Compiler.php +++ b/Library/Compiler.php @@ -13,13 +13,8 @@ namespace Zephir; -use DirectoryIterator; use Psr\Log\LoggerAwareTrait; use Psr\Log\NullLogger; -use RecursiveDirectoryIterator; -use RecursiveIteratorIterator; -use ReflectionClass; -use ReflectionException; use Zephir\Backend\Backend; use Zephir\Backend\FcallManagerInterface; use Zephir\Backend\StringsManager; @@ -37,12 +32,6 @@ use Zephir\Exception\RuntimeException; use Zephir\FileSystem\FileSystemInterface; use Zephir\Parser\Manager; -use function count; -use function dirname; -use function extension_loaded; -use function is_array; -use function is_string; -use const DIRECTORY_SEPARATOR; final class Compiler { @@ -131,7 +120,7 @@ private function resolvePrototypesPath(): ?string // fallback if (empty($prototypesPath)) { - $prototypesPath = dirname(__DIR__).'/prototypes'; + $prototypesPath = \dirname(__DIR__).'/prototypes'; } if (!is_dir($prototypesPath) || !is_readable($prototypesPath)) { @@ -207,7 +196,7 @@ public function addFunction(FunctionDefinition $func, array $statement = []): vo */ public function loadExternalClass(string $className, string $location): bool { - $filePath = $location.DIRECTORY_SEPARATOR.strtolower(str_replace('\\', DIRECTORY_SEPARATOR, $className)).'.zep'; + $filePath = $location.\DIRECTORY_SEPARATOR.strtolower(str_replace('\\', \DIRECTORY_SEPARATOR, $className)).'.zep'; /** * Fix the class name. @@ -302,7 +291,7 @@ public function isBundledInterface(string $className): bool /** * Returns class the class definition from a given class name. */ - public function getClassDefinition(string $className): Definition|bool + public function getClassDefinition(string $className): Definition | bool { foreach ($this->definitions as $key => $value) { if (!strcasecmp($key, $className)) { @@ -325,12 +314,12 @@ public function addClassDefinition(CompilerFileAnonymous $file, Definition $clas /** * Returns class the class definition from a given class name. * - * @throws ReflectionException + * @throws \ReflectionException */ public function getInternalClassDefinition(string $className): Definition { if (!isset(self::$internalDefinitions[$className])) { - $reflection = new ReflectionClass($className); + $reflection = new \ReflectionClass($className); self::$internalDefinitions[$className] = Definition::buildFromReflection($reflection); } @@ -391,7 +380,7 @@ public function getGccFlags(bool $development = false): string $gccFlags = getenv('CFLAGS'); - if (!is_string($gccFlags)) { + if (!\is_string($gccFlags)) { if (false === $development) { $gccVersion = $this->getGccVersion(); if (version_compare($gccVersion, '4.6.0', '>=')) { @@ -429,8 +418,8 @@ public function preCompileHeaders(): void $phpIncludes = $this->getPhpIncludeDirs(); - /** @var DirectoryIterator $file */ - foreach (new DirectoryIterator('ext/kernel') as $file) { + /** @var \DirectoryIterator $file */ + foreach (new \DirectoryIterator('ext/kernel') as $file) { if ($file->isDir() || $file->getExtension() !== 'h') { continue; } @@ -453,7 +442,7 @@ public function preCompileHeaders(): void * Generates the C sources from Zephir without compiling them. * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function generate(bool $fromGenerate = false): bool { @@ -466,7 +455,7 @@ public function generate(bool $fromGenerate = false): bool * Check whether there are external dependencies. */ $externalDependencies = $this->config->get('external-dependencies'); - if (is_array($externalDependencies)) { + if (\is_array($externalDependencies)) { foreach ($externalDependencies as $dependencyNs => $location) { if (!file_exists($location)) { throw new CompilerException( @@ -484,8 +473,8 @@ public function generate(bool $fromGenerate = false): bool /** * Round 1. pre-compile all files in memory */ - $this->recursivePreCompile(str_replace('\\', DIRECTORY_SEPARATOR, $namespace)); - if (!count($this->files)) { + $this->recursivePreCompile(str_replace('\\', \DIRECTORY_SEPARATOR, $namespace)); + if (!\count($this->files)) { throw new Exception( "Zephir files to compile couldn't be found. Did you add a first class to the extension?" ); @@ -520,7 +509,7 @@ public function generate(bool $fromGenerate = false): bool * Convert C-constants into PHP constants. */ $constantsSources = $this->config->get('constants-sources'); - if (is_array($constantsSources)) { + if (\is_array($constantsSources)) { $this->loadConstantsSources($constantsSources); } @@ -528,7 +517,7 @@ public function generate(bool $fromGenerate = false): bool * Set extension globals. */ $globals = $this->config->get('globals'); - if (is_array($globals)) { + if (\is_array($globals)) { $this->setExtensionGlobals($globals); } @@ -540,7 +529,7 @@ public function generate(bool $fromGenerate = false): bool FunctionCall::addOptimizerDir("{$optimizersPath}/FunctionCall"); $customOptimizersPaths = $this->config->get('optimizer-dirs'); - if (is_array($customOptimizersPaths)) { + if (\is_array($customOptimizersPaths)) { foreach ($customOptimizersPaths as $directory) { FunctionCall::addOptimizerDir(realpath($directory)); } @@ -550,7 +539,7 @@ public function generate(bool $fromGenerate = false): bool * Load additional extension prototypes. */ $prototypesPath = $this->resolvePrototypesPath(); - foreach (new DirectoryIterator($prototypesPath) as $file) { + foreach (new \DirectoryIterator($prototypesPath) as $file) { if ($file->isDir() || $file->isDot()) { continue; } @@ -559,7 +548,7 @@ public function generate(bool $fromGenerate = false): bool $realPath = "{$file->getPath()}/{$file->getFilename()}"; $extension = $file->getBasename(".{$file->getExtension()}"); - if (!extension_loaded($extension)) { + if (!\extension_loaded($extension)) { require_once $realPath; } } @@ -568,15 +557,15 @@ public function generate(bool $fromGenerate = false): bool * Load customer additional extension prototypes. */ $prototypeDirs = $this->config->get('prototype-dir'); - if (is_array($prototypeDirs)) { + if (\is_array($prototypeDirs)) { foreach ($prototypeDirs as $prototype => $prototypeDir) { /** * Check if the extension is installed */ - if (!extension_loaded($prototype)) { + if (!\extension_loaded($prototype)) { $prototypeRealpath = realpath($prototypeDir); if ($prototypeRealpath) { - foreach (new RecursiveDirectoryIterator($prototypeRealpath) as $file) { + foreach (new \RecursiveDirectoryIterator($prototypeRealpath) as $file) { if ($file->isDir()) { continue; } @@ -645,7 +634,7 @@ public function generate(bool $fromGenerate = false): bool * Round 3.3. Load extra C-sources. */ $extraSources = $this->config->get('extra-sources'); - if (is_array($extraSources)) { + if (\is_array($extraSources)) { $this->extraFiles = $extraSources; } else { $this->extraFiles = []; @@ -655,7 +644,7 @@ public function generate(bool $fromGenerate = false): bool * Round 3.4. Load extra classes sources. */ $extraClasses = $this->config->get('extra-classes'); - if (is_array($extraClasses)) { + if (\is_array($extraClasses)) { foreach ($extraClasses as $value) { if (isset($value['source'])) { $this->extraFiles[] = $value['source']; @@ -668,7 +657,7 @@ public function generate(bool $fromGenerate = false): bool */ $namespace = str_replace('\\', '_', $namespace); $extensionName = $this->config->get('extension-name'); - if (empty($extensionName) || !is_string($extensionName)) { + if (empty($extensionName) || !\is_string($extensionName)) { $extensionName = $namespace; } @@ -715,7 +704,7 @@ public function generate(bool $fromGenerate = false): bool * * @throws Exception */ - public function compile(bool $development = false, ?int $jobs = null): void + public function compile(bool $development = false, int $jobs = null): void { $jobs = $jobs ?: 2; @@ -724,7 +713,7 @@ public function compile(bool $development = false, ?int $jobs = null): void */ $namespace = str_replace('\\', '_', $this->checkDirectory()); $extensionName = $this->config->get('extension-name'); - if (empty($extensionName) || !is_string($extensionName)) { + if (empty($extensionName) || !\is_string($extensionName)) { $extensionName = $namespace; } @@ -765,7 +754,7 @@ public function compile(bool $development = false, ?int $jobs = null): void $configureFix = ["var PHP_ANALYZER = 'disabled';", "var PHP_PGO = 'no';", "var PHP_PGI = 'no';"]; $hasChanged = false; - if (false === strpos($configureFile, $fixMarker)) { + if (!str_contains($configureFile, $fixMarker)) { $configureFile = $fixMarker.PHP_EOL.implode(PHP_EOL, $configureFix).PHP_EOL.$configureFile; $hasChanged = true; } @@ -830,7 +819,7 @@ public function compile(bool $development = false, ?int $jobs = null): void * * @throws ConfigException * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function api(array $options = [], bool $fromGenerate = false): void { @@ -838,7 +827,7 @@ public function api(array $options = [], bool $fromGenerate = false): void $this->generate(); } - $templatesPath = $this->templatesPath ?: dirname(__DIR__).'/templates'; + $templatesPath = $this->templatesPath ?: \dirname(__DIR__).'/templates'; $documentator = new Documentation($this->files, $this->config, $templatesPath, $options); $documentator->setLogger($this->logger); @@ -851,7 +840,7 @@ public function api(array $options = [], bool $fromGenerate = false): void * Generate IDE stubs. * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function stubs(bool $fromGenerate = false): void { @@ -976,7 +965,7 @@ public function createConfigFiles(string $project): bool $buildDirs = []; foreach ($compiledFiles as $file) { - $dir = dirname($file); + $dir = \dirname($file); if (!in_array($dir, $buildDirs)) { $buildDirs[] = $dir; @@ -1135,7 +1124,7 @@ public function processExtensionGlobals(string $namespace): array * Generate the extensions globals declaration. */ $globals = $this->config->get('globals'); - if (is_array($globals)) { + if (\is_array($globals)) { $structures = []; $variables = []; foreach ($globals as $name => $global) { @@ -1277,7 +1266,7 @@ public function processExtensionInfo(): string $phpinfo = ''; $info = $this->config->get('info'); - if (!is_array($info)) { + if (!\is_array($info)) { return $phpinfo; } @@ -1289,7 +1278,7 @@ public function processExtensionInfo(): string $headerArray[] = '"'.htmlentities($header).'"'; } - $phpinfo .= "\t".'php_info_print_table_header('.count($headerArray).', '. + $phpinfo .= "\t".'php_info_print_table_header('.\count($headerArray).', '. implode(', ', $headerArray).');'.PHP_EOL; } @@ -1300,7 +1289,7 @@ public function processExtensionInfo(): string $rowArray[] = '"'.htmlentities($field).'"'; } - $phpinfo .= "\t".'php_info_print_table_row('.count($rowArray).', '. + $phpinfo .= "\t".'php_info_print_table_row('.\count($rowArray).', '. implode(', ', $rowArray).');'.PHP_EOL; } } @@ -1495,7 +1484,7 @@ public function createProjectFiles(string $project): bool * Check if there are module/request/global destructors. */ $destructors = $this->config->get('destructors'); - if (is_array($destructors)) { + if (\is_array($destructors)) { $invokeRequestDestructors = $this->processCodeInjection($destructors, 'request'); $includes .= PHP_EOL.$invokeRequestDestructors[0]; $reqDestructors = $invokeRequestDestructors[1]; @@ -1517,7 +1506,7 @@ public function createProjectFiles(string $project): bool * Check if there are module/request/global initializers. */ $initializers = $this->config->get('initializers'); - if (is_array($initializers)) { + if (\is_array($initializers)) { $invokeRequestInitializers = $this->processCodeInjection($initializers, 'request'); $includes .= PHP_EOL.$invokeRequestInitializers[0]; $reqInitializers = $invokeRequestInitializers[1]; @@ -1535,7 +1524,7 @@ public function createProjectFiles(string $project): bool * Append extra details. */ $extraClasses = $this->config->get('extra-classes'); - if (is_array($extraClasses)) { + if (\is_array($extraClasses)) { foreach ($extraClasses as $value) { if (isset($value['init'])) { $completeClassInits[] = 'ZEPHIR_INIT('.$value['init'].')'; @@ -1631,7 +1620,7 @@ public function createProjectFiles(string $project): bool * Append extra headers. */ $extraClasses = $this->config->get('extra-classes'); - if (is_array($extraClasses)) { + if (\is_array($extraClasses)) { foreach ($extraClasses as $value) { if (isset($value['header'])) { $include = '#include "'.$value['header'].'"'; @@ -1752,7 +1741,7 @@ public function checkIfPhpized(): bool */ public static function getShortUserPath(string $path): string { - return str_replace('\\', '/', str_replace(getcwd().DIRECTORY_SEPARATOR, '', $path)); + return str_replace('\\', '/', str_replace(getcwd().\DIRECTORY_SEPARATOR, '', $path)); } /** @@ -1763,7 +1752,7 @@ public static function getShortUserPath(string $path): string public function generatePackageDependenciesM4(string $contentM4): string { $packageDependencies = $this->config->get('package-dependencies'); - if (!is_array($packageDependencies)) { + if (!\is_array($packageDependencies)) { return str_replace('%PROJECT_PACKAGE_DEPENDENCIES%', '', $contentM4); } @@ -1778,7 +1767,7 @@ public function generatePackageDependenciesM4(string $contentM4): string $operatorCmd = '--exact-version'; $ar = explode('=', $version); - if (1 === count($ar)) { + if (1 === \count($ar)) { if ('*' === $version) { $version = '0.0.0'; $operator = '>='; @@ -1831,7 +1820,7 @@ private function preCompile(string $filePath): void } if (preg_match('#\.zep$#', $filePath)) { - $className = str_replace(DIRECTORY_SEPARATOR, '\\', $filePath); + $className = str_replace(\DIRECTORY_SEPARATOR, '\\', $filePath); $className = preg_replace('#.zep$#', '', $className); $className = implode('\\', array_map('ucfirst', explode('\\', $className))); @@ -1857,7 +1846,7 @@ private function recursivePreCompile(string $path): void sprintf( "An invalid path was passed to the compiler. Unable to obtain the '%s%s%s' directory.", getcwd(), - DIRECTORY_SEPARATOR, + \DIRECTORY_SEPARATOR, $path ) ); @@ -1866,9 +1855,9 @@ private function recursivePreCompile(string $path): void /** * Pre compile all files. */ - $iterator = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($path), - RecursiveIteratorIterator::SELF_FIRST + $iterator = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($path), + \RecursiveIteratorIterator::SELF_FIRST ); $files = []; @@ -1891,8 +1880,8 @@ private function recursivePreCompile(string $path): void * * @deprecated * - * @param $src - * @param $dest + * @param $src + * @param $dest * @param string $pattern * @param mixed $callback * @@ -1901,7 +1890,7 @@ private function recursivePreCompile(string $path): void private function recursiveProcess($src, $dest, $pattern = null, $callback = 'copy') { $success = true; - $iterator = new DirectoryIterator($src); + $iterator = new \DirectoryIterator($src); foreach ($iterator as $item) { $pathName = $item->getPathname(); if (!is_readable($pathName)) { @@ -1913,13 +1902,13 @@ private function recursiveProcess($src, $dest, $pattern = null, $callback = 'cop if ($item->isDir()) { if ('.' != $fileName && '..' != $fileName && '.libs' != $fileName) { - if (!is_dir($dest.DIRECTORY_SEPARATOR.$fileName)) { - mkdir($dest.DIRECTORY_SEPARATOR.$fileName, 0755, true); + if (!is_dir($dest.\DIRECTORY_SEPARATOR.$fileName)) { + mkdir($dest.\DIRECTORY_SEPARATOR.$fileName, 0755, true); } - $this->recursiveProcess($pathName, $dest.DIRECTORY_SEPARATOR.$fileName, $pattern, $callback); + $this->recursiveProcess($pathName, $dest.\DIRECTORY_SEPARATOR.$fileName, $pattern, $callback); } } elseif (!$pattern || ($pattern && 1 === preg_match($pattern, $fileName))) { - $path = $dest.DIRECTORY_SEPARATOR.$fileName; + $path = $dest.\DIRECTORY_SEPARATOR.$fileName; $success = $success && \call_user_func($callback, $pathName, $path); } } @@ -1943,9 +1932,9 @@ private function recursiveDeletePath($path, $mask) return; } - $objects = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($path), - RecursiveIteratorIterator::SELF_FIRST + $objects = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($path), + \RecursiveIteratorIterator::SELF_FIRST ); foreach ($objects as $name => $object) { @@ -1993,7 +1982,7 @@ private function processAddSources(array $sources, string $project): array { $groupSources = []; foreach ($sources as $source) { - $dirName = str_replace(DIRECTORY_SEPARATOR, '/', dirname($source)); + $dirName = str_replace(\DIRECTORY_SEPARATOR, '/', \dirname($source)); if (!isset($groupSources[$dirName])) { $groupSources[$dirName] = []; } @@ -2024,11 +2013,11 @@ private function assertRequiredExtensionsIsPresent(): void $extensions = []; foreach ($extensionRequires as $value) { // TODO: We'll use this as an object in the future. - if (!is_string($value)) { + if (!\is_string($value)) { continue; } - if (!extension_loaded($value)) { + if (!\extension_loaded($value)) { $extensions[] = $value; } } @@ -2071,7 +2060,7 @@ private function checkKernelFile(string $src, string $dst): bool */ private function checkKernelFiles(): bool { - $kernelPath = 'ext'.DIRECTORY_SEPARATOR.'kernel'; + $kernelPath = 'ext'.\DIRECTORY_SEPARATOR.'kernel'; if (!file_exists($kernelPath)) { if (!mkdir($kernelPath, 0775, true)) { @@ -2116,7 +2105,7 @@ private function checkDirectory(): string throw new Exception('Extension namespace cannot be loaded'); } - if (!is_string($namespace)) { + if (!\is_string($namespace)) { throw new Exception('Extension namespace is invalid'); } @@ -2154,7 +2143,7 @@ private function getGccVersion(): string $lines = $this->filesystem->file('gcc-version'); $lines = array_filter($lines); - $lastLine = $lines[count($lines) - 1]; + $lastLine = $lines[\count($lines) - 1]; if (preg_match('/\d+\.\d+\.\d+/', $lastLine, $matches)) { return $matches[0]; } @@ -2166,7 +2155,7 @@ private function toUnixPaths(array $paths): array { return array_map( static function (string $path): string { - return str_replace(DIRECTORY_SEPARATOR, '/', $path); + return str_replace(\DIRECTORY_SEPARATOR, '/', $path); }, $paths ); diff --git a/Library/CompilerFile.php b/Library/CompilerFile.php index 6c9fd343ed..01c917e70c 100644 --- a/Library/CompilerFile.php +++ b/Library/CompilerFile.php @@ -15,7 +15,6 @@ use Psr\Log\LoggerAwareTrait; use Psr\Log\NullLogger; -use ReflectionException; use Zephir\Class\Constant; use Zephir\Class\Definition\Definition; use Zephir\Class\Definition\DefinitionRuntime; @@ -29,7 +28,6 @@ use Zephir\Exception\IllegalStateException; use Zephir\Exception\ParseException; use Zephir\FileSystem\FileSystemInterface; -use function is_array; /** * This class represents every file compiled in a project. @@ -192,10 +190,10 @@ public function addFunction(Compiler $compiler, FunctionDefinition $func, array * * @param Compiler $compiler * + * @return array + * * @throws ParseException * @throws IllegalStateException if the intermediate representation is not of type 'array' - * - * @return array */ public function genIR(Compiler $compiler): array { @@ -227,7 +225,7 @@ public function genIR(Compiler $compiler): array * @param CompilationContext $compilationContext * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compileClass(CompilationContext $compilationContext): void { @@ -239,6 +237,7 @@ public function compileClass(CompilationContext $compilationContext): void * * @param CompilationContext $compilationContext * @param FunctionDefinition $functionDefinition + * * @throws Exception */ public function compileFunction(CompilationContext $compilationContext, FunctionDefinition $functionDefinition) @@ -291,7 +290,7 @@ public function preCompileInterface($namespace, $topStatement, $docblock) $classDefinition->setType('interface'); - if (is_array($docblock)) { + if (\is_array($docblock)) { $classDefinition->setDocBlock($docblock['value']); } @@ -367,7 +366,7 @@ public function preCompileClass(CompilationContext $compilationContext, $namespa $classDefinition->setIsFinal((bool) $topStatement['final']); } - if (is_array($docblock)) { + if (\is_array($docblock)) { $classDefinition->setDocBlock($docblock['value']); } @@ -648,7 +647,7 @@ public function getCompiledFile(): string * * @param Compiler $compiler * - * @throws ReflectionException + * @throws \ReflectionException */ public function checkDependencies(Compiler $compiler) { @@ -945,7 +944,7 @@ public function getFilePath(): string /** * Creates the property shortcuts. * - * @param array $property + * @param array $property * @param Definition $classDefinition * * @throws CompilerException diff --git a/Library/CompilerFileAnonymous.php b/Library/CompilerFileAnonymous.php index 9785152744..957b48efaf 100644 --- a/Library/CompilerFileAnonymous.php +++ b/Library/CompilerFileAnonymous.php @@ -15,11 +15,9 @@ use Psr\Log\LoggerAwareTrait; use Psr\Log\NullLogger; -use ReflectionException; use Zephir\Class\Definition\Definition; use Zephir\Code\Printer; use Zephir\Compiler\FileInterface; -use function count; /** * This class represents an anonymous file created to dump @@ -40,11 +38,11 @@ final class CompilerFileAnonymous implements FileInterface /** * CompilerFileAnonymous constructor. * - * @param Definition $classDefinition + * @param Definition $classDefinition * @param Config $config * @param CompilationContext|null $context */ - public function __construct(Definition $classDefinition, Config $config, ?CompilationContext $context = null) + public function __construct(Definition $classDefinition, Config $config, CompilationContext $context = null) { $this->classDefinition = $classDefinition; $this->config = $config; @@ -84,7 +82,7 @@ public function isExternal(): bool * @param CompilationContext $compilationContext * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ private function compileClass(CompilationContext $compilationContext) { @@ -95,7 +93,7 @@ private function compileClass(CompilationContext $compilationContext) */ $classDefinition->compile($compilationContext); - $separators = str_repeat('../', count(explode('\\', $classDefinition->getCompleteName())) - 1); + $separators = str_repeat('../', \count(explode('\\', $classDefinition->getCompleteName())) - 1); $code = PHP_EOL; $code .= '#ifdef HAVE_CONFIG_H'.PHP_EOL; @@ -121,7 +119,7 @@ private function compileClass(CompilationContext $compilationContext) } } - if (count($this->headerCBlocks) > 0) { + if (\count($this->headerCBlocks) > 0) { $code .= implode(PHP_EOL, $this->headerCBlocks).PHP_EOL; } diff --git a/Library/Config.php b/Library/Config.php index a678d640b9..46ae923e6b 100644 --- a/Library/Config.php +++ b/Library/Config.php @@ -13,13 +13,10 @@ namespace Zephir; -use ArrayAccess; -use JsonSerializable; - /** * Manages compiler global configuration. */ -class Config implements ArrayAccess, JsonSerializable +class Config implements \ArrayAccess, \JsonSerializable { /** * Is config changed? diff --git a/Library/ConfigException.php b/Library/ConfigException.php index ab1ad6229a..845c8bf98a 100644 --- a/Library/ConfigException.php +++ b/Library/ConfigException.php @@ -11,11 +11,9 @@ namespace Zephir; -use Exception; - -class ConfigException extends Exception +class ConfigException extends \Exception { - public function __construct($message = '', $code = 0, Exception $previous = null) + public function __construct($message = '', $code = 0, \Exception $previous = null) { $message .= PHP_EOL.'Please see https://docs.zephir-lang.com/0.12/en/config for more information'; diff --git a/Library/Console/Application.php b/Library/Console/Application.php index 5232d00547..09207a46dc 100644 --- a/Library/Console/Application.php +++ b/Library/Console/Application.php @@ -13,7 +13,6 @@ namespace Zephir\Console; -use Exception; use Symfony\Component\Console\Application as BaseApplication; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\HelpCommand; @@ -28,7 +27,6 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\EventDispatcher\EventDispatcher; -use Throwable; use Zephir\Console\Command\ListCommand; use Zephir\Zephir; @@ -111,7 +109,7 @@ public function getLongVersion(): string * * @return int * - * @throws Exception|Throwable + * @throws \Exception|\Throwable */ public function doRun(InputInterface $input, OutputInterface $output): int { @@ -151,7 +149,7 @@ public function doRun(InputInterface $input, OutputInterface $output): int try { return parent::doRun($input, $output); - } catch (CommandNotFoundException|RuntimeException $e) { + } catch (CommandNotFoundException | RuntimeException $e) { fprintf(STDERR, $e->getMessage().PHP_EOL); return 1; diff --git a/Library/Console/Command/ApiCommand.php b/Library/Console/Command/ApiCommand.php index 578ff463dc..c6e5e5533d 100644 --- a/Library/Console/Command/ApiCommand.php +++ b/Library/Console/Command/ApiCommand.php @@ -21,8 +21,6 @@ use Zephir\Compiler; use Zephir\Config; -use function in_array; - /** * Generates an HTML API based on the classes exposed in the extension. */ @@ -80,7 +78,7 @@ protected function sanitizeOptionsFromInput(InputInterface $input): array $options = array_filter($input->getOptions(), function ($v, $k) use ($defaults) { $allowedOpts = array_keys($defaults); - return in_array($k, $allowedOpts, true) && null !== $v; + return \in_array($k, $allowedOpts, true) && null !== $v; }, ARRAY_FILTER_USE_BOTH); foreach ($options as $option => $value) { diff --git a/Library/Console/Command/CleanCommand.php b/Library/Console/Command/CleanCommand.php index 070f601ab5..8a9a4bec26 100644 --- a/Library/Console/Command/CleanCommand.php +++ b/Library/Console/Command/CleanCommand.php @@ -13,12 +13,12 @@ namespace Zephir\Console\Command; -use Exception; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zephir\Exception\FileSystemException; use Zephir\FileSystem\FileSystemInterface; + use function Zephir\is_windows; /** @@ -74,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ); return 1; - } catch (Exception | \Throwable $e) { + } catch (\Exception | \Throwable $e) { $io->getErrorStyle()->error($e->getMessage()); return 1; diff --git a/Library/Console/Command/DevelopmentModeAwareTrait.php b/Library/Console/Command/DevelopmentModeAwareTrait.php index c9054ac077..aba669eb56 100644 --- a/Library/Console/Command/DevelopmentModeAwareTrait.php +++ b/Library/Console/Command/DevelopmentModeAwareTrait.php @@ -15,8 +15,6 @@ use Symfony\Component\Console\Input\InputInterface; -use const PHP_DEBUG; - trait DevelopmentModeAwareTrait { /** @@ -29,7 +27,7 @@ trait DevelopmentModeAwareTrait protected function isDevelopmentModeEnabled(InputInterface $input): bool { if (false === $input->getOption('no-dev')) { - return $input->getOption('dev') || PHP_DEBUG; + return $input->getOption('dev') || \PHP_DEBUG; } return false; diff --git a/Library/Console/Command/GenerateCommand.php b/Library/Console/Command/GenerateCommand.php index a05cd17d86..e5e2871abf 100644 --- a/Library/Console/Command/GenerateCommand.php +++ b/Library/Console/Command/GenerateCommand.php @@ -22,8 +22,6 @@ use Zephir\Exception\ExceptionInterface; use Zephir\Exception\InvalidArgumentException; -use function extension_loaded; - /** * Generate Command * @@ -57,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $trace = $input->getOption('trace'); - if (extension_loaded('timecop') && 1 == ini_get('timecop.func_override')) { + if (\extension_loaded('timecop') && 1 == ini_get('timecop.func_override')) { $io->getErrorStyle()->warning( <<sanitizeNamespace($input->getArgument('namespace')); // Tell the user the name could be reserved by another extension - if (extension_loaded($namespace)) { + if (\extension_loaded($namespace)) { $this->logger->warning('This extension can have conflicts with an existing loaded extension'); } $this->config->set('namespace', $namespace); $this->config->set('name', $namespace); - if (!is_dir("{$namespace}/{$namespace}")) { - mkdir("{$namespace}/{$namespace}", 0755, true); + if (!\is_dir("{$namespace}/{$namespace}")) { + \mkdir("{$namespace}/{$namespace}", 0755, true); } - chdir($namespace); + \chdir($namespace); // Create 'kernel' - if (!is_dir('ext/kernel')) { - mkdir('ext/kernel', 0755, true); + if (!\is_dir('ext/kernel')) { + \mkdir('ext/kernel', 0755, true); } // Copy the latest kernel files @@ -131,14 +122,14 @@ private function sanitizeNamespace(string $namespace): string * * @return void */ - private function recursiveProcess(string $src, string $dst, ?string $pattern = null, string $callback = 'copy'): void + private function recursiveProcess(string $src, string $dst, string $pattern = null, string $callback = 'copy'): void { $success = true; - $iterator = new DirectoryIterator($src); + $iterator = new \DirectoryIterator($src); foreach ($iterator as $item) { $pathName = $item->getPathname(); - if (!is_readable($pathName)) { + if (!\is_readable($pathName)) { $this->logger->error('File is not readable :'.$pathName); continue; } @@ -147,13 +138,13 @@ private function recursiveProcess(string $src, string $dst, ?string $pattern = n if ($item->isDir()) { if ('.' != $fileName && '..' != $fileName && '.libs' != $fileName) { - if (!is_dir($dst.DIRECTORY_SEPARATOR.$fileName)) { - mkdir($dst.DIRECTORY_SEPARATOR.$fileName, 0755, true); + if (!\is_dir($dst.\DIRECTORY_SEPARATOR.$fileName)) { + \mkdir($dst.\DIRECTORY_SEPARATOR.$fileName, 0755, true); } - $this->recursiveProcess($pathName, $dst.DIRECTORY_SEPARATOR.$fileName, $pattern, $callback); + $this->recursiveProcess($pathName, $dst.\DIRECTORY_SEPARATOR.$fileName, $pattern, $callback); } - } elseif ($pattern === null || 1 === preg_match($pattern, $fileName)) { - $path = $dst.DIRECTORY_SEPARATOR.$fileName; + } elseif ($pattern === null || 1 === \preg_match($pattern, $fileName)) { + $path = $dst.\DIRECTORY_SEPARATOR.$fileName; $success = $success && $callback($pathName, $path); } } diff --git a/Library/Console/Command/InstallCommand.php b/Library/Console/Command/InstallCommand.php index 0d8b6d0037..2758525463 100644 --- a/Library/Console/Command/InstallCommand.php +++ b/Library/Console/Command/InstallCommand.php @@ -23,8 +23,6 @@ use Zephir\Exception\CompilerException; use Zephir\Exception\NotImplementedException; -use function extension_loaded; - /** * Install Command * @@ -77,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $success = ['Extension installed.']; $namespace = $this->config->get('namespace'); - if (!extension_loaded($namespace)) { + if (!\extension_loaded($namespace)) { $success[] = sprintf('Add "extension=%s.so" to your php.ini', $namespace); } diff --git a/Library/Console/Command/RemoveOptionsTrait.php b/Library/Console/Command/RemoveOptionsTrait.php index c362fe5930..e1c9ee7e3e 100644 --- a/Library/Console/Command/RemoveOptionsTrait.php +++ b/Library/Console/Command/RemoveOptionsTrait.php @@ -16,9 +16,6 @@ use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; -use function array_filter; -use function in_array; - trait RemoveOptionsTrait { protected function removeOptions(array $names): void @@ -26,8 +23,8 @@ protected function removeOptions(array $names): void /** @var InputDefinition $definition */ $definition = $this->getDefinition(); - $filtered = array_filter($definition->getOptions(), function (InputOption $option) use ($names) { - return !in_array($option->getName(), $names, true); + $filtered = \array_filter($definition->getOptions(), function (InputOption $option) use ($names) { + return !\in_array($option->getName(), $names, true); }); $definition->setOptions($filtered); diff --git a/Library/Detectors/ReadDetector.php b/Library/Detectors/ReadDetector.php index d616c8e576..8740ddf172 100644 --- a/Library/Detectors/ReadDetector.php +++ b/Library/Detectors/ReadDetector.php @@ -14,7 +14,6 @@ namespace Zephir\Detectors; use Zephir\Variable\Variable; -use function is_array; /** * Detects if a variable is used in a given expression context @@ -44,13 +43,13 @@ public function detect($variable, array $expression): bool if (in_array($expression['type'], ['fcall', 'mcall', 'scall']) && isset($expression['parameters'])) { foreach ($expression['parameters'] as $parameter) { - if (is_array($parameter['parameter']) && 'variable' === $parameter['parameter']['type'] && $variable == $parameter['parameter']['value']) { + if (\is_array($parameter['parameter']) && 'variable' === $parameter['parameter']['type'] && $variable == $parameter['parameter']['value']) { return true; } } } - return (isset($expression['left']) && is_array($expression['left']) && $this->detect($variable, $expression['left'])) || - (isset($expression['right']) && is_array($expression['right']) && $this->detect($variable, $expression['right'])); + return (isset($expression['left']) && \is_array($expression['left']) && $this->detect($variable, $expression['left'])) + || (isset($expression['right']) && \is_array($expression['right']) && $this->detect($variable, $expression['right'])); } } diff --git a/Library/Documentation.php b/Library/Documentation.php index a3d2081017..ed00e2e120 100644 --- a/Library/Documentation.php +++ b/Library/Documentation.php @@ -236,9 +236,9 @@ public function getOutputDirectory() * @param array $themeConfig * @param string|null $options * - * @throws Exception - * * @return array + * + * @throws Exception */ private function prepareThemeOptions($themeConfig, $options = null) { @@ -307,10 +307,10 @@ private function findOutputDirectory($outputDir) * @param array $themeConfig * @param string|null $path * + * @return string|null + * * @throws InvalidArgumentException * @throws ConfigException - * - * @return string|null */ private function findThemeDirectory($themeConfig, $path = null) { diff --git a/Library/Documentation/DocblockParser.php b/Library/Documentation/DocblockParser.php index d3596fe418..f37f50bed1 100644 --- a/Library/Documentation/DocblockParser.php +++ b/Library/Documentation/DocblockParser.php @@ -19,9 +19,9 @@ class DocblockParser protected $annotation; protected $annotationLen; - protected $currentChar = null; - protected $currentCharIndex = null; - protected $currentLine = null; + protected $currentChar; + protected $currentCharIndex; + protected $currentLine; protected $lines = []; // Parsing helpers diff --git a/Library/Documentation/Template.php b/Library/Documentation/Template.php index 3755293309..c66c2dc15d 100644 --- a/Library/Documentation/Template.php +++ b/Library/Documentation/Template.php @@ -50,7 +50,7 @@ public function __construct( private function getTemplatePath($fileName) { - if ('/' == $fileName[0] || 0 === strpos($fileName, 'phar://')) { + if ('/' == $fileName[0] || str_starts_with($fileName, 'phar://')) { return $fileName; } diff --git a/Library/Exception/CompilerException.php b/Library/Exception/CompilerException.php index d4cb81eb49..8426045ea6 100644 --- a/Library/Exception/CompilerException.php +++ b/Library/Exception/CompilerException.php @@ -19,7 +19,7 @@ class CompilerException extends RuntimeException /** * CompilerException constructor. * - * @param string $message the Exception message to throw [optional] + * @param string $message the Exception message to throw [optional] * @param array|null $extra extra info [optional] * @param int $code the Exception code [optional] * @param \Exception|\Throwable $previous the previous throwable used for the exception chaining [optional] diff --git a/Library/Expression.php b/Library/Expression.php index f002195974..6d6e43bed9 100644 --- a/Library/Expression.php +++ b/Library/Expression.php @@ -13,7 +13,6 @@ namespace Zephir; -use ReflectionException; use Zephir\Exception\CompilerException; use Zephir\Expression\Closure; use Zephir\Expression\ClosureArrow; @@ -225,12 +224,11 @@ public function emptyArray(array $expression, CompilationContext $compilationCon * * @param CompilationContext $compilationContext * - * @throws CompilerException|Exception - * * @return CompiledExpression * + * @throws CompilerException|Exception * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(CompilationContext $compilationContext): CompiledExpression { diff --git a/Library/Expression/Builder/AbstractBuilder.php b/Library/Expression/Builder/AbstractBuilder.php index af821e05dc..669d8278a0 100644 --- a/Library/Expression/Builder/AbstractBuilder.php +++ b/Library/Expression/Builder/AbstractBuilder.php @@ -13,9 +13,9 @@ abstract class AbstractBuilder { - private $file = null; - private $line = null; - private $char = null; + private $file; + private $line; + private $char; /** * @param string $file diff --git a/Library/Expression/Builder/BuilderFactory.php b/Library/Expression/Builder/BuilderFactory.php index 3eca0a0bb1..e3e08f9b99 100644 --- a/Library/Expression/Builder/BuilderFactory.php +++ b/Library/Expression/Builder/BuilderFactory.php @@ -75,7 +75,7 @@ public function variable($name) } /** - * @param $type + * @param $type * @param null $value * * @return RawExpression diff --git a/Library/Expression/Builder/Factory/OperatorsFactory.php b/Library/Expression/Builder/Factory/OperatorsFactory.php index 6b84dfaa68..946126eff4 100644 --- a/Library/Expression/Builder/Factory/OperatorsFactory.php +++ b/Library/Expression/Builder/Factory/OperatorsFactory.php @@ -98,7 +98,7 @@ public function unary($operator = null, AbstractBuilder $expression = null) } /** - * @param $type + * @param $type * @param AbstractBuilder $expression * * @return RawOperator @@ -113,7 +113,7 @@ public function cast($type, AbstractBuilder $expression) } /** - * @param $type + * @param $type * @param AbstractBuilder $expression * * @return RawOperator diff --git a/Library/Expression/Builder/Statements/CallFunctionStatement.php b/Library/Expression/Builder/Statements/CallFunctionStatement.php index b45056202c..b0f460cf98 100644 --- a/Library/Expression/Builder/Statements/CallFunctionStatement.php +++ b/Library/Expression/Builder/Statements/CallFunctionStatement.php @@ -40,7 +40,7 @@ class CallFunctionStatement extends AbstractStatement /** * @param string|null $name * @param array|null $parameters - * @param int $typeCall + * @param int $typeCall */ public function __construct(string $name = null, array $parameters = null, int $typeCall = self::TYPE_CALL_DIRECT) { diff --git a/Library/Expression/Closure.php b/Library/Expression/Closure.php index 1e80cbd82a..b7b90f8972 100644 --- a/Library/Expression/Closure.php +++ b/Library/Expression/Closure.php @@ -23,7 +23,6 @@ use Zephir\Exception; use Zephir\StatementsBlock; use Zephir\Variable\Variable; -use function is_array; /** * Creates an anonymous function within the extension simulating a closure @@ -57,7 +56,7 @@ class Closure * @param bool $expecting * @param Variable|null $expectingVariable */ - public function setExpectReturn(bool $expecting, ?Variable $expectingVariable = null): void + public function setExpectReturn(bool $expecting, Variable $expectingVariable = null): void { $this->expecting = $expecting; $this->expectingVariable = $expectingVariable; @@ -105,7 +104,7 @@ public function compile(array $expression, CompilationContext $compilationContex $block = $expression['right'] ?? []; $staticVariables = []; - if (isset($expression['use']) && is_array($expression['use'])) { + if (isset($expression['use']) && \is_array($expression['use'])) { foreach ($expression['use'] as $parameter) { $staticVariables[$parameter['name']] = $compilationContext->symbolTable->getVariable($parameter['name']); } diff --git a/Library/Expression/ClosureArrow.php b/Library/Expression/ClosureArrow.php index d420c656e5..75ba6eff5e 100644 --- a/Library/Expression/ClosureArrow.php +++ b/Library/Expression/ClosureArrow.php @@ -14,8 +14,8 @@ namespace Zephir\Expression; use Zephir\Class\Definition\Definition; -use Zephir\Class\Method\Parameters; use Zephir\Class\Method\Method; +use Zephir\Class\Method\Parameters; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\CompilerFileAnonymous; @@ -34,9 +34,9 @@ class ClosureArrow extends Closure * @param array $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return CompiledExpression + * + * @throws CompilerException */ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { diff --git a/Library/Expression/Constants.php b/Library/Expression/Constants.php index da8c874d36..079c525851 100644 --- a/Library/Expression/Constants.php +++ b/Library/Expression/Constants.php @@ -16,10 +16,8 @@ use Zephir\Exception\CompilerException; use Zephir\LiteralCompiledExpression; use Zephir\Variable\Variable; + use function constant; -use function defined; -use function gettype; -use function in_array; use function Zephir\add_slashes; /** @@ -101,7 +99,7 @@ class Constants * @param bool $expecting * @param Variable|null $expectingVariable */ - public function setExpectReturn(bool $expecting, ?Variable $expectingVariable = null) + public function setExpectReturn(bool $expecting, Variable $expectingVariable = null) { $this->expecting = $expecting; $this->expectingVariable = $expectingVariable; @@ -123,9 +121,9 @@ public function setReadOnly(bool $readOnly): void * @param array $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return CompiledExpression + * + * @throws CompilerException */ public function compile(array $expression, CompilationContext $compilationContext) { @@ -135,7 +133,7 @@ public function compile(array $expression, CompilationContext $compilationContex $constantName = $expression['value']; $mergedConstants = array_merge($this->envConstants, $this->magicConstants, $this->resources); - if (!defined($expression['value']) && !in_array($constantName, $mergedConstants)) { + if (!\defined($expression['value']) && !\in_array($constantName, $mergedConstants)) { if (!$compilationContext->compiler->isConstant($constantName)) { $compilationContext->logger->warning( "Constant '".$constantName."' does not exist at compile time", @@ -145,18 +143,18 @@ public function compile(array $expression, CompilationContext $compilationContex $isZephirConstant = true; } } else { - $isPhpConstant = false === strpos($constantName, 'VERSION'); + $isPhpConstant = !str_contains($constantName, 'VERSION'); } - if ($isZephirConstant && !in_array($constantName, $this->resources)) { + if ($isZephirConstant && !\in_array($constantName, $this->resources)) { $constant = $compilationContext->compiler->getConstant($constantName); return new LiteralCompiledExpression($constant[0], $constant[1], $expression); } - if ($isPhpConstant && !in_array($constantName, $mergedConstants)) { - $constantName = constant($constantName); - $type = strtolower(gettype($constantName)); + if ($isPhpConstant && !\in_array($constantName, $mergedConstants)) { + $constantName = \constant($constantName); + $type = strtolower(\gettype($constantName)); switch ($type) { case 'integer': @@ -175,7 +173,7 @@ public function compile(array $expression, CompilationContext $compilationContex } } - if (in_array($constantName, $this->magicConstants)) { + if (\in_array($constantName, $this->magicConstants)) { switch ($constantName) { case '__CLASS__': return new CompiledExpression( diff --git a/Library/Expression/NativeArray.php b/Library/Expression/NativeArray.php index a1d13afa22..32ba85bde0 100644 --- a/Library/Expression/NativeArray.php +++ b/Library/Expression/NativeArray.php @@ -13,7 +13,6 @@ namespace Zephir\Expression; -use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; @@ -21,8 +20,6 @@ use Zephir\Expression; use Zephir\GlobalConstant; use Zephir\Variable\Variable; -use function count; -use function function_exists; /** * Resolves expressions that create arrays @@ -165,7 +162,7 @@ public function getArrayValue(CompiledExpression $exprCompiled, CompilationConte * * @return CompiledExpression * - * @throws ReflectionException + * @throws \ReflectionException * @throws Exception */ public function compile(array $expression, CompilationContext $compilationContext) @@ -206,8 +203,8 @@ public function compile(array $expression, CompilationContext $compilationContex * This calculates a prime number bigger than the current array size to possibly * reduce hash collisions when adding new members to the array. */ - $arrayLength = count($expression['left']); - if ($arrayLength >= 33 && function_exists('gmp_nextprime')) { + $arrayLength = \count($expression['left']); + if ($arrayLength >= 33 && \function_exists('gmp_nextprime')) { $arrayLength = (int) gmp_strval(gmp_nextprime($arrayLength - 1)); } diff --git a/Library/Expression/NativeArrayAccess.php b/Library/Expression/NativeArrayAccess.php index 28e167c1ca..84f0f273cf 100644 --- a/Library/Expression/NativeArrayAccess.php +++ b/Library/Expression/NativeArrayAccess.php @@ -13,7 +13,6 @@ namespace Zephir\Expression; -use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; @@ -38,7 +37,7 @@ class NativeArrayAccess * Sets if the variable must be resolved into a direct variable symbol * create a temporary value or ignore the return value. * - * @param bool $expecting + * @param bool $expecting * @param Variable|null $expectingVariable */ public function setExpectReturn(bool $expecting, Variable $expectingVariable = null): void @@ -70,12 +69,13 @@ public function setNoisy(bool $noisy): void /** * Compiles foo[x] = {expr}. * - * @param $expression + * @param $expression * @param CompilationContext $compilationContext * * @return CompiledExpression + * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile($expression, CompilationContext $compilationContext) { @@ -127,7 +127,7 @@ public function compile($expression, CompilationContext $compilationContext) * * @return CompiledExpression * - * @throws ReflectionException + * @throws \ReflectionException * @throws Exception */ protected function accessStringOffset(array $expression, Variable $variableVariable, CompilationContext $compilationContext): CompiledExpression @@ -182,13 +182,14 @@ protected function accessStringOffset(array $expression, Variable $variableVaria } /** - * @param array $expression - * @param Variable $variableVariable + * @param array $expression + * @param Variable $variableVariable * @param CompilationContext $compilationContext * * @return CompiledExpression + * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ protected function accessDimensionArray(array $expression, Variable $variableVariable, CompilationContext $compilationContext): CompiledExpression { diff --git a/Library/Expression/PropertyAccess.php b/Library/Expression/PropertyAccess.php index d1bcf4d192..e294e1f1ab 100644 --- a/Library/Expression/PropertyAccess.php +++ b/Library/Expression/PropertyAccess.php @@ -34,7 +34,7 @@ class PropertyAccess * Sets if the variable must be resolved into a direct variable symbol * create a temporary value or ignore the return value. * - * @param bool $expecting + * @param bool $expecting * @param Variable|null $expectingVariable */ public function setExpectReturn(bool $expecting, Variable $expectingVariable = null): void diff --git a/Library/Expression/PropertyDynamicAccess.php b/Library/Expression/PropertyDynamicAccess.php index e62992deba..eac8b2f048 100644 --- a/Library/Expression/PropertyDynamicAccess.php +++ b/Library/Expression/PropertyDynamicAccess.php @@ -16,6 +16,7 @@ use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Variable\Variable; + use function Zephir\add_slashes; /** diff --git a/Library/Expression/Reference.php b/Library/Expression/Reference.php index d5e87b53d4..ebad811eb3 100644 --- a/Library/Expression/Reference.php +++ b/Library/Expression/Reference.php @@ -13,7 +13,6 @@ namespace Zephir\Expression; -use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; @@ -58,7 +57,7 @@ class Reference * @param bool $expecting * @param Variable|null $expectingVariable */ - public function setExpectReturn(bool $expecting, ?Variable $expectingVariable = null): void + public function setExpectReturn(bool $expecting, Variable $expectingVariable = null): void { $this->expecting = $expecting; $this->expectingVariable = $expectingVariable; @@ -78,7 +77,7 @@ public function setReadOnly(bool $readOnly): void * Compiles a reference to a value. * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { diff --git a/Library/Expression/StaticConstantAccess.php b/Library/Expression/StaticConstantAccess.php index 282062e756..16638d7d1f 100644 --- a/Library/Expression/StaticConstantAccess.php +++ b/Library/Expression/StaticConstantAccess.php @@ -13,15 +13,12 @@ namespace Zephir\Expression; -use ReflectionException; use Zephir\Class\Constant; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Variable\Variable; -use function gettype; -use function in_array; /** * Resolves class constants @@ -38,7 +35,7 @@ class StaticConstantAccess * Sets if the variable must be resolved into a direct variable symbol * create a temporary value or ignore the return value. * - * @param bool $expecting + * @param bool $expecting * @param Variable|null $expectingVariable */ public function setExpectReturn(bool $expecting, Variable $expectingVariable = null): void @@ -60,12 +57,13 @@ public function setReadOnly(bool $readOnly): void /** * Access a static constant class. * - * @param array $expression + * @param array $expression * @param CompilationContext $compilationContext * * @return CompiledExpression + * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { @@ -77,7 +75,7 @@ public function compile(array $expression, CompilationContext $compilationContex * Fetch the class definition according to the class where the constant * is supposed to be declared */ - if (!in_array($className, ['this', 'self', 'static', 'parent'])) { + if (!\in_array($className, ['this', 'self', 'static', 'parent'])) { $className = $compilationContext->getFullName($className); if ($compiler->isClass($className) || $compiler->isInterface($className)) { $classDefinition = $compiler->getClassDefinition($className); @@ -89,7 +87,7 @@ public function compile(array $expression, CompilationContext $compilationContex } } } else { - if (in_array($className, ['self', 'static', 'this'])) { + if (\in_array($className, ['self', 'static', 'this'])) { $classDefinition = $compilationContext->classDefinition; } elseif ('parent' === $className) { $classDefinition = $compilationContext->classDefinition; @@ -182,7 +180,7 @@ public function compile(array $expression, CompilationContext $compilationContex $type = $constantDefinition->getValueType(); } else { $value = $constantDefinition; - $type = gettype($value); + $type = \gettype($value); if ('integer' === $type) { $type = 'int'; } diff --git a/Library/Expression/StaticPropertyAccess.php b/Library/Expression/StaticPropertyAccess.php index 228ba3ae30..6f48f7b5a7 100644 --- a/Library/Expression/StaticPropertyAccess.php +++ b/Library/Expression/StaticPropertyAccess.php @@ -13,14 +13,12 @@ namespace Zephir\Expression; -use ReflectionException; use Zephir\Class\Property; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Variable\Variable; -use function in_array; /** * Resolves class static properties @@ -54,7 +52,7 @@ public function setReadOnly(bool $readOnly): void /** * Access a static property. * - * @throws ReflectionException + * @throws \ReflectionException * @throws Exception */ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression @@ -67,7 +65,7 @@ public function compile(array $expression, CompilationContext $compilationContex * Fetch the class definition according to the class where the constant * is supposed to be declared */ - if (!in_array($className, ['self', 'static', 'parent'])) { + if (!\in_array($className, ['self', 'static', 'parent'])) { $className = $compilationContext->getFullName($className); if ($compiler->isClass($className)) { $classDefinition = $compiler->getClassDefinition($className); @@ -79,7 +77,7 @@ public function compile(array $expression, CompilationContext $compilationContex } } } else { - if (in_array($className, ['self', 'static'])) { + if (\in_array($className, ['self', 'static'])) { $classDefinition = $compilationContext->classDefinition; } else { if ('parent' === $className) { diff --git a/Library/FileSystem/HardDisk.php b/Library/FileSystem/HardDisk.php index c9f3c04e9f..9a5010b0b6 100644 --- a/Library/FileSystem/HardDisk.php +++ b/Library/FileSystem/HardDisk.php @@ -13,13 +13,7 @@ namespace Zephir\FileSystem; -use FilesystemIterator; -use Generator; -use RecursiveDirectoryIterator; -use RecursiveIteratorIterator; -use SplFileInfo; use Zephir\Exception\InvalidArgumentException; -use Zephir\Exception\RuntimeException; use Zephir\Zephir; /** @@ -172,10 +166,10 @@ public function clean(): void $contents = $this->listDirectoryRecursively( $this->basePath.DIRECTORY_SEPARATOR.$this->localPath, - RecursiveIteratorIterator::CHILD_FIRST, + \RecursiveIteratorIterator::CHILD_FIRST, ); - /** @var SplFileInfo $file */ + /** @var \SplFileInfo $file */ foreach ($contents as $file) { $this->deleteFileInfoObject($file); } @@ -231,7 +225,7 @@ public function normalizePath(string $path): string return str_replace(['\\', ':', '/'], '_', $path); } - protected function deleteFileInfoObject(SplFileInfo $file): bool + protected function deleteFileInfoObject(\SplFileInfo $file): bool { switch ($file->getType()) { case 'dir': @@ -245,10 +239,10 @@ protected function deleteFileInfoObject(SplFileInfo $file): bool private function listDirectoryRecursively( string $path, - int $mode = RecursiveIteratorIterator::SELF_FIRST - ): Generator { - yield from new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS), + int $mode = \RecursiveIteratorIterator::SELF_FIRST + ): \Generator { + yield from new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS), $mode ); } diff --git a/Library/FunctionCall.php b/Library/FunctionCall.php index f6ea9c2887..5047b87258 100644 --- a/Library/FunctionCall.php +++ b/Library/FunctionCall.php @@ -141,9 +141,9 @@ public function functionExists($functionName, CompilationContext $context) * @param Expression $expr * @param CompilationContext $compilationContext * - * @throws CompilerException|Exception - * * @return CompiledExpression + * + * @throws CompilerException|Exception */ public function compile(Expression $expr, CompilationContext $compilationContext) { @@ -178,9 +178,9 @@ public static function addOptimizerDir($directory) * @param string $funcName * @param array $expression * - * @throws CompilerException - * * @return bool + * + * @throws CompilerException */ protected function isReadOnly($funcName, array $expression) { @@ -213,9 +213,9 @@ protected function isReadOnly($funcName, array $expression) * Check if the number of parameters. */ $numberParameters = \count($expression['parameters']); - if ('unpack' == $funcName && - (0 == version_compare(PHP_VERSION, '7.1.0') || - 0 == version_compare(PHP_VERSION, '7.1.1')) + if ('unpack' == $funcName + && (0 == version_compare(PHP_VERSION, '7.1.0') + || 0 == version_compare(PHP_VERSION, '7.1.1')) ) { if ($numberParameters < 2) { throw new CompilerException(sprintf($messageFormat, $funcName), $expression); @@ -308,9 +308,9 @@ protected function markReferences( * @param Call $call * @param CompilationContext $compilationContext * - * @throws Exception - * * @return bool|mixed + * + * @throws Exception */ protected function optimize($funcName, array $expression, Call $call, CompilationContext $compilationContext) { @@ -364,9 +364,9 @@ protected function optimize($funcName, array $expression, Call $call, Compilatio * @param array $expression * @param CompilationContext $compilationContext * - * @throws Exception|\Zephir\Exception\CompilerException - * * @return CompiledExpression + * + * @throws Exception|\Zephir\Exception\CompilerException */ protected function _callNormal(array $expression, CompilationContext $compilationContext) { @@ -557,9 +557,9 @@ protected function _callNormal(array $expression, CompilationContext $compilatio * @param array $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return CompiledExpression + * + * @throws CompilerException */ protected function _callDynamic(array $expression, CompilationContext $compilationContext) { diff --git a/Library/FunctionDefinition.php b/Library/FunctionDefinition.php index 1ea93d1067..0775857f51 100644 --- a/Library/FunctionDefinition.php +++ b/Library/FunctionDefinition.php @@ -13,8 +13,8 @@ namespace Zephir; -use Zephir\Class\Method\Parameters; use Zephir\Class\Method\Method; +use Zephir\Class\Method\Parameters; /** * Represents a function @@ -27,12 +27,12 @@ class FunctionDefinition extends Method private bool $isGlobal = false; public function __construct( - private string $namespace, - protected string $name, - protected ?Parameters $parameters = null, + private string $namespace, + protected string $name, + protected ?Parameters $parameters = null, protected ?StatementsBlock $statements = null, - array $returnType = null, - protected ?array $expression = [], + array $returnType = null, + protected ?array $expression = [], ) { $this->setReturnTypes($returnType); } diff --git a/Library/Logger/Formatter/CompilerFormatter.php b/Library/Logger/Formatter/CompilerFormatter.php index 99e5320960..cf6c7b9c19 100644 --- a/Library/Logger/Formatter/CompilerFormatter.php +++ b/Library/Logger/Formatter/CompilerFormatter.php @@ -16,10 +16,6 @@ use Monolog\Formatter\LineFormatter; use Zephir\Config; -use function array_key_exists; -use function count; -use function is_array; - /** * Formatter for warnings/notices/errors generated in compilation. */ @@ -53,9 +49,9 @@ public function format(array $record): string $output = str_replace('%context%', '', $output); // ignore empty context or invalid format - if (!empty($vars['context']) && - is_array($vars['context']) && - 2 == count($vars['context']) + if (!empty($vars['context']) + && \is_array($vars['context']) + && 2 == \count($vars['context']) ) { $type = $vars['context'][0]; $node = $vars['context'][1]; @@ -97,7 +93,7 @@ public function format(array $record): string private function replacePlaceholders(array $vars, $output) { // WARNING -> Warning - if (array_key_exists('level_name', $vars)) { + if (\array_key_exists('level_name', $vars)) { $vars['level_name'] = ucfirst(strtolower($vars['level_name'])); } diff --git a/Library/MethodCall.php b/Library/MethodCall.php index 6d92d4693f..a6aac43fff 100644 --- a/Library/MethodCall.php +++ b/Library/MethodCall.php @@ -11,7 +11,6 @@ namespace Zephir; -use ReflectionException; use Zephir\Class\Method\Method; use Zephir\Detectors\ReadDetector; use Zephir\Exception\CompilerException; @@ -41,11 +40,13 @@ class MethodCall extends Call /** * Compiles a method call. * - * @param Expression $expr + * @param Expression $expr * @param CompilationContext $compilationContext + * * @return mixed|CompiledExpression + * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(Expression $expr, CompilationContext $compilationContext): mixed { @@ -319,10 +320,10 @@ public function compile(Expression $expr, CompilationContext $compilationContext $numberImplemented = 0; $compiler = $compilationContext->compiler; foreach ($classTypes as $classType) { - if ($compiler->isClass($classType) || - $compiler->isInterface($classType) || - $compiler->isBundledClass($classType) || - $compiler->isBundledInterface($classType) + if ($compiler->isClass($classType) + || $compiler->isInterface($classType) + || $compiler->isBundledClass($classType) + || $compiler->isBundledInterface($classType) ) { if ($compiler->isClass($classType) || $compiler->isInterface($classType)) { $classDefinition = $compiler->getClassDefinition($classType); @@ -373,9 +374,9 @@ public function compile(Expression $expr, CompilationContext $compilationContext /* * Check visibility for protected methods */ - if ($method->isProtected() && - $method->getClassDefinition() != $classDefinition && - $method->getClassDefinition() != $classDefinition->getExtendsClass() + if ($method->isProtected() + && $method->getClassDefinition() != $classDefinition + && $method->getClassDefinition() != $classDefinition->getExtendsClass() ) { throw new CompilerException( sprintf( @@ -672,10 +673,10 @@ public function compile(Expression $expr, CompilationContext $compilationContext } break; - /** - * Passing polymorphic variables to static typed parameters - * could lead to potential unexpected type coercions - */ + /** + * Passing polymorphic variables to static typed parameters + * could lead to potential unexpected type coercions + */ case 'variable': if ($resolvedDynamicTypes[$n] != $parameter['data-type']) { if ('undefined' == $resolvedDynamicTypes[$n]) { @@ -746,7 +747,7 @@ public function compile(Expression $expr, CompilationContext $compilationContext $compilationContext ); } else { - //TODO: also move to backend + // TODO: also move to backend if ($isExpecting) { $symbolCode = $compilationContext->backend->getVariableCode($symbolVariable); } @@ -828,11 +829,12 @@ public function compile(Expression $expr, CompilationContext $compilationContext * Examine internal class information and returns the method called. * * @param CompilationContext $compilationContext - * @param Variable $caller - * @param string $methodName + * @param Variable $caller + * @param string $methodName * * @return array - * @throws ReflectionException + * + * @throws \ReflectionException */ private function getRealCalledMethod(CompilationContext $compilationContext, Variable $caller, string $methodName): array { @@ -854,9 +856,9 @@ private function getRealCalledMethod(CompilationContext $compilationContext, Var continue; } - if ($compiler->isClass($classType) || - $compiler->isBundledClass($classType) || - $compiler->isBundledInterface($classType) + if ($compiler->isClass($classType) + || $compiler->isBundledClass($classType) + || $compiler->isBundledInterface($classType) ) { if ($compiler->isClass($classType)) { $classDefinition = $compiler->getClassDefinition($classType); diff --git a/Library/Operators/AbstractOperator.php b/Library/Operators/AbstractOperator.php index d35b8aca1b..330435ef0d 100644 --- a/Library/Operators/AbstractOperator.php +++ b/Library/Operators/AbstractOperator.php @@ -35,7 +35,7 @@ abstract class AbstractOperator * @param bool $expecting * @param Variable|null $expectingVariable */ - public function setExpectReturn(bool $expecting, ?Variable $expectingVariable = null): void + public function setExpectReturn(bool $expecting, Variable $expectingVariable = null): void { $this->expecting = $expecting; $this->expectingVariable = $expectingVariable; @@ -81,8 +81,8 @@ public function getExpectedNonLiteral(CompilationContext $compilationContext, ar * store the result. * * @param CompilationContext $compilationContext - * @param array $expression - * @param bool $init + * @param array $expression + * @param bool $init * * @return Variable|null */ diff --git a/Library/Operators/Arithmetical/ArithmeticalBaseOperator.php b/Library/Operators/Arithmetical/ArithmeticalBaseOperator.php index a6d992e14b..ac6b94bcae 100644 --- a/Library/Operators/Arithmetical/ArithmeticalBaseOperator.php +++ b/Library/Operators/Arithmetical/ArithmeticalBaseOperator.php @@ -82,10 +82,10 @@ public function optimizeConstantFolding(array $expression, CompilationContext $c * @param array $expression * @param CompilationContext $compilationContext * + * @return CompiledExpression + * * @throws Exception * @throws CompilerException - * - * @return CompiledExpression */ public function compile($expression, CompilationContext $compilationContext) { @@ -443,7 +443,7 @@ public function compile($expression, CompilationContext $compilationContext) } break; - /* a(var) + a(x) */ + /* a(var) + a(x) */ case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->resolve(null, $compilationContext), $compilationContext, $expression); switch ($variableRight->getType()) { @@ -468,7 +468,7 @@ public function compile($expression, CompilationContext $compilationContext) ); break; - /* a(var) + a(bool) */ + /* a(var) + a(bool) */ case 'bool': $compilationContext->headersManager->add('kernel/operators'); $variableLeft = $compilationContext->backend->getVariableCode($variableLeft); @@ -476,7 +476,7 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('int', '(zephir_get_numberval('.$variableLeft.') '.$this->operator.' '.$variableRight->getName().')', $expression); break; - /* a(var) + a(var) */ + /* a(var) + a(var) */ case 'variable': case 'array': $compilationContext->headersManager->add('kernel/operators'); diff --git a/Library/Operators/Arithmetical/DivOperator.php b/Library/Operators/Arithmetical/DivOperator.php index bdb56058f6..5e66647eb0 100644 --- a/Library/Operators/Arithmetical/DivOperator.php +++ b/Library/Operators/Arithmetical/DivOperator.php @@ -329,7 +329,7 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('double', 'zephir_safe_div_zval_double('.$op1.', '.$op2.')', $expression); - /* a(var) + a(x) */ + /* a(var) + a(x) */ case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->resolve(null, $compilationContext), $compilationContext, $expression); switch ($variableRight->getType()) { @@ -343,11 +343,11 @@ public function compile($expression, CompilationContext $compilationContext) case 'double': return new CompiledExpression('double', 'zephir_safe_div_zval_double('.$op1.', '.$variableRight->getName().')', $expression); - /* a(var) + a(bool) */ + /* a(var) + a(bool) */ case 'bool': return new CompiledExpression('int', 'zephir_safe_div_zval_long('.$op1.', '.$variableRight->getName().')', $expression); - /* a(var) + a(var) */ + /* a(var) + a(var) */ case 'variable': $op2 = $compilationContext->backend->getVariableCode($variableRight); diff --git a/Library/Operators/Arithmetical/ModOperator.php b/Library/Operators/Arithmetical/ModOperator.php index a82bb4718a..d6aaddc7af 100644 --- a/Library/Operators/Arithmetical/ModOperator.php +++ b/Library/Operators/Arithmetical/ModOperator.php @@ -333,7 +333,7 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('double', 'zephir_safe_mod_zval_double('.$op1.', '.$op2.')', $expression); break; - /* a(var) + a(x) */ + /* a(var) + a(x) */ case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->resolve(null, $compilationContext), $compilationContext, $expression); switch ($variableRight->getType()) { @@ -345,12 +345,12 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('double', 'zephir_safe_mod_zval_long('.$op1.', '.$variableRight->getName().')', $expression); break; - /* a(var) + a(bool) */ + /* a(var) + a(bool) */ case 'bool': return new CompiledExpression('int', 'zephir_safe_mod_zval_long('.$op1.', '.$variableRight->getName().')', $expression); break; - /* a(var) + a(var) */ + /* a(var) + a(var) */ case 'variable': $compilationContext->headersManager->add('kernel/operators'); $op2 = $compilationContext->backend->getVariableCode($variableRight); diff --git a/Library/Operators/Bitwise/BitwiseBaseOperator.php b/Library/Operators/Bitwise/BitwiseBaseOperator.php index e7e82b2a0d..a0f896cacb 100644 --- a/Library/Operators/Bitwise/BitwiseBaseOperator.php +++ b/Library/Operators/Bitwise/BitwiseBaseOperator.php @@ -36,7 +36,7 @@ class BitwiseBaseOperator extends AbstractOperator * @param array $expression * @param CompilationContext $compilationContext * - * @return null|CompiledExpression + * @return CompiledExpression|null */ public function optimizeConstantFolding(array $expression, CompilationContext $compilationContext): ?CompiledExpression { @@ -50,7 +50,7 @@ public function optimizeConstantFolding(array $expression, CompilationContext $c case 'long': case 'ulong': case 'double': - //continue to next switch + // continue to next switch break; default: return null; @@ -63,7 +63,7 @@ public function optimizeConstantFolding(array $expression, CompilationContext $c case 'long': case 'ulong': case 'double': - //continue to operator switch + // continue to operator switch break; default: return null; @@ -430,7 +430,7 @@ public function compile($expression, CompilationContext $compilationContext) } break; - /* a(var) + a(x) */ + /* a(var) + a(x) */ case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->resolve(null, $compilationContext), $compilationContext, $expression); $symbol = $compilationContext->backend->getVariableCode($variableLeft); @@ -445,14 +445,14 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('int', '((int) (zephir_get_numberval('.$symbol.')) '.$this->operator.' '.$variableRight->getName().')', $expression); break; - /* a(var) + a(bool) */ + /* a(var) + a(bool) */ case 'bool': $compilationContext->headersManager->add('kernel/operators'); return new CompiledExpression('int', '((int) (zephir_get_numberval('.$symbol.')) '.$this->operator.' '.$variableRight->getName().')', $expression); break; - /* a(var) + a(var) */ + /* a(var) + a(var) */ case 'variable': $compilationContext->headersManager->add('kernel/operators'); $op1 = $symbol; diff --git a/Library/Operators/Bitwise/BitwiseNotOperator.php b/Library/Operators/Bitwise/BitwiseNotOperator.php index f0666a57d7..e7a7b2dd07 100644 --- a/Library/Operators/Bitwise/BitwiseNotOperator.php +++ b/Library/Operators/Bitwise/BitwiseNotOperator.php @@ -13,7 +13,6 @@ namespace Zephir\Operators\Bitwise; -use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; @@ -24,11 +23,12 @@ class BitwiseNotOperator extends AbstractOperator { /** - * @param $expression + * @param $expression * @param CompilationContext $compilationContext * * @return CompiledExpression - * @throws ReflectionException + * + * @throws \ReflectionException * @throws Exception */ public function compile($expression, CompilationContext $compilationContext) diff --git a/Library/Operators/Comparison/ComparisonBaseOperator.php b/Library/Operators/Comparison/ComparisonBaseOperator.php index a09fbbbbe3..887c24f8ec 100644 --- a/Library/Operators/Comparison/ComparisonBaseOperator.php +++ b/Library/Operators/Comparison/ComparisonBaseOperator.php @@ -13,7 +13,6 @@ namespace Zephir\Operators\Comparison; -use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; @@ -35,7 +34,7 @@ class ComparisonBaseOperator extends AbstractOperator * @return CompiledExpression|null * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function optimizeTypeOf(array $expr, CompilationContext $compilationContext): ?CompiledExpression { @@ -170,7 +169,7 @@ public function optimizeTypeOf(array $expr, CompilationContext $compilationConte * * @return CompiledExpression * - * @throws ReflectionException + * @throws \ReflectionException * @throws Exception */ public function compile(array $expression, CompilationContext $compilationContext) diff --git a/Library/Operators/Logical/AndOperator.php b/Library/Operators/Logical/AndOperator.php index 0ce42886df..4869779d1f 100644 --- a/Library/Operators/Logical/AndOperator.php +++ b/Library/Operators/Logical/AndOperator.php @@ -13,8 +13,6 @@ namespace Zephir\Operators\Logical; -use Exception; -use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception\CompilerException; @@ -28,22 +26,22 @@ class AndOperator extends LogicalBaseOperator protected string $bitOperator = '&&'; /** - * @param $expression + * @param $expression * @param CompilationContext $compilationContext * * @return CompiledExpression * - * @throws ReflectionException + * @throws \ReflectionException * @throws \Zephir\Exception */ public function compile($expression, CompilationContext $compilationContext): CompiledExpression { if (!isset($expression['left'])) { - throw new Exception('Missing left part of the expression'); + throw new \Exception('Missing left part of the expression'); } if (!isset($expression['right'])) { - throw new Exception('Missing right part of the expression'); + throw new \Exception('Missing right part of the expression'); } $leftExpr = new Expression($expression['left']); diff --git a/Library/Operators/Logical/LogicalBaseOperator.php b/Library/Operators/Logical/LogicalBaseOperator.php index 6fa832e923..6131252824 100644 --- a/Library/Operators/Logical/LogicalBaseOperator.php +++ b/Library/Operators/Logical/LogicalBaseOperator.php @@ -258,7 +258,7 @@ public function compile($expression, CompilationContext $compilationContext): Co $compilationContext->headersManager->add('kernel/operators'); $variableCode = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('bool', '('.$variableLeft->getName().' && Z_STRLEN_P('.$variableLeft->getName().')) '.' '.$this->operator.' zephir_is_true('.$variableCode.')', $expression); + return new CompiledExpression('bool', '('.$variableLeft->getName().' && Z_STRLEN_P('.$variableLeft->getName().')) '.$this->operator.' zephir_is_true('.$variableCode.')', $expression); default: throw new CompilerException("Cannot compare variable('double') with variable('".$variableRight->getType()."')", $expression); @@ -285,7 +285,7 @@ public function compile($expression, CompilationContext $compilationContext): Co return new CompiledExpression('bool', 'zephir_is_true('.$op1.') '.$op.' '.$op2, $expression); - /* a(var) && a(x) */ + /* a(var) && a(x) */ case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->resolve(null, $compilationContext), $compilationContext, $expression); $variableRightCode = $compilationContext->backend->getVariableCode($variableRight); @@ -298,7 +298,7 @@ public function compile($expression, CompilationContext $compilationContext): Co return new CompiledExpression('bool', 'zephir_is_true('.$variableLeftCode.') '.$this->operator.' '.$variableRightCode, $expression); - /* a(var) && a(var) */ + /* a(var) && a(var) */ case 'variable': $compilationContext->headersManager->add('kernel/operators'); $op1 = $variableLeftCode; diff --git a/Library/Operators/Logical/OrOperator.php b/Library/Operators/Logical/OrOperator.php index 6e8588e8f1..54be169b90 100644 --- a/Library/Operators/Logical/OrOperator.php +++ b/Library/Operators/Logical/OrOperator.php @@ -13,7 +13,6 @@ namespace Zephir\Operators\Logical; -use Exception; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception\CompilerException; @@ -29,11 +28,11 @@ class OrOperator extends LogicalBaseOperator public function compile($expression, CompilationContext $compilationContext): CompiledExpression { if (!isset($expression['left'])) { - throw new Exception('Missing left part of the expression'); + throw new \Exception('Missing left part of the expression'); } if (!isset($expression['right'])) { - throw new Exception('Missing right part of the expression'); + throw new \Exception('Missing right part of the expression'); } $leftExpr = new Expression($expression['left']); diff --git a/Library/Operators/Other/CastOperator.php b/Library/Operators/Other/CastOperator.php index 0ceb7ccde6..4fcaa8a344 100644 --- a/Library/Operators/Other/CastOperator.php +++ b/Library/Operators/Other/CastOperator.php @@ -13,7 +13,6 @@ namespace Zephir\Operators\Other; -use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Detectors\ReadDetector; @@ -37,7 +36,7 @@ class CastOperator extends AbstractOperator * * @return CompiledExpression * - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { diff --git a/Library/Operators/Other/ConcatOperator.php b/Library/Operators/Other/ConcatOperator.php index 3f5ab4b7b5..5701ea8521 100644 --- a/Library/Operators/Other/ConcatOperator.php +++ b/Library/Operators/Other/ConcatOperator.php @@ -19,6 +19,7 @@ use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Operators\AbstractOperator; + use function Zephir\add_slashes; /** diff --git a/Library/Operators/Other/InstanceOfOperator.php b/Library/Operators/Other/InstanceOfOperator.php index f309ad2035..a1b9bedfee 100644 --- a/Library/Operators/Other/InstanceOfOperator.php +++ b/Library/Operators/Other/InstanceOfOperator.php @@ -13,7 +13,6 @@ namespace Zephir\Operators\Other; -use ReflectionException; use Zephir\Class\Entry; use Zephir\CompilationContext; use Zephir\CompiledExpression; @@ -30,13 +29,13 @@ class InstanceOfOperator extends AbstractOperator { /** - * @param $expression + * @param $expression * @param CompilationContext $context * * @return CompiledExpression * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile($expression, CompilationContext $context): CompiledExpression { diff --git a/Library/Operators/Other/IssetOperator.php b/Library/Operators/Other/IssetOperator.php index 4ed034dd7b..0666448753 100644 --- a/Library/Operators/Other/IssetOperator.php +++ b/Library/Operators/Other/IssetOperator.php @@ -13,7 +13,6 @@ namespace Zephir\Operators\Other; -use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; @@ -35,7 +34,7 @@ class IssetOperator extends AbstractOperator * @return CompiledExpression * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { diff --git a/Library/Operators/Other/LikelyOperator.php b/Library/Operators/Other/LikelyOperator.php index e6cc5418d2..ef2bc03a72 100644 --- a/Library/Operators/Other/LikelyOperator.php +++ b/Library/Operators/Other/LikelyOperator.php @@ -13,7 +13,6 @@ namespace Zephir\Operators\Other; -use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; @@ -27,13 +26,13 @@ class LikelyOperator extends AbstractOperator { /** - * @param array $expression + * @param array $expression * @param CompilationContext $compilationContext * * @return CompiledExpression * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { diff --git a/Library/Operators/Other/NewInstanceOperator.php b/Library/Operators/Other/NewInstanceOperator.php index b4f1f37bbd..6787949683 100644 --- a/Library/Operators/Other/NewInstanceOperator.php +++ b/Library/Operators/Other/NewInstanceOperator.php @@ -13,8 +13,6 @@ namespace Zephir\Operators\Other; -use ReflectionClass; -use ReflectionException; use Zephir\Class\Entry; use Zephir\CompilationContext; use Zephir\CompiledExpression; @@ -41,7 +39,7 @@ class NewInstanceOperator extends AbstractOperator * * @return CompiledExpression * - * @throws ReflectionException + * @throws \ReflectionException * @throws Exception */ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression @@ -158,7 +156,7 @@ public function compile(array $expression, CompilationContext $compilationContex $zendClassEntry = $compilationContext->cacheManager->getClassEntryCache()->get($classNameToFetch, false, $compilationContext); $classEntry = $zendClassEntry->getName(); } else { - $reflectionClass = new ReflectionClass($className); + $reflectionClass = new \ReflectionClass($className); if ($reflectionClass->isInterface()) { throw new CompilerException('Interfaces cannot be instantiated', $expression); } diff --git a/Library/Operators/Other/RequireOperator.php b/Library/Operators/Other/RequireOperator.php index 6dd7af44ea..04001afe7c 100644 --- a/Library/Operators/Other/RequireOperator.php +++ b/Library/Operators/Other/RequireOperator.php @@ -13,7 +13,6 @@ namespace Zephir\Operators\Other; -use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; @@ -26,13 +25,13 @@ class RequireOperator extends AbstractOperator { /** - * @param array $expression + * @param array $expression * @param CompilationContext $compilationContext * * @return CompiledExpression * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { diff --git a/Library/Operators/Other/ShortTernaryOperator.php b/Library/Operators/Other/ShortTernaryOperator.php index 2efa139671..029cfc5912 100644 --- a/Library/Operators/Other/ShortTernaryOperator.php +++ b/Library/Operators/Other/ShortTernaryOperator.php @@ -32,7 +32,7 @@ class ShortTernaryOperator extends AbstractOperator /** * Compile ternary operator. * - * @param $expression + * @param $expression * @param CompilationContext $compilationContext * * @return CompiledExpression diff --git a/Library/Operators/Other/TernaryOperator.php b/Library/Operators/Other/TernaryOperator.php index e3d0054aae..9ed0f29464 100644 --- a/Library/Operators/Other/TernaryOperator.php +++ b/Library/Operators/Other/TernaryOperator.php @@ -27,7 +27,7 @@ class TernaryOperator extends AbstractOperator /** * Compile ternary operator. * - * @param $expression + * @param $expression * @param CompilationContext $compilationContext * * @return CompiledExpression diff --git a/Library/Operators/Other/TypeHintOperator.php b/Library/Operators/Other/TypeHintOperator.php index 1696d30933..6baf09c6e6 100644 --- a/Library/Operators/Other/TypeHintOperator.php +++ b/Library/Operators/Other/TypeHintOperator.php @@ -13,7 +13,6 @@ namespace Zephir\Operators\Other; -use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; @@ -26,13 +25,13 @@ class TypeHintOperator extends AbstractOperator /** * Performs type-hint compilation. * - * @param array $expression + * @param array $expression * @param CompilationContext $compilationContext * * @return CompiledExpression * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { diff --git a/Library/Operators/Other/TypeOfOperator.php b/Library/Operators/Other/TypeOfOperator.php index 6ac240678e..cb1fac6c31 100644 --- a/Library/Operators/Other/TypeOfOperator.php +++ b/Library/Operators/Other/TypeOfOperator.php @@ -13,7 +13,6 @@ namespace Zephir\Operators\Other; -use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; @@ -28,13 +27,13 @@ class TypeOfOperator extends AbstractOperator { /** - * @param $expression + * @param $expression * @param CompilationContext $compilationContext * * @return CompiledExpression * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile($expression, CompilationContext $compilationContext): CompiledExpression { diff --git a/Library/Operators/Other/UnlikelyOperator.php b/Library/Operators/Other/UnlikelyOperator.php index 587d0b060f..8c4e33af3e 100644 --- a/Library/Operators/Other/UnlikelyOperator.php +++ b/Library/Operators/Other/UnlikelyOperator.php @@ -13,7 +13,6 @@ namespace Zephir\Operators\Other; -use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; @@ -29,13 +28,13 @@ class UnlikelyOperator extends AbstractOperator /** * Compile unlikely operator * - * @param $expression + * @param $expression * @param CompilationContext $compilationContext * * @return CompiledExpression * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile($expression, CompilationContext $compilationContext): CompiledExpression { diff --git a/Library/Operators/Unary/MinusOperator.php b/Library/Operators/Unary/MinusOperator.php index 5532bba95c..38a3c94415 100644 --- a/Library/Operators/Unary/MinusOperator.php +++ b/Library/Operators/Unary/MinusOperator.php @@ -13,7 +13,6 @@ namespace Zephir\Operators\Unary; -use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; @@ -26,13 +25,13 @@ class MinusOperator extends AbstractOperator /** * Compile expression. * - * @param $expression + * @param $expression * @param CompilationContext $compilationContext * * @return CompiledExpression * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile($expression, CompilationContext $compilationContext): CompiledExpression { diff --git a/Library/Operators/Unary/NotOperator.php b/Library/Operators/Unary/NotOperator.php index 2d5eee5b57..ab9b10969f 100644 --- a/Library/Operators/Unary/NotOperator.php +++ b/Library/Operators/Unary/NotOperator.php @@ -13,7 +13,6 @@ namespace Zephir\Operators\Unary; -use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; @@ -24,13 +23,13 @@ class NotOperator extends AbstractOperator { /** - * @param $expression + * @param $expression * @param CompilationContext $compilationContext * * @return CompiledExpression * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile($expression, CompilationContext $compilationContext): CompiledExpression { diff --git a/Library/Optimizers/EvalExpression.php b/Library/Optimizers/EvalExpression.php index 94a64a9463..b87fe6af19 100644 --- a/Library/Optimizers/EvalExpression.php +++ b/Library/Optimizers/EvalExpression.php @@ -65,7 +65,7 @@ public function optimizeNot(array $expr, CompilationContext $compilationContext) /** * Optimizes expressions. * - * @param $exprRaw + * @param $exprRaw * @param CompilationContext $compilationContext * * @return bool|string @@ -166,7 +166,7 @@ public function optimize($exprRaw, CompilationContext $compilationContext) break; case 'int': - if (!(int) ($possibleValue->getCode())) { + if (!(int) $possibleValue->getCode()) { $this->unreachable = true; } else { $this->unreachableElse = true; @@ -174,7 +174,7 @@ public function optimize($exprRaw, CompilationContext $compilationContext) break; case 'double': - if (!(float) ($possibleValue->getCode())) { + if (!(float) $possibleValue->getCode()) { $this->unreachable = true; } else { $this->unreachableElse = true; @@ -182,7 +182,7 @@ public function optimize($exprRaw, CompilationContext $compilationContext) break; default: - //echo $possibleValue->getType(); + // echo $possibleValue->getType(); } } } diff --git a/Library/Optimizers/FunctionCall/AddslashesOptimizer.php b/Library/Optimizers/FunctionCall/AddslashesOptimizer.php index 27ed82adc8..84c75f6177 100644 --- a/Library/Optimizers/FunctionCall/AddslashesOptimizer.php +++ b/Library/Optimizers/FunctionCall/AddslashesOptimizer.php @@ -29,9 +29,9 @@ class AddslashesOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/ArrayKeyExistsOptimizer.php b/Library/Optimizers/FunctionCall/ArrayKeyExistsOptimizer.php index 940864f57f..c423940905 100644 --- a/Library/Optimizers/FunctionCall/ArrayKeyExistsOptimizer.php +++ b/Library/Optimizers/FunctionCall/ArrayKeyExistsOptimizer.php @@ -29,9 +29,9 @@ class ArrayKeyExistsOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { @@ -47,7 +47,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression); - //Note: the first parameter is key in php array_key_exists + // Note: the first parameter is key in php array_key_exists return new CompiledExpression('bool', 'zephir_array_key_exists('.$resolvedParams[1].', '.$resolvedParams[0].')', $expression); } } diff --git a/Library/Optimizers/FunctionCall/ArrayKeysOptimizer.php b/Library/Optimizers/FunctionCall/ArrayKeysOptimizer.php index f6ae4fdd06..9e86502c5e 100644 --- a/Library/Optimizers/FunctionCall/ArrayKeysOptimizer.php +++ b/Library/Optimizers/FunctionCall/ArrayKeysOptimizer.php @@ -29,9 +29,9 @@ class ArrayKeysOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/ArrayMergeOptimizer.php b/Library/Optimizers/FunctionCall/ArrayMergeOptimizer.php index 8135036d7d..a474f1196b 100644 --- a/Library/Optimizers/FunctionCall/ArrayMergeOptimizer.php +++ b/Library/Optimizers/FunctionCall/ArrayMergeOptimizer.php @@ -29,9 +29,9 @@ class ArrayMergeOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/BasenameOptimizer.php b/Library/Optimizers/FunctionCall/BasenameOptimizer.php index 8a0c34c9fd..66c5e8f278 100644 --- a/Library/Optimizers/FunctionCall/BasenameOptimizer.php +++ b/Library/Optimizers/FunctionCall/BasenameOptimizer.php @@ -29,9 +29,9 @@ class BasenameOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/CamelizeOptimizer.php b/Library/Optimizers/FunctionCall/CamelizeOptimizer.php index 136235a192..ebd0166572 100644 --- a/Library/Optimizers/FunctionCall/CamelizeOptimizer.php +++ b/Library/Optimizers/FunctionCall/CamelizeOptimizer.php @@ -29,9 +29,9 @@ class CamelizeOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/CeilOptimizer.php b/Library/Optimizers/FunctionCall/CeilOptimizer.php index 6c05009847..cc22851e7a 100644 --- a/Library/Optimizers/FunctionCall/CeilOptimizer.php +++ b/Library/Optimizers/FunctionCall/CeilOptimizer.php @@ -29,9 +29,9 @@ class CeilOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/ClassExistsOptimizer.php b/Library/Optimizers/FunctionCall/ClassExistsOptimizer.php index a448ca560d..dd539f3b08 100644 --- a/Library/Optimizers/FunctionCall/ClassExistsOptimizer.php +++ b/Library/Optimizers/FunctionCall/ClassExistsOptimizer.php @@ -29,9 +29,9 @@ class ClassExistsOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/CompareMtimeOptimizer.php b/Library/Optimizers/FunctionCall/CompareMtimeOptimizer.php index bc18878f5f..6495b4ba4e 100644 --- a/Library/Optimizers/FunctionCall/CompareMtimeOptimizer.php +++ b/Library/Optimizers/FunctionCall/CompareMtimeOptimizer.php @@ -29,9 +29,9 @@ class CompareMtimeOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/Crc32Optimizer.php b/Library/Optimizers/FunctionCall/Crc32Optimizer.php index 71139b435c..bb425a165f 100644 --- a/Library/Optimizers/FunctionCall/Crc32Optimizer.php +++ b/Library/Optimizers/FunctionCall/Crc32Optimizer.php @@ -29,9 +29,9 @@ class Crc32Optimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/CreateArrayOptimizer.php b/Library/Optimizers/FunctionCall/CreateArrayOptimizer.php index bb4d76ec5a..be4584274c 100644 --- a/Library/Optimizers/FunctionCall/CreateArrayOptimizer.php +++ b/Library/Optimizers/FunctionCall/CreateArrayOptimizer.php @@ -29,9 +29,9 @@ class CreateArrayOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/CreateInstanceOptimizer.php b/Library/Optimizers/FunctionCall/CreateInstanceOptimizer.php index 70117105f2..51040a4f90 100644 --- a/Library/Optimizers/FunctionCall/CreateInstanceOptimizer.php +++ b/Library/Optimizers/FunctionCall/CreateInstanceOptimizer.php @@ -29,9 +29,9 @@ class CreateInstanceOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/CreateSymbolTableOptimizer.php b/Library/Optimizers/FunctionCall/CreateSymbolTableOptimizer.php index f4d164c949..8bd23407dd 100644 --- a/Library/Optimizers/FunctionCall/CreateSymbolTableOptimizer.php +++ b/Library/Optimizers/FunctionCall/CreateSymbolTableOptimizer.php @@ -29,9 +29,9 @@ class CreateSymbolTableOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/DoublevalOptimizer.php b/Library/Optimizers/FunctionCall/DoublevalOptimizer.php index 6cfde21ea5..e274e15c09 100644 --- a/Library/Optimizers/FunctionCall/DoublevalOptimizer.php +++ b/Library/Optimizers/FunctionCall/DoublevalOptimizer.php @@ -29,9 +29,9 @@ class DoublevalOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/EvalOptimizer.php b/Library/Optimizers/FunctionCall/EvalOptimizer.php index 143c06a619..1e51333066 100644 --- a/Library/Optimizers/FunctionCall/EvalOptimizer.php +++ b/Library/Optimizers/FunctionCall/EvalOptimizer.php @@ -29,10 +29,10 @@ class EvalOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * + * @return bool|CompiledExpression|mixed + * * @throws CompilerException * @throws \Zephir\Exception - * - * @return bool|CompiledExpression|mixed */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/ExitOptimizer.php b/Library/Optimizers/FunctionCall/ExitOptimizer.php index b2f6084c90..d04826fe4e 100644 --- a/Library/Optimizers/FunctionCall/ExitOptimizer.php +++ b/Library/Optimizers/FunctionCall/ExitOptimizer.php @@ -29,9 +29,9 @@ class ExitOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { @@ -41,7 +41,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont $context->headersManager->add('kernel/exit'); if (isset($expression['parameters'])) { - //TODO: protect resolvedParams[0] from restore + // TODO: protect resolvedParams[0] from restore } if (!isset($expression['parameters'])) { $context->codePrinter->output('ZEPHIR_MM_RESTORE();'); diff --git a/Library/Optimizers/FunctionCall/ExplodeOptimizer.php b/Library/Optimizers/FunctionCall/ExplodeOptimizer.php index 3ad81dc9d6..73f766a62e 100644 --- a/Library/Optimizers/FunctionCall/ExplodeOptimizer.php +++ b/Library/Optimizers/FunctionCall/ExplodeOptimizer.php @@ -31,9 +31,9 @@ class ExplodeOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/FcloseOptimizer.php b/Library/Optimizers/FunctionCall/FcloseOptimizer.php index af5db2b021..f5dc100353 100644 --- a/Library/Optimizers/FunctionCall/FcloseOptimizer.php +++ b/Library/Optimizers/FunctionCall/FcloseOptimizer.php @@ -29,9 +29,9 @@ class FcloseOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/FileExistsOptimizer.php b/Library/Optimizers/FunctionCall/FileExistsOptimizer.php index d06e1e562c..5867ae067b 100644 --- a/Library/Optimizers/FunctionCall/FileExistsOptimizer.php +++ b/Library/Optimizers/FunctionCall/FileExistsOptimizer.php @@ -29,9 +29,9 @@ class FileExistsOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/FileGetContentsOptimizer.php b/Library/Optimizers/FunctionCall/FileGetContentsOptimizer.php index 6b2b6abd97..1008be680a 100644 --- a/Library/Optimizers/FunctionCall/FileGetContentsOptimizer.php +++ b/Library/Optimizers/FunctionCall/FileGetContentsOptimizer.php @@ -29,9 +29,9 @@ class FileGetContentsOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/FilePutContentsOptimizer.php b/Library/Optimizers/FunctionCall/FilePutContentsOptimizer.php index 894bc0b16d..0693608567 100644 --- a/Library/Optimizers/FunctionCall/FilePutContentsOptimizer.php +++ b/Library/Optimizers/FunctionCall/FilePutContentsOptimizer.php @@ -29,9 +29,9 @@ class FilePutContentsOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/FilemtimeOptimizer.php b/Library/Optimizers/FunctionCall/FilemtimeOptimizer.php index b14e3e7b73..1958e8ecdb 100644 --- a/Library/Optimizers/FunctionCall/FilemtimeOptimizer.php +++ b/Library/Optimizers/FunctionCall/FilemtimeOptimizer.php @@ -29,9 +29,9 @@ class FilemtimeOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/FloorOptimizer.php b/Library/Optimizers/FunctionCall/FloorOptimizer.php index e3296ffe94..6719a2e6ae 100644 --- a/Library/Optimizers/FunctionCall/FloorOptimizer.php +++ b/Library/Optimizers/FunctionCall/FloorOptimizer.php @@ -29,9 +29,9 @@ class FloorOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/FuncGetArgOptimizer.php b/Library/Optimizers/FunctionCall/FuncGetArgOptimizer.php index 44ce4ca16d..b0b624c05b 100644 --- a/Library/Optimizers/FunctionCall/FuncGetArgOptimizer.php +++ b/Library/Optimizers/FunctionCall/FuncGetArgOptimizer.php @@ -31,9 +31,9 @@ class FuncGetArgOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return CompiledExpression + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/FuncGetArgsOptimizer.php b/Library/Optimizers/FunctionCall/FuncGetArgsOptimizer.php index 05c566024e..28f718b295 100644 --- a/Library/Optimizers/FunctionCall/FuncGetArgsOptimizer.php +++ b/Library/Optimizers/FunctionCall/FuncGetArgsOptimizer.php @@ -29,9 +29,9 @@ class FuncGetArgsOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/FunctionExistsOptimizer.php b/Library/Optimizers/FunctionCall/FunctionExistsOptimizer.php index ace5a2b80e..66a5c7e64f 100644 --- a/Library/Optimizers/FunctionCall/FunctionExistsOptimizer.php +++ b/Library/Optimizers/FunctionCall/FunctionExistsOptimizer.php @@ -16,7 +16,6 @@ use Zephir\CompiledExpression; use Zephir\Optimizers\OptimizerAbstract; -use function count; use function Zephir\add_slashes; /** @@ -35,7 +34,7 @@ class FunctionExistsOptimizer extends OptimizerAbstract */ public function optimize(array $expression, Call $call, CompilationContext $context) { - if (!isset($expression['parameters']) || 1 !== count($expression['parameters'])) { + if (!isset($expression['parameters']) || 1 !== \count($expression['parameters'])) { return false; } diff --git a/Library/Optimizers/FunctionCall/FwriteOptimizer.php b/Library/Optimizers/FunctionCall/FwriteOptimizer.php index d77cf01b3e..4a01a27476 100644 --- a/Library/Optimizers/FunctionCall/FwriteOptimizer.php +++ b/Library/Optimizers/FunctionCall/FwriteOptimizer.php @@ -29,9 +29,9 @@ class FwriteOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/GetCalledClassOptimizer.php b/Library/Optimizers/FunctionCall/GetCalledClassOptimizer.php index a771b5099d..899f457e6a 100644 --- a/Library/Optimizers/FunctionCall/GetCalledClassOptimizer.php +++ b/Library/Optimizers/FunctionCall/GetCalledClassOptimizer.php @@ -29,9 +29,9 @@ class GetCalledClassOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/GetClassLowerOptimizer.php b/Library/Optimizers/FunctionCall/GetClassLowerOptimizer.php index 10595eb489..41ee43c7fa 100644 --- a/Library/Optimizers/FunctionCall/GetClassLowerOptimizer.php +++ b/Library/Optimizers/FunctionCall/GetClassLowerOptimizer.php @@ -29,9 +29,9 @@ class GetClassLowerOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/GetClassNsOptimizer.php b/Library/Optimizers/FunctionCall/GetClassNsOptimizer.php index d00fce6168..0169caed01 100644 --- a/Library/Optimizers/FunctionCall/GetClassNsOptimizer.php +++ b/Library/Optimizers/FunctionCall/GetClassNsOptimizer.php @@ -29,9 +29,9 @@ class GetClassNsOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/GetClassOptimizer.php b/Library/Optimizers/FunctionCall/GetClassOptimizer.php index c7afeab546..d896e88916 100644 --- a/Library/Optimizers/FunctionCall/GetClassOptimizer.php +++ b/Library/Optimizers/FunctionCall/GetClassOptimizer.php @@ -29,9 +29,9 @@ class GetClassOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/GetNsClassOptimizer.php b/Library/Optimizers/FunctionCall/GetNsClassOptimizer.php index d6d0208cc9..1c26badebf 100644 --- a/Library/Optimizers/FunctionCall/GetNsClassOptimizer.php +++ b/Library/Optimizers/FunctionCall/GetNsClassOptimizer.php @@ -29,9 +29,9 @@ class GetNsClassOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/GettypeOptimizer.php b/Library/Optimizers/FunctionCall/GettypeOptimizer.php index 3cb217ec27..d7f3eca7d1 100644 --- a/Library/Optimizers/FunctionCall/GettypeOptimizer.php +++ b/Library/Optimizers/FunctionCall/GettypeOptimizer.php @@ -29,9 +29,9 @@ class GettypeOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/GlobalsGetOptimizer.php b/Library/Optimizers/FunctionCall/GlobalsGetOptimizer.php index d71f69fb46..89364dc379 100644 --- a/Library/Optimizers/FunctionCall/GlobalsGetOptimizer.php +++ b/Library/Optimizers/FunctionCall/GlobalsGetOptimizer.php @@ -19,8 +19,6 @@ use Zephir\Exception\CompilerException; use Zephir\Optimizers\OptimizerAbstract; -use function count; - /** * `globals_get()` internal function. * @@ -43,7 +41,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont return null; } - if (1 !== count($expression['parameters'])) { + if (1 !== \count($expression['parameters'])) { throw new CompilerException("'globals_get' only accepts one parameter", $expression); } @@ -59,7 +57,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont $type = $context->compiler->getExtensionGlobal($globalName)['type']; - if (false !== strpos($globalName, '.')) { + if (str_contains($globalName, '.')) { $parts = explode('.', $globalName); return new CompiledExpression($type, 'ZEPHIR_GLOBAL('.$parts[0].').'.$parts[1], $expression); diff --git a/Library/Optimizers/FunctionCall/GlobalsSetOptimizer.php b/Library/Optimizers/FunctionCall/GlobalsSetOptimizer.php index 5ff8573b52..93599ab0bb 100644 --- a/Library/Optimizers/FunctionCall/GlobalsSetOptimizer.php +++ b/Library/Optimizers/FunctionCall/GlobalsSetOptimizer.php @@ -20,8 +20,6 @@ use Zephir\Exception\CompilerException; use Zephir\Optimizers\OptimizerAbstract; -use function count; - /** * `globals_set()` internal function. * @@ -34,9 +32,9 @@ class GlobalsSetOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return CompiledExpression + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context): CompiledExpression { @@ -44,7 +42,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont throw new CompilerException("'globals_set' requires two parameters", $expression); } - if (2 !== count($expression['parameters'])) { + if (2 !== \count($expression['parameters'])) { throw new CompilerException("'globals_set' only accepts two parameters", $expression); } diff --git a/Library/Optimizers/FunctionCall/HashEqualsOptimizer.php b/Library/Optimizers/FunctionCall/HashEqualsOptimizer.php index ed0840c3e6..d4a93e0266 100644 --- a/Library/Optimizers/FunctionCall/HashEqualsOptimizer.php +++ b/Library/Optimizers/FunctionCall/HashEqualsOptimizer.php @@ -29,9 +29,9 @@ class HashEqualsOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/ImplodeOptimizer.php b/Library/Optimizers/FunctionCall/ImplodeOptimizer.php index 651c15b55e..fb4744f81d 100644 --- a/Library/Optimizers/FunctionCall/ImplodeOptimizer.php +++ b/Library/Optimizers/FunctionCall/ImplodeOptimizer.php @@ -31,9 +31,9 @@ class ImplodeOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/InArrayOptimizer.php b/Library/Optimizers/FunctionCall/InArrayOptimizer.php index 58727048a7..2d248c6eb9 100644 --- a/Library/Optimizers/FunctionCall/InArrayOptimizer.php +++ b/Library/Optimizers/FunctionCall/InArrayOptimizer.php @@ -29,9 +29,9 @@ class InArrayOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/InterfaceExistsOptimizer.php b/Library/Optimizers/FunctionCall/InterfaceExistsOptimizer.php index 5ffb906e13..ea60dc2ad8 100644 --- a/Library/Optimizers/FunctionCall/InterfaceExistsOptimizer.php +++ b/Library/Optimizers/FunctionCall/InterfaceExistsOptimizer.php @@ -29,9 +29,9 @@ class InterfaceExistsOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/IntvalOptimizer.php b/Library/Optimizers/FunctionCall/IntvalOptimizer.php index 081d8c37ca..5c45900cd1 100644 --- a/Library/Optimizers/FunctionCall/IntvalOptimizer.php +++ b/Library/Optimizers/FunctionCall/IntvalOptimizer.php @@ -29,9 +29,9 @@ class IntvalOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/IsPrivatePropertyOptimizer.php b/Library/Optimizers/FunctionCall/IsPrivatePropertyOptimizer.php index 61e3612774..73d359c1e0 100644 --- a/Library/Optimizers/FunctionCall/IsPrivatePropertyOptimizer.php +++ b/Library/Optimizers/FunctionCall/IsPrivatePropertyOptimizer.php @@ -30,9 +30,9 @@ class IsPrivatePropertyOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/LdexpOptimizer.php b/Library/Optimizers/FunctionCall/LdexpOptimizer.php index 847b919b20..480f9f0107 100644 --- a/Library/Optimizers/FunctionCall/LdexpOptimizer.php +++ b/Library/Optimizers/FunctionCall/LdexpOptimizer.php @@ -39,9 +39,9 @@ public function getFunctionName() * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/Md5Optimizer.php b/Library/Optimizers/FunctionCall/Md5Optimizer.php index 75e276c446..89c5fbeb7a 100644 --- a/Library/Optimizers/FunctionCall/Md5Optimizer.php +++ b/Library/Optimizers/FunctionCall/Md5Optimizer.php @@ -29,9 +29,9 @@ class Md5Optimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/MergeAppendOptimizer.php b/Library/Optimizers/FunctionCall/MergeAppendOptimizer.php index ab708d1b3e..7d55d98641 100644 --- a/Library/Optimizers/FunctionCall/MergeAppendOptimizer.php +++ b/Library/Optimizers/FunctionCall/MergeAppendOptimizer.php @@ -29,9 +29,9 @@ class MergeAppendOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/MicrotimeOptimizer.php b/Library/Optimizers/FunctionCall/MicrotimeOptimizer.php index 18e97c0f61..9be95691bc 100644 --- a/Library/Optimizers/FunctionCall/MicrotimeOptimizer.php +++ b/Library/Optimizers/FunctionCall/MicrotimeOptimizer.php @@ -29,9 +29,9 @@ class MicrotimeOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/PowOptimizer.php b/Library/Optimizers/FunctionCall/PowOptimizer.php index 3382d28818..f2a1495b89 100644 --- a/Library/Optimizers/FunctionCall/PowOptimizer.php +++ b/Library/Optimizers/FunctionCall/PowOptimizer.php @@ -29,9 +29,9 @@ class PowOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/PregMatchOptimizer.php b/Library/Optimizers/FunctionCall/PregMatchOptimizer.php index b1822b8c8a..23b50522aa 100644 --- a/Library/Optimizers/FunctionCall/PregMatchOptimizer.php +++ b/Library/Optimizers/FunctionCall/PregMatchOptimizer.php @@ -35,9 +35,9 @@ class PregMatchOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return CompiledExpression + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { @@ -118,9 +118,9 @@ public function optimize(array $expression, Call $call, CompilationContext $cont * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return array + * + * @throws CompilerException */ private function processOptionals(array &$expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/PrepareVirtualPathOptimizer.php b/Library/Optimizers/FunctionCall/PrepareVirtualPathOptimizer.php index fa175f9464..cff2c8604e 100644 --- a/Library/Optimizers/FunctionCall/PrepareVirtualPathOptimizer.php +++ b/Library/Optimizers/FunctionCall/PrepareVirtualPathOptimizer.php @@ -29,9 +29,9 @@ class PrepareVirtualPathOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/RoundOptimizer.php b/Library/Optimizers/FunctionCall/RoundOptimizer.php index 7dcd0b0962..3b99a9d00c 100644 --- a/Library/Optimizers/FunctionCall/RoundOptimizer.php +++ b/Library/Optimizers/FunctionCall/RoundOptimizer.php @@ -30,9 +30,9 @@ class RoundOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { @@ -74,9 +74,9 @@ public function optimize(array $expression, Call $call, CompilationContext $cont ); break; - /* - * float $val, int $mode - */ + /* + * float $val, int $mode + */ case 2: $context->codePrinter->output( 'zephir_round('.$symbol.', '.$resolvedParams[0].', '.$resolvedParams[1].', NULL);' diff --git a/Library/Optimizers/FunctionCall/StrReplaceOptimizer.php b/Library/Optimizers/FunctionCall/StrReplaceOptimizer.php index 0e6535308e..6cee852152 100644 --- a/Library/Optimizers/FunctionCall/StrReplaceOptimizer.php +++ b/Library/Optimizers/FunctionCall/StrReplaceOptimizer.php @@ -29,9 +29,9 @@ class StrReplaceOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/StripcslashesOptimizer.php b/Library/Optimizers/FunctionCall/StripcslashesOptimizer.php index 102130fd20..c00f98faec 100644 --- a/Library/Optimizers/FunctionCall/StripcslashesOptimizer.php +++ b/Library/Optimizers/FunctionCall/StripcslashesOptimizer.php @@ -29,9 +29,9 @@ class StripcslashesOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/StripslashesOptimizer.php b/Library/Optimizers/FunctionCall/StripslashesOptimizer.php index 6bf84bbce6..b5bc457bd2 100644 --- a/Library/Optimizers/FunctionCall/StripslashesOptimizer.php +++ b/Library/Optimizers/FunctionCall/StripslashesOptimizer.php @@ -29,9 +29,9 @@ class StripslashesOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/StrposOptimizer.php b/Library/Optimizers/FunctionCall/StrposOptimizer.php index 6a68d4f294..fb6e2a0acf 100644 --- a/Library/Optimizers/FunctionCall/StrposOptimizer.php +++ b/Library/Optimizers/FunctionCall/StrposOptimizer.php @@ -29,9 +29,9 @@ class StrposOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/StrtokOptimizer.php b/Library/Optimizers/FunctionCall/StrtokOptimizer.php index e3b5040570..fa7f4e1a50 100644 --- a/Library/Optimizers/FunctionCall/StrtokOptimizer.php +++ b/Library/Optimizers/FunctionCall/StrtokOptimizer.php @@ -29,9 +29,9 @@ class StrtokOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/StrtolowerOptimizer.php b/Library/Optimizers/FunctionCall/StrtolowerOptimizer.php index 9543ac7f7f..19fc8aa29c 100644 --- a/Library/Optimizers/FunctionCall/StrtolowerOptimizer.php +++ b/Library/Optimizers/FunctionCall/StrtolowerOptimizer.php @@ -29,9 +29,9 @@ class StrtolowerOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/StrtoupperOptimizer.php b/Library/Optimizers/FunctionCall/StrtoupperOptimizer.php index 8c95e9d45e..0713304fb1 100644 --- a/Library/Optimizers/FunctionCall/StrtoupperOptimizer.php +++ b/Library/Optimizers/FunctionCall/StrtoupperOptimizer.php @@ -29,9 +29,9 @@ class StrtoupperOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/SubstrOptimizer.php b/Library/Optimizers/FunctionCall/SubstrOptimizer.php index 8dc69b8a5e..dd0e40c6d3 100644 --- a/Library/Optimizers/FunctionCall/SubstrOptimizer.php +++ b/Library/Optimizers/FunctionCall/SubstrOptimizer.php @@ -29,9 +29,9 @@ class SubstrOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/TimeOptimizer.php b/Library/Optimizers/FunctionCall/TimeOptimizer.php index a96dfa2db5..aa48887ff9 100644 --- a/Library/Optimizers/FunctionCall/TimeOptimizer.php +++ b/Library/Optimizers/FunctionCall/TimeOptimizer.php @@ -29,9 +29,9 @@ class TimeOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/TrimOptimizer.php b/Library/Optimizers/FunctionCall/TrimOptimizer.php index b0f8377dd5..a22a660093 100644 --- a/Library/Optimizers/FunctionCall/TrimOptimizer.php +++ b/Library/Optimizers/FunctionCall/TrimOptimizer.php @@ -31,9 +31,9 @@ class TrimOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/UcfirstOptimizer.php b/Library/Optimizers/FunctionCall/UcfirstOptimizer.php index 0d2b49ddfb..13def33d99 100644 --- a/Library/Optimizers/FunctionCall/UcfirstOptimizer.php +++ b/Library/Optimizers/FunctionCall/UcfirstOptimizer.php @@ -29,9 +29,9 @@ class UcfirstOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/UncamelizeOptimizer.php b/Library/Optimizers/FunctionCall/UncamelizeOptimizer.php index 68036a8429..50daee809a 100644 --- a/Library/Optimizers/FunctionCall/UncamelizeOptimizer.php +++ b/Library/Optimizers/FunctionCall/UncamelizeOptimizer.php @@ -29,9 +29,9 @@ class UncamelizeOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/UniqueKeyOptimizer.php b/Library/Optimizers/FunctionCall/UniqueKeyOptimizer.php index 69e4e3852a..2f06c54489 100644 --- a/Library/Optimizers/FunctionCall/UniqueKeyOptimizer.php +++ b/Library/Optimizers/FunctionCall/UniqueKeyOptimizer.php @@ -29,9 +29,9 @@ class UniqueKeyOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/UniquePathKeyOptimizer.php b/Library/Optimizers/FunctionCall/UniquePathKeyOptimizer.php index b241f3528a..9ab964b968 100644 --- a/Library/Optimizers/FunctionCall/UniquePathKeyOptimizer.php +++ b/Library/Optimizers/FunctionCall/UniquePathKeyOptimizer.php @@ -29,9 +29,9 @@ class UniquePathKeyOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/VarExportOptimizer.php b/Library/Optimizers/FunctionCall/VarExportOptimizer.php index f99f0c3d4f..180e07ea36 100644 --- a/Library/Optimizers/FunctionCall/VarExportOptimizer.php +++ b/Library/Optimizers/FunctionCall/VarExportOptimizer.php @@ -30,9 +30,9 @@ class VarExportOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/FunctionCall/ZephirStringToHexOptimizer.php b/Library/Optimizers/FunctionCall/ZephirStringToHexOptimizer.php index 8b19da0264..c9357d95ee 100644 --- a/Library/Optimizers/FunctionCall/ZephirStringToHexOptimizer.php +++ b/Library/Optimizers/FunctionCall/ZephirStringToHexOptimizer.php @@ -29,9 +29,9 @@ class ZephirStringToHexOptimizer extends OptimizerAbstract * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Optimizers/IsTypeOptimizerAbstract.php b/Library/Optimizers/IsTypeOptimizerAbstract.php index 9b1e0b92b1..17186a38b8 100644 --- a/Library/Optimizers/IsTypeOptimizerAbstract.php +++ b/Library/Optimizers/IsTypeOptimizerAbstract.php @@ -18,8 +18,6 @@ use Zephir\CompiledExpression; use Zephir\Exception; -use function count; - abstract class IsTypeOptimizerAbstract extends OptimizerAbstract { /** @@ -33,7 +31,7 @@ abstract class IsTypeOptimizerAbstract extends OptimizerAbstract */ public function optimize(array $expression, Call $call, CompilationContext $context): ?CompiledExpression { - if (!isset($expression['parameters']) || count($expression['parameters']) !== 1) { + if (!isset($expression['parameters']) || \count($expression['parameters']) !== 1) { return null; } diff --git a/Library/Optimizers/MathOptimizer.php b/Library/Optimizers/MathOptimizer.php index 36e7ba3da8..36e1fb3ba6 100644 --- a/Library/Optimizers/MathOptimizer.php +++ b/Library/Optimizers/MathOptimizer.php @@ -32,9 +32,9 @@ abstract public function getFunctionName(); * @param Call $call * @param CompilationContext $context * - * @throws CompilerException - * * @return bool|CompiledExpression|mixed + * + * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { diff --git a/Library/Parser/Manager.php b/Library/Parser/Manager.php index 70cf7160cf..8eb8f3371c 100644 --- a/Library/Parser/Manager.php +++ b/Library/Parser/Manager.php @@ -32,8 +32,8 @@ public function getParser(): Parser */ public function isAvailable(): bool { - return $this->parser->isAvailable() && - version_compare(self::MINIMUM_PARSER_VERSION, $this->parser->getVersion(), '<='); + return $this->parser->isAvailable() + && version_compare(self::MINIMUM_PARSER_VERSION, $this->parser->getVersion(), '<='); } public function requirements(): string diff --git a/Library/Parser/Parser.php b/Library/Parser/Parser.php index be20898ba4..9973cbebc9 100644 --- a/Library/Parser/Parser.php +++ b/Library/Parser/Parser.php @@ -17,8 +17,6 @@ use Zephir\Exception\InvalidArgumentException; use Zephir\Exception\ParseException; -use function function_exists; - class Parser { /** @@ -28,7 +26,7 @@ class Parser */ public function isAvailable(): bool { - return function_exists('zephir_parse_file'); + return \function_exists('zephir_parse_file'); } /** diff --git a/Library/Passes/LocalContextPass.php b/Library/Passes/LocalContextPass.php index f160bbde3e..1dd6d0d16b 100644 --- a/Library/Passes/LocalContextPass.php +++ b/Library/Passes/LocalContextPass.php @@ -15,10 +15,6 @@ use Zephir\StatementsBlock; -use function constant; -use function defined; -use function gettype; - /** * This pass tries to check whether variables only do exist in the local context of the method block * or if they're used externally which will un allow variables to be placed in the stack @@ -88,7 +84,7 @@ public function markVariableNoLocal(string $variable): void * Marks the latest use/read of a variable. * * @param string $variable - * @param array $node + * @param array $node */ public function markLastUse(string $variable, array $node): void { @@ -203,8 +199,8 @@ public function passLetStatement(array $statement): void break; case 'constant': - if (defined($assignment['expr']['value'])) { - if ('string' === gettype(constant($assignment['expr']['value']))) { + if (\defined($assignment['expr']['value'])) { + if ('string' === \gettype(\constant($assignment['expr']['value']))) { $this->markVariableNoLocal($assignment['variable']); } } @@ -225,7 +221,7 @@ public function passLetStatement(array $statement): void break; default: - //echo '[', $assignment['expr']['type'], ']', PHP_EOL; + // echo '[', $assignment['expr']['type'], ']', PHP_EOL; } break; @@ -246,12 +242,12 @@ public function passLetStatement(array $statement): void $this->markVariableNoLocal($assignment['expr']['value']); break; default: - //echo '[', $assignment['assign-type'], ']'; + // echo '[', $assignment['assign-type'], ']'; } break; default: - //echo $assignment['assign-type']; + // echo $assignment['assign-type']; } } } diff --git a/Library/Passes/SkipVariantInit.php b/Library/Passes/SkipVariantInit.php index 2843a5a5c0..3587011a6c 100644 --- a/Library/Passes/SkipVariantInit.php +++ b/Library/Passes/SkipVariantInit.php @@ -13,8 +13,6 @@ use Zephir\StatementsBlock; -use function count; - /** * In 'if'/'else' statements sometimes dynamical variables are initialized in every branch * Same case in 'switch' statements @@ -28,7 +26,7 @@ class SkipVariantInit /** * Do the compilation pass. * - * @param int $branchNumber + * @param int $branchNumber * @param StatementsBlock $block */ public function pass(int $branchNumber, StatementsBlock $block): void @@ -40,7 +38,7 @@ public function pass(int $branchNumber, StatementsBlock $block): void /** * Check assignment types for possible skip. * - * @param int $branchNumber + * @param int $branchNumber * @param array $statement */ public function passLetStatement(int $branchNumber, array $statement): void @@ -99,7 +97,7 @@ public function getVariables(): array } $variables = []; - $numberBranches = count($this->branches); + $numberBranches = \count($this->branches); foreach ($variableStats as $variable => $number) { if ($number == $numberBranches) { $variables[] = $variable; @@ -110,7 +108,7 @@ public function getVariables(): array } /** - * @param int $branchNumber + * @param int $branchNumber * @param array $variablesToSkip */ public function setVariablesToSkip(int $branchNumber, array $variablesToSkip): void diff --git a/Library/Passes/StaticTypeInference.php b/Library/Passes/StaticTypeInference.php index 0b58a7ba90..9ae1278f8e 100644 --- a/Library/Passes/StaticTypeInference.php +++ b/Library/Passes/StaticTypeInference.php @@ -198,7 +198,7 @@ public function getInferedType($variable) if (isset($this->variables[$variable])) { $type = $this->variables[$variable]; if ('variable' != $type && 'undefined' != $type && 'string' != $type && 'istring' != $type && 'array' != $type && 'null' != $type && 'numeric' != $type) { - //echo $variable, ' ', $type, PHP_EOL; + // echo $variable, ' ', $type, PHP_EOL; return $type; } } @@ -457,8 +457,8 @@ public function passExpression(array $expression) case 'ternary': case 'short-ternary': - //$right = $this->passExpression($expression['right']); - //$extra = $this->passExpression($expression['extra']); + // $right = $this->passExpression($expression['right']); + // $extra = $this->passExpression($expression['extra']); /*if ($right == $extra) { if ($right != 'string' && $right != 'array') { return $right; @@ -576,7 +576,7 @@ public function passStatementBlock(array $statements) case 'unset': case 'cblock': case 'comment': - // empty statement != empty operator + // empty statement != empty operator case 'empty': break; diff --git a/Library/Statements/DoWhileStatement.php b/Library/Statements/DoWhileStatement.php index bf33f534d4..0a8afbc17e 100644 --- a/Library/Statements/DoWhileStatement.php +++ b/Library/Statements/DoWhileStatement.php @@ -11,7 +11,6 @@ namespace Zephir\Statements; -use ReflectionException; use Zephir\CompilationContext; use Zephir\Exception; use Zephir\Optimizers\EvalExpression; @@ -24,7 +23,8 @@ class DoWhileStatement extends StatementAbstract { /** * @param CompilationContext $compilationContext - * @throws ReflectionException + * + * @throws \ReflectionException * @throws Exception */ public function compile(CompilationContext $compilationContext): void diff --git a/Library/Statements/EchoStatement.php b/Library/Statements/EchoStatement.php index 87f442fb8c..d640aaf9e9 100644 --- a/Library/Statements/EchoStatement.php +++ b/Library/Statements/EchoStatement.php @@ -11,7 +11,6 @@ namespace Zephir\Statements; -use ReflectionException; use Zephir\CompilationContext; use Zephir\Exception; use Zephir\Exception\CompilerException; @@ -27,7 +26,7 @@ class EchoStatement extends StatementAbstract /** * @param CompilationContext $compilationContext * - * @throws ReflectionException + * @throws \ReflectionException * @throws Exception */ public function compile(CompilationContext $compilationContext): void diff --git a/Library/Statements/ForStatement.php b/Library/Statements/ForStatement.php index 5edf1e3a0d..63a0561da6 100644 --- a/Library/Statements/ForStatement.php +++ b/Library/Statements/ForStatement.php @@ -11,7 +11,6 @@ namespace Zephir\Statements; -use ReflectionException; use Zephir\CompilationContext; use Zephir\Detectors\ForValueUseDetector; use Zephir\Exception; @@ -22,6 +21,7 @@ use Zephir\Optimizers\EvalExpression; use Zephir\StatementsBlock; use Zephir\Variable\Variable; + use function Zephir\add_slashes; class ForStatement extends StatementAbstract @@ -29,11 +29,12 @@ class ForStatement extends StatementAbstract /** * Compiles a for statement that use a 'range' as expression. * - * @param array $exprRaw + * @param array $exprRaw * @param CompilationContext $compilationContext * * @return bool - * @throws ReflectionException + * + * @throws \ReflectionException * @throws Exception */ public function compileRange(array $exprRaw, CompilationContext $compilationContext): bool @@ -394,12 +395,13 @@ public function compileRange(array $exprRaw, CompilationContext $compilationCont /** * Compiles a 'for' statement that use an 'iterator' as expression. * - * @param array $exprRaw + * @param array $exprRaw * @param CompilationContext $compilationContext * * @return void + * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compileIterator(array $exprRaw, CompilationContext $compilationContext): void { @@ -520,11 +522,12 @@ public function compileIterator(array $exprRaw, CompilationContext $compilationC * - Every key must be an integer or compatible * - Every value must be a char/integer or compatible. * - * @param array $expression + * @param array $expression * @param CompilationContext $compilationContext - * @param Variable $exprVariable + * @param Variable $exprVariable + * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compileStringTraverse($expression, CompilationContext $compilationContext, $exprVariable) { @@ -745,7 +748,7 @@ public function compileHashTraverse(CompilationContext $compilationContext, Vari * @param CompilationContext $compilationContext * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(CompilationContext $compilationContext): void { diff --git a/Library/Statements/IfStatement.php b/Library/Statements/IfStatement.php index df1756947e..6c8c29c55a 100644 --- a/Library/Statements/IfStatement.php +++ b/Library/Statements/IfStatement.php @@ -11,7 +11,6 @@ namespace Zephir\Statements; -use ReflectionException; use Zephir\Branch; use Zephir\CompilationContext; use Zephir\Detectors\ReadDetector; @@ -27,7 +26,8 @@ class IfStatement extends StatementAbstract { /** * @param CompilationContext $compilationContext - * @throws ReflectionException + * + * @throws \ReflectionException * @throws Exception */ public function compile(CompilationContext $compilationContext): void diff --git a/Library/Statements/Let/ArrayIndex.php b/Library/Statements/Let/ArrayIndex.php index 9880cbcef0..25a7fa1d15 100644 --- a/Library/Statements/Let/ArrayIndex.php +++ b/Library/Statements/Let/ArrayIndex.php @@ -96,9 +96,9 @@ public function assign($variable, ZephirVariable $symbolVariable, CompiledExpres * @param CompiledExpression $resolvedExpr * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return GlobalConstant|ZephirVariable + * + * @throws CompilerException */ protected function _getResolvedArrayItem(CompiledExpression $resolvedExpr, CompilationContext $compilationContext) { diff --git a/Library/Statements/Let/ObjectDynamicProperty.php b/Library/Statements/Let/ObjectDynamicProperty.php index 9c7ade5d1e..bdb85e1beb 100644 --- a/Library/Statements/Let/ObjectDynamicProperty.php +++ b/Library/Statements/Let/ObjectDynamicProperty.php @@ -13,7 +13,6 @@ namespace Zephir\Statements\Let; -use Exception; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception\CompilerException; @@ -34,7 +33,7 @@ class ObjectDynamicProperty * @param array $statement * * @throws CompilerException - * @throws Exception + * @throws \Exception */ public function assign(string $variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, array $statement) { @@ -104,7 +103,7 @@ public function assign(string $variable, ZephirVariable $symbolVariable, Compile } elseif ('0' == $resolvedExpr->getBooleanCode()) { $value = 'false'; } else { - throw new Exception('?'); + throw new \Exception('?'); } $compilationContext->backend->updateProperty($symbolVariable, $propertyVariableName, $value, $compilationContext); diff --git a/Library/Statements/Let/ObjectProperty.php b/Library/Statements/Let/ObjectProperty.php index c277bb8c0a..09d9a63227 100644 --- a/Library/Statements/Let/ObjectProperty.php +++ b/Library/Statements/Let/ObjectProperty.php @@ -239,7 +239,7 @@ public function assign( $codePrinter->output('}'); break; - /* unreachable code */ + /* unreachable code */ case 'empty-array': $tempVariable = $context->symbolTable->getTempNonTrackedVariable('variable', $context); diff --git a/Library/Statements/Let/ObjectPropertyArrayIndexAppend.php b/Library/Statements/Let/ObjectPropertyArrayIndexAppend.php index a27b54ae01..63edeadddb 100644 --- a/Library/Statements/Let/ObjectPropertyArrayIndexAppend.php +++ b/Library/Statements/Let/ObjectPropertyArrayIndexAppend.php @@ -48,10 +48,10 @@ public function assign($variable, ZephirVariable $symbolVariable, CompiledExpres /** * Compiles x->y[a][b][] = {expr} (multiple offset assignment). * - * @param ZephirVariable $symbolVariable + * @param ZephirVariable $symbolVariable * @param CompiledExpression $resolvedExpr * @param CompilationContext $compilationContext - * @param array $statement + * @param array $statement * * @throws \ReflectionException * @throws Exception diff --git a/Library/Statements/Let/StaticProperty.php b/Library/Statements/Let/StaticProperty.php index 01258407c7..2f011da5a9 100644 --- a/Library/Statements/Let/StaticProperty.php +++ b/Library/Statements/Let/StaticProperty.php @@ -13,7 +13,6 @@ namespace Zephir\Statements\Let; -use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; @@ -28,13 +27,13 @@ class StaticProperty /** * Compiles ClassName::foo = {expr}. * - * @param string $className - * @param string $property + * @param string $className + * @param string $property * @param CompiledExpression $resolvedExpr * @param CompilationContext $compilationContext - * @param array $statement + * @param array $statement * - * @throws ReflectionException + * @throws \ReflectionException */ public function assignStatic( string $className, diff --git a/Library/Statements/Let/Variable.php b/Library/Statements/Let/Variable.php index 594e806009..0387e5fa06 100644 --- a/Library/Statements/Let/Variable.php +++ b/Library/Statements/Let/Variable.php @@ -18,6 +18,7 @@ use Zephir\Exception\CompilerException; use Zephir\Exception\IllegalOperationException; use Zephir\Variable\Variable as ZephirVariable; + use function Zephir\add_slashes; /** @@ -115,10 +116,10 @@ public function assign( * @throws \Zephir\Exception\IllegalOperationException */ private function doNumericAssignment( - Printer $codePrinter, + Printer $codePrinter, CompiledExpression $resolvedExpr, - string $variable, - array $statement, + string $variable, + array $statement, CompilationContext $compilationContext ) { switch ($resolvedExpr->getType()) { @@ -347,10 +348,10 @@ private function doNumericAssignment( * @throws IllegalOperationException */ private function doDoubleAssignment( - Printer $codePrinter, + Printer $codePrinter, CompiledExpression $resolvedExpr, - string $variable, - array $statement, + string $variable, + array $statement, CompilationContext $compilationContext ) { switch ($resolvedExpr->getType()) { @@ -528,11 +529,11 @@ private function doDoubleAssignment( * @throws \Zephir\Exception\IllegalOperationException */ private function doStringAssignment( - Printer $codePrinter, + Printer $codePrinter, CompiledExpression $resolvedExpr, - ZephirVariable $symbolVariable, - string $variable, - array $statement, + ZephirVariable $symbolVariable, + string $variable, + array $statement, CompilationContext $compilationContext ) { switch ($resolvedExpr->getType()) { @@ -705,7 +706,7 @@ private function doStringAssignment( /** * Performs array assignment. * - * @param Printer $codePrinter + * @param Printer $codePrinter * @param CompiledExpression $resolvedExpr * @param ZephirVariable $symbolVariable * @param string $variable @@ -716,11 +717,11 @@ private function doStringAssignment( * @throws IllegalOperationException */ private function doArrayAssignment( - Printer $codePrinter, + Printer $codePrinter, CompiledExpression $resolvedExpr, - ZephirVariable $symbolVariable, - string $variable, - array $statement, + ZephirVariable $symbolVariable, + string $variable, + array $statement, CompilationContext $compilationContext ) { switch ($resolvedExpr->getType()) { @@ -754,7 +755,7 @@ private function doArrayAssignment( /** * Performs boolean assignment. * - * @param Printer $codePrinter + * @param Printer $codePrinter * @param CompiledExpression $resolvedExpr * @param string $variable * @param array $statement @@ -764,10 +765,10 @@ private function doArrayAssignment( * @throws IllegalOperationException */ private function doBoolAssignment( - Printer $codePrinter, + Printer $codePrinter, CompiledExpression $resolvedExpr, - string $variable, - array $statement, + string $variable, + array $statement, CompilationContext $compilationContext ) { switch ($resolvedExpr->getType()) { @@ -889,7 +890,7 @@ private function doBoolAssignment( /** * Performs variable assignment. * - * @param Printer $codePrinter + * @param Printer $codePrinter * @param CompiledExpression $resolvedExpr * @param ZephirVariable $symbolVariable * @param string $variable @@ -901,13 +902,13 @@ private function doBoolAssignment( * @throws IllegalOperationException */ private function doVariableAssignment( - Printer $codePrinter, + Printer $codePrinter, CompiledExpression $resolvedExpr, - ZephirVariable $symbolVariable, - string $variable, - array $statement, + ZephirVariable $symbolVariable, + string $variable, + array $statement, CompilationContext $compilationContext, - ReadDetector $readDetector + ReadDetector $readDetector ) { switch ($resolvedExpr->getType()) { case 'null': diff --git a/Library/Statements/Let/VariableAppend.php b/Library/Statements/Let/VariableAppend.php index caccc18bfa..7b850d9dfd 100644 --- a/Library/Statements/Let/VariableAppend.php +++ b/Library/Statements/Let/VariableAppend.php @@ -26,11 +26,11 @@ class VariableAppend /** * Compiles foo[] = {expr}. * - * @param $variable + * @param $variable * @param ZephirVariable $symbolVariable * @param CompiledExpression $resolvedExpr * @param CompilationContext $compilationContext - * @param $statement + * @param $statement * * @throws CompilerException */ diff --git a/Library/Statements/ReturnStatement.php b/Library/Statements/ReturnStatement.php index 551236cf33..4104c0476a 100644 --- a/Library/Statements/ReturnStatement.php +++ b/Library/Statements/ReturnStatement.php @@ -11,13 +11,13 @@ namespace Zephir\Statements; -use ReflectionException; use Zephir\CompilationContext; use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Exception\InvalidTypeException; use Zephir\Expression; use Zephir\Types\Types; + use function Zephir\add_slashes; /** @@ -29,7 +29,7 @@ final class ReturnStatement extends StatementAbstract * @param CompilationContext $compilationContext * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(CompilationContext $compilationContext): void { diff --git a/Library/Statements/SwitchStatement.php b/Library/Statements/SwitchStatement.php index bff0c62b27..5db2f726df 100644 --- a/Library/Statements/SwitchStatement.php +++ b/Library/Statements/SwitchStatement.php @@ -17,7 +17,6 @@ use Zephir\Expression; use Zephir\Optimizers\EvalExpression; use Zephir\StatementsBlock; -use function count; /** * Switch statement, the same as in PHP/C @@ -26,6 +25,7 @@ class SwitchStatement extends StatementAbstract { /** * @param CompilationContext $compilationContext + * * @throws \ReflectionException * @throws Exception */ @@ -122,7 +122,7 @@ public function compile(CompilationContext $compilationContext): void foreach ($blocks as $block) { $expressions = $block['expr']; - if (1 == count($expressions)) { + if (1 == \count($expressions)) { $condition = $evalExpr->optimize($expressions[0], $compilationContext); $codePrinter->output('if ('.$condition.') {'); } else { @@ -167,7 +167,7 @@ public function normalizeClauses($clauses) } } - if ($defaultIndex === count($clauses) - 1) { + if ($defaultIndex === \count($clauses) - 1) { return $clauses; } diff --git a/Library/Statements/ThrowStatement.php b/Library/Statements/ThrowStatement.php index f7394034e1..701cc7b69b 100644 --- a/Library/Statements/ThrowStatement.php +++ b/Library/Statements/ThrowStatement.php @@ -13,7 +13,6 @@ namespace Zephir\Statements; -use ReflectionException; use Zephir\Class\Entry; use Zephir\Code\Printer; use Zephir\CompilationContext; @@ -21,7 +20,7 @@ use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; -use function in_array; + use function Zephir\add_slashes; use function Zephir\fqcn; @@ -34,7 +33,7 @@ class ThrowStatement extends StatementAbstract * @param CompilationContext $compilationContext * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(CompilationContext $compilationContext): void { @@ -48,10 +47,10 @@ public function compile(CompilationContext $compilationContext): void * This optimizes throw new Exception("hello") */ if (!$compilationContext->insideTryCatch) { - if (isset($expr['class']) && - isset($expr['parameters']) && - 1 == \count($expr['parameters']) && - 'string' == $expr['parameters'][0]['parameter']['type'] + if (isset($expr['class']) + && isset($expr['parameters']) + && 1 == \count($expr['parameters']) + && 'string' == $expr['parameters'][0]['parameter']['type'] ) { $className = fqcn( $expr['class'], @@ -80,7 +79,7 @@ public function compile(CompilationContext $compilationContext): void } } } else { - if (in_array($expr['type'], ['string', 'char', 'int', 'double'])) { + if (\in_array($expr['type'], ['string', 'char', 'int', 'double'])) { $class = (new Entry('Exception', $compilationContext))->get(); $this->throwStringException($codePrinter, $class, $expr['value'], $expr); @@ -97,7 +96,7 @@ public function compile(CompilationContext $compilationContext): void throw new CompilerException($e->getMessage(), $expr, $e->getCode(), $e); } - if (!in_array($resolvedExpr->getType(), ['variable', 'string'])) { + if (!\in_array($resolvedExpr->getType(), ['variable', 'string'])) { throw new CompilerException( "Expression '".$resolvedExpr->getType().'" cannot be used as exception', $expr @@ -110,7 +109,7 @@ public function compile(CompilationContext $compilationContext): void $expr ); - if (!in_array($variableVariable->getType(), ['variable', 'string'])) { + if (!\in_array($variableVariable->getType(), ['variable', 'string'])) { throw new CompilerException( "Variable '".$variableVariable->getType()."' cannot be used as exception", $expr @@ -142,9 +141,9 @@ public function compile(CompilationContext $compilationContext): void * Throws an exception escaping the data. * * @param Printer $printer - * @param string $class - * @param string $message - * @param array $expression + * @param string $class + * @param string $message + * @param array $expression */ private function throwStringException(Printer $printer, string $class, string $message, array $expression): void { diff --git a/Library/Statements/UnsetStatement.php b/Library/Statements/UnsetStatement.php index e8eda65fcd..b6da495c60 100644 --- a/Library/Statements/UnsetStatement.php +++ b/Library/Statements/UnsetStatement.php @@ -13,14 +13,11 @@ namespace Zephir\Statements; -use ReflectionException; use Zephir\CompilationContext; use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; -use function in_array; - /** * unset() statement */ @@ -30,7 +27,7 @@ class UnsetStatement extends StatementAbstract * @param CompilationContext $compilationContext * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(CompilationContext $compilationContext): void { @@ -79,7 +76,7 @@ public function compile(CompilationContext $compilationContext): void throw new CompilerException('Cannot use expression type: '.$expression['type'].' in "unset"', $expression); } - if (!in_array($variable->getType(), ['variable', 'array'])) { + if (!\in_array($variable->getType(), ['variable', 'array'])) { throw new CompilerException('Cannot use variable type: '.$variable->gettype().' in "unset"', $expression['left']); } @@ -100,7 +97,7 @@ public function compile(CompilationContext $compilationContext): void * @return CompilationContext * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ private function generateUnsetPropertyFromObject(array $expression, CompilationContext $compilationContext): CompilationContext { diff --git a/Library/StatementsBlock.php b/Library/StatementsBlock.php index c29c9e112a..8cfafe5f97 100644 --- a/Library/StatementsBlock.php +++ b/Library/StatementsBlock.php @@ -11,7 +11,6 @@ namespace Zephir; -use ReflectionException; use Zephir\Passes\MutateGathererPass; use Zephir\Statements\BreakStatement; use Zephir\Statements\ContinueStatement; @@ -30,7 +29,6 @@ use Zephir\Statements\TryCatchStatement; use Zephir\Statements\UnsetStatement; use Zephir\Statements\WhileStatement; -use function count; /** * This represents a single basic block in Zephir. @@ -87,9 +85,9 @@ public function isLoop(bool $loop): static * @return Branch * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ - public function compile(CompilationContext $compilationContext, ?bool $unreachable = null, int $branchType = Branch::TYPE_UNKNOWN): Branch + public function compile(CompilationContext $compilationContext, bool $unreachable = null, int $branchType = Branch::TYPE_UNKNOWN): Branch { $compilationContext->codePrinter->increaseLevel(); ++$compilationContext->currentBranch; @@ -410,7 +408,7 @@ public function getLastStatement() */ public function isEmpty(): bool { - return 0 === count($this->statements); + return 0 === \count($this->statements); } /** diff --git a/Library/StaticCall.php b/Library/StaticCall.php index c1161bbebc..1d9a44da86 100644 --- a/Library/StaticCall.php +++ b/Library/StaticCall.php @@ -11,15 +11,11 @@ namespace Zephir; -use ReflectionException; use Zephir\Class\Definition\Definition; use Zephir\Class\Method\Method; use Zephir\Detectors\ReadDetector; use Zephir\Exception\CompilerException; use Zephir\Variable\Variable; -use function count; -use function in_array; -use function is_string; /** * Call methods in a static context @@ -29,13 +25,13 @@ class StaticCall extends Call /** * Compiles a static method call. * - * @param Expression $expr + * @param Expression $expr * @param CompilationContext $compilationContext * * @return CompiledExpression * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function compile(Expression $expr, CompilationContext $compilationContext): CompiledExpression { @@ -91,8 +87,8 @@ public function compile(Expression $expr, CompilationContext $compilationContext $className = $expression['class']; $classDefinition = false; - if (!in_array($className, ['self', 'static', 'parent'])) { - if (is_string($className)) { + if (!\in_array($className, ['self', 'static', 'parent'])) { + if (\is_string($className)) { $className = $compilationContext->getFullName($className); if ($compiler->isClass($className)) { $classDefinition = $compiler->getClassDefinition($className); @@ -147,7 +143,7 @@ public function compile(Expression $expr, CompilationContext $compilationContext throw new CompilerException("Cannot call private method '".$methodName."' out of its scope", $expression); } - if (!in_array($className, ['self', 'static', 'parent']) && !$method->isStatic()) { + if (!\in_array($className, ['self', 'static', 'parent']) && !$method->isStatic()) { throw new CompilerException("Cannot call non-static method '".$methodName."' in a static way", $expression); } @@ -156,7 +152,7 @@ public function compile(Expression $expr, CompilationContext $compilationContext /** * Try to produce an exception if method is called with a wrong number of parameters */ - $callNumberParameters = isset($expression['parameters']) ? count($expression['parameters']) : 0; + $callNumberParameters = isset($expression['parameters']) ? \count($expression['parameters']) : 0; $classMethod = $classDefinition->getMethod($methodName); $expectedNumberParameters = $classMethod->getNumberOfRequiredParameters(); @@ -191,7 +187,7 @@ public function compile(Expression $expr, CompilationContext $compilationContext if ($dynamicClass) { $this->callFromDynamicClass($methodName, $expression, $symbolVariable, $mustInit, $isExpecting, $compilationContext); } else { - if (in_array($className, ['self', 'static']) || $classDefinition == $compilationContext->classDefinition) { + if (\in_array($className, ['self', 'static']) || $classDefinition == $compilationContext->classDefinition) { $this->call(strtoupper($className), $methodName, $expression, $mustInit, $isExpecting, $compilationContext, $symbolVariable, $method ?? null); } else { if ('parent' == $className) { @@ -243,14 +239,15 @@ public function compile(Expression $expr, CompilationContext $compilationContext /** * Calls static methods on the 'self/static' context. * - * @param string $context SELF / STATIC - * @param string $methodName - * @param array $expression - * @param bool $mustInit - * @param bool $isExpecting + * @param string $context SELF / STATIC + * @param string $methodName + * @param array $expression + * @param bool $mustInit + * @param bool $isExpecting * @param CompilationContext $compilationContext - * @param Variable|null $symbolVariable - * @param Method|null $method + * @param Variable|null $symbolVariable + * @param Method|null $method + * * @throws Exception */ protected function call( @@ -260,10 +257,10 @@ protected function call( bool $mustInit, bool $isExpecting, CompilationContext $compilationContext, - ?Variable $symbolVariable = null, - ?Method $method = null + Variable $symbolVariable = null, + Method $method = null ): void { - if (!in_array($context, ['SELF', 'STATIC'])) { + if (!\in_array($context, ['SELF', 'STATIC'])) { $context = 'SELF'; } @@ -293,7 +290,7 @@ protected function call( $cachePointer = $methodCache->get($compilationContext, $method ?? null); $params = []; - if (isset($expression['parameters']) && count($expression['parameters'])) { + if (isset($expression['parameters']) && \count($expression['parameters'])) { $params = $this->getResolvedParams($expression['parameters'], $compilationContext, $expression); } @@ -301,7 +298,7 @@ protected function call( $symbol = $compilationContext->backend->getVariableCode($symbolVariable); } - $paramCount = count($params); + $paramCount = \count($params); $paramsStr = $paramCount ? ', '.implode(', ', $params) : ''; $isInternal = isset($method) && $method->isInternal(); @@ -344,14 +341,15 @@ protected function call( /** * Calls static methods on the 'parent' context. * - * @param string $methodName - * @param array $expression - * @param Variable $symbolVariable - * @param bool $mustInit - * @param bool $isExpecting - * @param Definition $classDefinition + * @param string $methodName + * @param array $expression + * @param Variable $symbolVariable + * @param bool $mustInit + * @param bool $isExpecting + * @param Definition $classDefinition * @param CompilationContext $compilationContext - * @param Method $method + * @param Method $method + * * @throws Exception */ protected function callParent(string $methodName, array $expression, $symbolVariable, $mustInit, $isExpecting, Definition $classDefinition, CompilationContext $compilationContext, Method $method) @@ -376,11 +374,11 @@ protected function callParent(string $methodName, array $expression, $symbolVari $cachePointer = $methodCache->get($compilationContext, isset($method) ? $method : null); $params = []; - if (isset($expression['parameters']) && count($expression['parameters'])) { + if (isset($expression['parameters']) && \count($expression['parameters'])) { $params = $this->getResolvedParams($expression['parameters'], $compilationContext, $expression); } - if (!count($params)) { + if (!\count($params)) { if ($isExpecting) { if ('return_value' == $symbolVariable->getName()) { $codePrinter->output('ZEPHIR_RETURN_CALL_PARENT('.$classCe.', getThis(), "'.$methodName.'", '.$cachePointer.');'); @@ -415,14 +413,15 @@ protected function callParent(string $methodName, array $expression, $symbolVari /** * Calls static methods on some class context. * - * @param string $methodName - * @param array $expression - * @param Variable $symbolVariable - * @param bool $mustInit - * @param bool $isExpecting - * @param Definition $classDefinition + * @param string $methodName + * @param array $expression + * @param Variable $symbolVariable + * @param bool $mustInit + * @param bool $isExpecting + * @param Definition $classDefinition * @param CompilationContext $compilationContext - * @param Method $method + * @param Method $method + * * @throws Exception */ protected function callFromClass($methodName, array $expression, $symbolVariable, $mustInit, $isExpecting, Definition $classDefinition, CompilationContext $compilationContext, Method $method) @@ -456,7 +455,7 @@ protected function callFromClass($methodName, array $expression, $symbolVariable $cachePointer = $methodCache->get($compilationContext, $method); $params = []; - if (isset($expression['parameters']) && count($expression['parameters'])) { + if (isset($expression['parameters']) && \count($expression['parameters'])) { $params = $this->getResolvedParams($expression['parameters'], $compilationContext, $expression); } @@ -464,7 +463,7 @@ protected function callFromClass($methodName, array $expression, $symbolVariable $symbol = $compilationContext->backend->getVariableCode($symbolVariable); } - $paramCount = count($params); + $paramCount = \count($params); $paramsStr = $paramCount ? ', '.implode(', ', $params) : ''; if ($method->isInternal()) { @@ -506,7 +505,7 @@ protected function callFromClass($methodName, array $expression, $symbolVariable /** * Calls static methods on using a dynamic variable as class. * - * @param string $methodName + * @param string $methodName * @param array $expression * @param Variable $symbolVariable * @param bool $mustInit @@ -523,7 +522,7 @@ protected function callFromDynamicClass(string $methodName, array $expression, $ $cachePointer = 'NULL, 0'; - if (!count($params)) { + if (!\count($params)) { if ($isExpecting) { if ('return_value' == $symbolVariable->getName()) { $compilationContext->codePrinter->output('ZEPHIR_RETURN_CALL_CE_STATIC('.$classEntry.', "'.$methodName.'", '.$cachePointer.');'); @@ -558,10 +557,10 @@ protected function callFromDynamicClass(string $methodName, array $expression, $ /** * Calls static methods on using a dynamic variable as class and a dynamic method. * - * @param array $expression - * @param Variable $symbolVariable - * @param bool $mustInit - * @param bool $isExpecting + * @param array $expression + * @param Variable $symbolVariable + * @param bool $mustInit + * @param bool $isExpecting * @param CompilationContext $compilationContext */ protected function callFromDynamicClassDynamicMethod(array $expression, $symbolVariable, bool $mustInit, bool $isExpecting, CompilationContext $compilationContext): void @@ -582,7 +581,7 @@ protected function callFromDynamicClassDynamicMethod(array $expression, $symbolV $cachePointer = 'NULL, 0'; - if (!count($params)) { + if (!\count($params)) { if ($isExpecting) { if ('return_value' === $symbolVariable->getName()) { $compilationContext->codePrinter->output('ZEPHIR_RETURN_CALL_CE_STATIC_ZVAL('.$classEntry.', '.$methodNameVariable->getName().', '.$cachePointer.');'); diff --git a/Library/Stubs/DocBlock.php b/Library/Stubs/DocBlock.php index d31b576a47..f0ba7018e1 100644 --- a/Library/Stubs/DocBlock.php +++ b/Library/Stubs/DocBlock.php @@ -13,8 +13,6 @@ namespace Zephir\Stubs; -use function count; - /** * @author Gusakov Nikita */ @@ -43,7 +41,7 @@ public function __construct(?string $source, string $indent = ' ') { $this->indent = $indent; $lines = explode("\n", trim($source ?: '')); - $count = count($lines); + $count = \count($lines); foreach ($lines as $i => $line) { $line = preg_replace('#^([\s\t]+)?/?([*]+)([\s\t]+)?$#im', '', rtrim($line)); @@ -56,7 +54,7 @@ public function __construct(?string $source, string $indent = ' ') $cleaned = trim($line, "\t*\0 "); $cleaned = str_replace('$$', '$', $cleaned); - if (0 === strpos($cleaned, '@')) { + if (str_starts_with($cleaned, '@')) { $this->lines[] = $cleaned; } else { $line = preg_replace('#([\s\t]+)?[*]#', '', $line); @@ -68,7 +66,7 @@ public function __construct(?string $source, string $indent = ' ') } } - if (!empty($this->lines) && 0 !== strpos(trim($this->lines[0], "\t*\0 "), '@')) { + if (!empty($this->lines) && !str_starts_with(trim($this->lines[0], "\t*\0 "), '@')) { $description = array_shift($this->lines); $description = explode("\n", $description); diff --git a/Library/Stubs/Generator.php b/Library/Stubs/Generator.php index f1ec5af964..049cd823a2 100644 --- a/Library/Stubs/Generator.php +++ b/Library/Stubs/Generator.php @@ -14,15 +14,13 @@ namespace Zephir\Stubs; use Zephir\AliasManager; -use Zephir\Class\Property; use Zephir\Class\Constant; use Zephir\Class\Definition\Definition; -use Zephir\Class\Method\Parameters; use Zephir\Class\Method\Method; +use Zephir\Class\Method\Parameters; +use Zephir\Class\Property; use Zephir\CompilerFile; use Zephir\Exception; -use function array_key_exists; -use function in_array; class Generator { @@ -37,6 +35,7 @@ class Generator 'scoped', 'deprecated', ]; + /** * @param CompilerFile[] $files */ @@ -90,12 +89,12 @@ public function generate(string $namespace, string $path, string $indent, string * Build class. * * @param Definition $class - * @param string $indent - * @param string $banner + * @param string $indent + * @param string $banner * * @return string - *@throws Exception\RuntimeException * + * @throws Exception\RuntimeException */ protected function buildClass(Definition $class, string $indent, string $banner): string { @@ -209,7 +208,7 @@ protected function buildClass(Definition $class, string $indent, string $banner) * Build property. * * @param Property $property - * @param string $indent + * @param string $indent * * @return string */ @@ -239,7 +238,7 @@ protected function buildProperty(Property $property, string $indent): string /** * @param Constant $constant - * @param string $indent + * @param string $indent * * @return string */ @@ -256,8 +255,8 @@ protected function buildConstant(Constant $constant, string $indent): string /** * @param Method $method - * @param bool $isInterface - * @param string $indent + * @param bool $isInterface + * @param string $indent * * @return string */ @@ -285,13 +284,13 @@ protected function buildMethod(Method $method, bool $isInterface, string $indent } elseif (isset($parameter['data-type']) && 'array' === $parameter['data-type']) { $paramStr .= 'array '; } elseif (isset($parameter['data-type'])) { - if (in_array($parameter['data-type'], ['bool', 'boolean'])) { + if (\in_array($parameter['data-type'], ['bool', 'boolean'])) { $paramStr .= 'bool '; } elseif ('double' == $parameter['data-type']) { $paramStr .= 'float '; - } elseif (in_array($parameter['data-type'], ['int', 'uint', 'long', 'ulong', 'uchar'])) { + } elseif (\in_array($parameter['data-type'], ['int', 'uint', 'long', 'ulong', 'uchar'])) { $paramStr .= 'int '; - } elseif (in_array($parameter['data-type'], ['char', 'string'])) { + } elseif (\in_array($parameter['data-type'], ['char', 'string'])) { $paramStr .= 'string '; } } @@ -310,7 +309,7 @@ protected function buildMethod(Method $method, bool $isInterface, string $indent if ($method->hasReturnTypes()) { $supported = 0; - if (array_key_exists('object', $method->getReturnTypes())) { + if (\array_key_exists('object', $method->getReturnTypes())) { $return = key($method->getReturnClassTypes()); ++$supported; } @@ -335,7 +334,7 @@ protected function buildMethod(Method $method, bool $isInterface, string $indent ++$supported; } - if (array_key_exists('array', $method->getReturnTypes())) { + if (\array_key_exists('array', $method->getReturnTypes())) { $return = 'array'; ++$supported; } @@ -345,7 +344,7 @@ protected function buildMethod(Method $method, bool $isInterface, string $indent } // PHP doesn't support multiple return types (yet?) - if ($supported > 1 || array_key_exists('variable', $method->getReturnTypes())) { + if ($supported > 1 || \array_key_exists('variable', $method->getReturnTypes())) { $return = ''; } } elseif ($method->isVoid()) { @@ -376,9 +375,9 @@ protected function buildMethod(Method $method, bool $isInterface, string $indent * * @param array $parameter * - * @throws Exception\NotImplementedException - * * @return string + * + * @throws Exception\NotImplementedException */ protected function wrapPHPValue(array $parameter): string { diff --git a/Library/Stubs/MethodDocBlock.php b/Library/Stubs/MethodDocBlock.php index 3f29b84e9b..31722746cd 100644 --- a/Library/Stubs/MethodDocBlock.php +++ b/Library/Stubs/MethodDocBlock.php @@ -64,10 +64,10 @@ class MethodDocBlock extends DocBlock private Types $types; public function __construct( - Method $method, + Method $method, AliasManager $aliasManager, - string $indent = ' ', - ?Types $types = null + string $indent = ' ', + Types $types = null ) { parent::__construct($method->getDocBlock(), $indent); diff --git a/Library/SymbolTable.php b/Library/SymbolTable.php index 818d6f9b26..553a53a0af 100644 --- a/Library/SymbolTable.php +++ b/Library/SymbolTable.php @@ -17,7 +17,6 @@ use Zephir\Passes\LocalContextPass; use Zephir\Variable\Globals; use Zephir\Variable\Variable; -use function count; /** * A symbol table stores all the variables defined in a method, their data types and default values. @@ -94,7 +93,7 @@ public function setLocalContext(LocalContextPass $localContext): void /** * Check if a variable is declared in the current symbol table. * - * @param string $name + * @param string $name * @param CompilationContext|null $compilationContext * * @return bool @@ -174,7 +173,7 @@ public function addRawVariable(Variable $variable): Variable /** * Returns a variable in the symbol table. * - * @param $name + * @param $name * @param CompilationContext|null $compilationContext * * @return bool|Variable @@ -184,7 +183,7 @@ public function getVariable($name, CompilationContext $compilationContext = null /* Check if the variable already is referencing a branch */ $pos = strpos($name, Variable::BRANCH_MAGIC); if ($pos > -1) { - $branchId = (int) (substr($name, $pos + \strlen(Variable::BRANCH_MAGIC))); + $branchId = (int) substr($name, $pos + \strlen(Variable::BRANCH_MAGIC)); $name = substr($name, 0, $pos); } else { $compilationContext = $compilationContext ?: $this->compilationContext; @@ -225,9 +224,9 @@ public function getVariables() * @param CompilationContext $compilationContext * @param array $statement * - * @throws CompilerException - * * @return Variable + * + * @throws CompilerException */ public function getVariableForRead($name, CompilationContext $compilationContext = null, array $statement = null) { @@ -298,7 +297,7 @@ public function getVariableForRead($name, CompilationContext $compilationContext /** @var Branch[] $branches */ $branches = array_reverse($initBranches); - if (1 == count($branches)) { + if (1 == \count($branches)) { if (Branch::TYPE_CONDITIONAL_TRUE == $branches[0]->getType()) { if (true === $branches[0]->isUnreachable()) { throw new CompilerException('Initialization of variable "'.$name.'" depends on unreachable branch, consider initialize it at its declaration', $statement); @@ -348,7 +347,7 @@ public function getVariableForRead($name, CompilationContext $compilationContext * Variable was initialized in a sub-branch, and it's being used in a parent branch. */ $possibleBadAssignment = $currentBranch->getLevel() < $branches[0]->getLevel(); - if ($possibleBadAssignment && count($branches) === 1) { + if ($possibleBadAssignment && \count($branches) === 1) { /** * Variable is assigned just once, and it's assigned in a conditional branch */ @@ -402,8 +401,8 @@ public function getVariableForRead($name, CompilationContext $compilationContext * @param array $statement * * @return bool|\Zephir\Variable\Variable - *@throws CompilerException * + * @throws CompilerException */ public function getVariableForWrite($name, CompilationContext $compilationContext, array $statement = null) { @@ -454,9 +453,9 @@ public function getVariableForWrite($name, CompilationContext $compilationContex * Return a variable in the symbol table, it will be used for a mutating operation * This method implies mutation of one of the members of the variable but no the variables itself. * - * @param string $name + * @param string $name * @param CompilationContext $compilationContext - * @param array|null $statement + * @param array|null $statement * * @return Variable */ @@ -549,7 +548,7 @@ public function getTempVariable(string $type, CompilationContext $compilationCon /** * Creates a temporary variable to be used in a write operation. * - * @param string $type + * @param string $type * @param CompilationContext $context * @param mixed $init * @@ -587,7 +586,7 @@ public function getTempVariableForWrite(string $type, CompilationContext $contex * Creates a temporary variable to be used to point to a heap variable * These kind of variables MUST not be tracked by the Zephir memory manager. * - * @param $type + * @param $type * @param CompilationContext $context * @param bool $initNonReferenced * @@ -839,7 +838,7 @@ public function markTemporalVariablesIdle(CompilationContext $compilationContext $pos = strpos($variable->getName(), Variable::BRANCH_MAGIC); $otherBranchId = 1; if ($pos > -1) { - $otherBranchId = (int) (substr($variable->getName(), $pos + \strlen(Variable::BRANCH_MAGIC))); + $otherBranchId = (int) substr($variable->getName(), $pos + \strlen(Variable::BRANCH_MAGIC)); } if ($branchId == $otherBranchId) { $variable->setIdle(true); @@ -919,9 +918,10 @@ protected function registerTempVariable($type, $location, Variable $variable, Co /** * Reuse variables marked as idle after leave a branch. * - * @param string $type - * @param string $location + * @param string $type + * @param string $location * @param CompilationContext|null $compilationContext + * * @return Variable|null */ protected function reuseTempVariable(string $type, string $location, CompilationContext $compilationContext = null): ?Variable diff --git a/Library/Types/AbstractType.php b/Library/Types/AbstractType.php index 7c52906e15..76e6e63b49 100644 --- a/Library/Types/AbstractType.php +++ b/Library/Types/AbstractType.php @@ -13,7 +13,6 @@ namespace Zephir\Types; -use ReflectionException; use Zephir\Call; use Zephir\CompilationContext; use Zephir\CompiledExpression; @@ -32,16 +31,16 @@ abstract class AbstractType /** * Intercepts calls to built-in methods. * - * @param string $methodName - * @param object $caller + * @param string $methodName + * @param object $caller * @param CompilationContext $compilationContext - * @param Call $call - * @param array $expression + * @param Call $call + * @param array $expression * * @return bool|CompiledExpression * * @throws Exception - * @throws ReflectionException + * @throws \ReflectionException */ public function invokeMethod( $methodName, diff --git a/Library/Types/ArrayType.php b/Library/Types/ArrayType.php index 7ecbb04593..5d3b00d1b2 100644 --- a/Library/Types/ArrayType.php +++ b/Library/Types/ArrayType.php @@ -11,7 +11,6 @@ namespace Zephir\Types; -use ReflectionException; use Zephir\Call; use Zephir\CompilationContext; use Zephir\CompiledExpression; @@ -78,13 +77,14 @@ public function getTypeName(): string /** * Transforms calls to method "join" to function calls to "join". * - * @param object $caller + * @param object $caller * @param CompilationContext $compilationContext - * @param Call $call - * @param array $expression + * @param Call $call + * @param array $expression * * @return bool|CompiledExpression - * @throws ReflectionException + * + * @throws \ReflectionException * @throws Exception */ public function join($caller, CompilationContext $compilationContext, Call $call, array $expression) diff --git a/Library/Types/CharType.php b/Library/Types/CharType.php index 607a3bceb5..2233f73f6f 100644 --- a/Library/Types/CharType.php +++ b/Library/Types/CharType.php @@ -13,7 +13,6 @@ namespace Zephir\Types; -use ReflectionException; use Zephir\Call; use Zephir\CompilationContext; use Zephir\CompiledExpression; @@ -31,13 +30,14 @@ public function getTypeName(): string /** * Transforms calls to method "toHex" to sprintf('%X') call. * - * @param object $caller + * @param object $caller * @param CompilationContext $compilationContext - * @param Call $call - * @param array $expression + * @param Call $call + * @param array $expression * * @return bool|mixed|CompiledExpression - * @throws ReflectionException + * + * @throws \ReflectionException * @throws Exception */ public function toHex($caller, CompilationContext $compilationContext, Call $call, array $expression) diff --git a/Library/Types/Types.php b/Library/Types/Types.php index ecfcdbc7b3..4f7a95eb46 100644 --- a/Library/Types/Types.php +++ b/Library/Types/Types.php @@ -14,9 +14,6 @@ namespace Zephir\Types; use Zephir\Class\Method\Method; -use function array_key_exists; -use function count; -use function in_array; final class Types { @@ -55,9 +52,9 @@ public function getReturnTypeAnnotation(Method $method, array $returnTypes = nul $isProcessedReturnType = null !== $returnTypes; $returnTypes = $returnTypes ?? $method->getReturnTypes(); - $typesCount = count($returnTypes); + $typesCount = \count($returnTypes); - $isDynamic = in_array('var', array_keys($returnTypes)); + $isDynamic = \in_array('var', array_keys($returnTypes)); $isNullable = $this->isNullable($returnTypes); $isBool = $this->areReturnTypesBoolCompatible($returnTypes); @@ -275,9 +272,9 @@ private function isNumeric(array $types): bool */ private function isNullable(array $types): bool { - return (array_key_exists(self::T_NULL, $types) - || in_array(self::T_NULL, $types)) - && 1 !== count($types); + return (\array_key_exists(self::T_NULL, $types) + || \in_array(self::T_NULL, $types)) + && 1 !== \count($types); } /** @@ -305,7 +302,7 @@ private function areReturnTypesCompatible(array $types, array $allowedTypes, boo } foreach ($types as $type => $data) { - $areEquals = in_array($type, $allowedTypes); + $areEquals = \in_array($type, $allowedTypes); $result = isset($result) ? ($areEquals && $result) diff --git a/Library/Variable/Variable.php b/Library/Variable/Variable.php index fef290049e..8924fe6b71 100644 --- a/Library/Variable/Variable.php +++ b/Library/Variable/Variable.php @@ -13,7 +13,6 @@ namespace Zephir\Variable; -use ReflectionClass; use Zephir\Branch; use Zephir\BranchManager; use Zephir\Class\Definition\Definition; @@ -21,8 +20,6 @@ use Zephir\CompiledExpression; use Zephir\Exception\CompilerException; use Zephir\TypeAwareInterface; -use function in_array; -use function is_string; /** * This represents a variable in a symbol table @@ -102,7 +99,7 @@ class Variable implements TypeAwareInterface protected array $classTypes = []; - protected Definition|ReflectionClass|null $associatedClass = null; + protected Definition | \ReflectionClass | null $associatedClass = null; /** * Initialization skips. @@ -142,7 +139,7 @@ class Variable implements TypeAwareInterface public function __construct(protected string $type, protected string $name, protected ?Branch $branch = null) { $this->globalsManager = new Globals(); - $this->type = in_array($type, ['callable', 'object', 'resource'], true) ? 'variable' : $type; + $this->type = \in_array($type, ['callable', 'object', 'resource'], true) ? 'variable' : $type; } /** @@ -428,10 +425,10 @@ public function getOriginal(): array * * @param array|string $classTypes */ - public function setClassTypes(array|string $classTypes): void + public function setClassTypes(array | string $classTypes): void { - if (is_string($classTypes)) { - if (!in_array($classTypes, $this->classTypes)) { + if (\is_string($classTypes)) { + if (!\in_array($classTypes, $this->classTypes)) { $this->classTypes[] = $classTypes; } @@ -439,7 +436,7 @@ public function setClassTypes(array|string $classTypes): void } foreach ($classTypes as $classType) { - if (!in_array($classType, $this->classTypes)) { + if (!\in_array($classType, $this->classTypes)) { $this->classTypes[] = $classType; } } @@ -458,9 +455,9 @@ public function getClassTypes(): array /** * Sets the PHP class related to variable. * - * @param ReflectionClass|Definition $associatedClass + * @param \ReflectionClass|Definition $associatedClass */ - public function setAssociatedClass(ReflectionClass|Definition $associatedClass): void + public function setAssociatedClass(\ReflectionClass | Definition $associatedClass): void { $this->associatedClass = $associatedClass; } @@ -468,7 +465,7 @@ public function setAssociatedClass(ReflectionClass|Definition $associatedClass): /** * Returns the class related to the variable. */ - public function getAssociatedClass(): Definition|ReflectionClass|null + public function getAssociatedClass(): Definition | \ReflectionClass | null { return $this->associatedClass; } @@ -478,11 +475,11 @@ public function getAssociatedClass(): Definition|ReflectionClass|null * * @param array|string $types */ - public function setDynamicTypes(array|string $types): void + public function setDynamicTypes(array | string $types): void { unset($this->dynamicTypes['unknown']); - if (is_string($types)) { + if (\is_string($types)) { $types = [$types]; } @@ -510,9 +507,9 @@ public function getDynamicTypes(): array * * @return bool */ - public function hasAnyDynamicType(array|string $types): bool + public function hasAnyDynamicType(array | string $types): bool { - if (is_string($types)) { + if (\is_string($types)) { $types = [$types]; } @@ -712,7 +709,7 @@ public function getDefaultInitValue(): mixed */ public function separate(CompilationContext $compilationContext): void { - if (!in_array($this->getName(), [self::VAR_THIS_POINTER, self::VAR_RETURN_VALUE], true)) { + if (!\in_array($this->getName(), [self::VAR_THIS_POINTER, self::VAR_RETURN_VALUE], true)) { $compilationContext->codePrinter->output('ZEPHIR_SEPARATE('.$compilationContext->backend->getVariableCode($this).');'); } } @@ -955,7 +952,7 @@ public function observeOrNullifyVariant(CompilationContext $compilationContext): return; } - if (in_array($this->getName(), [self::VAR_THIS_POINTER, self::VAR_RETURN_VALUE], true)) { + if (\in_array($this->getName(), [self::VAR_THIS_POINTER, self::VAR_RETURN_VALUE], true)) { return; } diff --git a/Library/functions.php b/Library/functions.php index dbb29bf847..39755a2443 100644 --- a/Library/functions.php +++ b/Library/functions.php @@ -12,10 +12,6 @@ namespace Zephir; use Zephir\Exception\InvalidArgumentException; -use const INFO_GENERAL; -use const PHP_INT_SIZE; -use const PHP_OS; -use const PHP_ZTS; /** * Camelize a string. @@ -179,7 +175,7 @@ function file_put_contents_ex($content, $path) */ function is_windows() { - return 0 === stripos(PHP_OS, 'WIN'); + return 0 === stripos(\PHP_OS, 'WIN'); } /** @@ -189,12 +185,12 @@ function is_windows() */ function is_zts() { - if (\defined('PHP_ZTS') && PHP_ZTS === 1) { + if (\defined('PHP_ZTS') && \PHP_ZTS === 1) { return true; } ob_start(); - phpinfo(INFO_GENERAL); + phpinfo(\INFO_GENERAL); return (bool) preg_match('/Thread\s*Safety\s*enabled/i', strip_tags(ob_get_clean())); } @@ -207,12 +203,12 @@ function is_zts() function windows_release_dir() { if (is_zts()) { - if (PHP_INT_SIZE === 4) { + if (\PHP_INT_SIZE === 4) { // 32-bit version of PHP return 'ext\\Release_TS'; } - if (PHP_INT_SIZE === 8) { + if (\PHP_INT_SIZE === 8) { // 64-bit version of PHP return 'ext\\x64\\Release_TS'; } @@ -221,12 +217,12 @@ function windows_release_dir() return 'ext\\Release_TS'; } - if (PHP_INT_SIZE === 4) { + if (\PHP_INT_SIZE === 4) { // 32-bit version of PHP return 'ext\\Release'; } - if (PHP_INT_SIZE === 8) { + if (\PHP_INT_SIZE === 8) { // 64-bit version of PHP return 'ext\\x64\\Release'; } diff --git a/prototypes/apc.php b/prototypes/apc.php index d488269dcc..b378522b47 100644 --- a/prototypes/apc.php +++ b/prototypes/apc.php @@ -120,8 +120,8 @@ function apc_sma_info($limited = false) /** * @see https://www.php.net/manual/en/function.apc-store.php * - * @param $key - * @param $var + * @param $key + * @param $var * @param int $ttl */ function apc_store($key, $var, $ttl = 0) @@ -131,7 +131,7 @@ function apc_store($key, $var, $ttl = 0) /** * @see https://www.php.net/manual/en/function.apc-fetch.php * - * @param $key + * @param $key * @param null $success * * @return mixed @@ -152,7 +152,7 @@ function apc_delete($key) /** * @see https://www.php.net/manual/en/function.apc-define-constants.php * - * @param $key + * @param $key * @param array $constants * @param bool $case_sensitive */ @@ -163,8 +163,8 @@ function apc_define_constants($key, array $constants, $case_sensitive = true) /** * @see https://www.php.net/manual/en/function.apc-add.php * - * @param $key - * @param $var + * @param $key + * @param $var * @param int $ttl */ function apc_add($key, $var, $ttl = 0) @@ -174,7 +174,7 @@ function apc_add($key, $var, $ttl = 0) /** * @see https://www.php.net/manual/en/function.apc-compile-file.php * - * @param $filename + * @param $filename * @param bool $atomic */ function apc_compile_file($filename, $atomic = true) @@ -184,7 +184,7 @@ function apc_compile_file($filename, $atomic = true) /** * @see https://www.php.net/manual/en/function.apc-load-constants.php * - * @param $key + * @param $key * @param bool $case_sensitive */ function apc_load_constants($key, $case_sensitive = true) @@ -212,7 +212,7 @@ function apc_delete_file($keys) /** * @see https://www.php.net/manual/en/function.apc-inc.php * - * @param $key + * @param $key * @param int $step * @param null $success */ @@ -223,7 +223,7 @@ function apc_inc($key, $step = 1, &$success = null) /** * @see https://www.php.net/manual/en/function.apc-dec.php * - * @param $key + * @param $key * @param int $step * @param null $success */ @@ -255,9 +255,9 @@ function apc_bin_dump($files = null, $user_vars = null) /** * @see https://php.net/manual/en/function.apc-bin-dumpfile.php * - * @param $files - * @param $user_vars - * @param $filename + * @param $files + * @param $user_vars + * @param $filename * @param int $flags * @param null $context */ @@ -268,7 +268,7 @@ function apc_bin_dumpfile($files, $user_vars, $filename, $flags = 0, $context = /** * @see https://php.net/manual/en/function.apc-bin-load.php * - * @param $data + * @param $data * @param int $flags */ function apc_bin_load($data, $flags = 0) @@ -278,7 +278,7 @@ function apc_bin_load($data, $flags = 0) /** * @see https://php.net/manual/en/function.apc-bin-loadfile.php * - * @param $filename + * @param $filename * @param null $context * @param int $flags */ diff --git a/prototypes/gd.php b/prototypes/gd.php index 058bfbdf39..0492995137 100644 --- a/prototypes/gd.php +++ b/prototypes/gd.php @@ -60,7 +60,7 @@ function getimagesizefromstring($imagedata, array &$imageinfo) * * @see https://www.php.net/manual/en/function.image-type-to-extension.php * - * @param $imagetype + * @param $imagetype * @param bool $include_dot * * @return string diff --git a/tests/Extension/ArrayAccessTest.php b/tests/Extension/ArrayAccessTest.php index 97ea15ba81..737bc8d083 100644 --- a/tests/Extension/ArrayAccessTest.php +++ b/tests/Extension/ArrayAccessTest.php @@ -21,9 +21,9 @@ final class ArrayAccessTest extends TestCase 'key_a' => 'marcin', 'key_b' => 'paula', 3 => 'long value', - //3.14 => 'double value', // Not supported yet - //false => 'bool value', // Not supported yet - //null => 'null value', // Not supported yet + // 3.14 => 'double value', // Not supported yet + // false => 'bool value', // Not supported yet + // null => 'null value', // Not supported yet ]; public function testTest(): void diff --git a/tests/Extension/ExitDieTest.php b/tests/Extension/ExitDieTest.php index fb5896289f..91fe030cce 100644 --- a/tests/Extension/ExitDieTest.php +++ b/tests/Extension/ExitDieTest.php @@ -15,9 +15,6 @@ use PHPUnit\Framework\TestCase; -use function constant; -use function defined; - final class ExitDieTest extends TestCase { private string $phpBinary; @@ -27,9 +24,9 @@ final class ExitDieTest extends TestCase */ protected function setUp(): void { - $this->phpBinary = constant('PHP_BINARY'); + $this->phpBinary = \constant('PHP_BINARY'); /* If we use phpdbg, you need to add options -qrr */ - if (defined('PHP_SAPI') && 'phpdbg' == constant('PHP_SAPI')) { + if (\defined('PHP_SAPI') && 'phpdbg' == \constant('PHP_SAPI')) { $this->phpBinary .= ' -qrr'; } diff --git a/tests/Extension/FunctionExistsTest.php b/tests/Extension/FunctionExistsTest.php index 48c45b6df1..b5d633265b 100644 --- a/tests/Extension/FunctionExistsTest.php +++ b/tests/Extension/FunctionExistsTest.php @@ -27,6 +27,7 @@ protected function setUp(): void /** * @dataProvider providerInternalFunctions + * * @issue https://github.com/zephir-lang/zephir/issues/1547 * * @param string $func The internal (built-in) function name diff --git a/tests/Extension/Globals/EnvTest.php b/tests/Extension/Globals/EnvTest.php index e2f5b2582d..806341e3e2 100644 --- a/tests/Extension/Globals/EnvTest.php +++ b/tests/Extension/Globals/EnvTest.php @@ -22,7 +22,7 @@ protected function setUp(): void { parent::setUp(); - if (false === strpos(ini_get('variables_order'), 'E')) { + if (!str_contains(ini_get('variables_order'), 'E')) { $this->markTestSkipped( "variables_order ini directive does not contain 'E'. ". "Make sure you have set variables_order to 'EGPCS' in php.ini." diff --git a/tests/Extension/Integral/RegexDNATest.php b/tests/Extension/Integral/RegexDNATest.php index d95548fb3b..d2f09717a0 100644 --- a/tests/Extension/Integral/RegexDNATest.php +++ b/tests/Extension/Integral/RegexDNATest.php @@ -16,7 +16,6 @@ use PHPUnit\Framework\TestCase; use Stub\RegexDNA; -use function dirname; use function Zephir\is_windows; final class RegexDNATest extends TestCase @@ -30,12 +29,12 @@ public function testProcess(): void $test = new RegexDNA(); ob_start(); - $test->process(dirname(__DIR__).'/../fixtures/regexdna/input.txt'); + $test->process(\dirname(__DIR__).'/../fixtures/regexdna/input.txt'); $content = ob_get_clean(); $this->assertSame( $content, - file_get_contents(dirname(__DIR__).'/../fixtures/regexdna/output.txt') + file_get_contents(\dirname(__DIR__).'/../fixtures/regexdna/output.txt') ); } } diff --git a/tests/Extension/Issue1134Test.php b/tests/Extension/Issue1134Test.php index bad9995745..48e9be1c0f 100644 --- a/tests/Extension/Issue1134Test.php +++ b/tests/Extension/Issue1134Test.php @@ -14,8 +14,6 @@ namespace Extension; use PHPUnit\Framework\TestCase; -use ReflectionClass; -use ReflectionException; use Stub\Issue1134; /** @@ -24,11 +22,11 @@ final class Issue1134Test extends TestCase { /** - * @throws ReflectionException + * @throws \ReflectionException */ public function testIssue914ReflectionParamDefaultValueShouldReturnTrue(): void { - $ref = new ReflectionClass(Issue1134::class); + $ref = new \ReflectionClass(Issue1134::class); $constructor = $ref->getConstructor(); $params = $constructor->getParameters(); diff --git a/tests/Extension/MCallTest.php b/tests/Extension/MCallTest.php index f6e48fa431..d209487b01 100644 --- a/tests/Extension/MCallTest.php +++ b/tests/Extension/MCallTest.php @@ -14,8 +14,6 @@ namespace Extension; use PHPUnit\Framework\TestCase; -use ReflectionClass; -use ReflectionParameter; use Stub\Mcall; use Stub\Oo\Param; @@ -132,7 +130,7 @@ public function testObjectParamCastStdClass(): void $this->assertNumberOfParameters(1); $this->assertNumberOfRequiredParameters(1); - $this->assertSame(\StdClass::class, $this->getMethodFirstParameter()->getType()->getName()); + $this->assertSame(\stdClass::class, $this->getMethodFirstParameter()->getType()->getName()); $this->assertInstanceOf(\stdClass::class, $this->test->testObjectParamCastStdClass(new \stdClass())); } @@ -145,7 +143,7 @@ public function testObjectParamCastOoParam(): void $this->assertInstanceOf(Param::class, $this->test->testObjectParamCastOoParam(new Param())); } - protected function getMethodFirstParameter(): ReflectionParameter + protected function getMethodFirstParameter(): \ReflectionParameter { $methodInfo = $this->reflection->getMethod($this->getName()); $parameters = $methodInfo->getParameters(); @@ -154,12 +152,12 @@ protected function getMethodFirstParameter(): ReflectionParameter } /** - * @return mixed|ReflectionClass + * @return mixed|\ReflectionClass */ private function getReflection() { if (null === $this->reflection) { - return $this->reflection = new ReflectionClass(Mcall::class); + return $this->reflection = new \ReflectionClass(Mcall::class); } return $this->reflection; diff --git a/tests/Extension/NewInstanceOperatorTest.php b/tests/Extension/NewInstanceOperatorTest.php index 818d44849f..f35793aa3d 100644 --- a/tests/Extension/NewInstanceOperatorTest.php +++ b/tests/Extension/NewInstanceOperatorTest.php @@ -38,8 +38,7 @@ protected function tearDown(): void public function autoload(string $className): void { - if (version_compare(PHP_VERSION, '8.1.0', '>=') && - version_compare(PHP_VERSION, '8.3.0', '<')) { + if (version_compare(PHP_VERSION, '8.1.0', '>=')) { try { if (isset($this->autoloadMap[$className])) { include $this->autoloadMap[$className]; diff --git a/tests/Extension/Oo/ExtendClassTest.php b/tests/Extension/Oo/ExtendClassTest.php index 1586003099..a868477908 100644 --- a/tests/Extension/Oo/ExtendClassTest.php +++ b/tests/Extension/Oo/ExtendClassTest.php @@ -13,7 +13,6 @@ namespace Extension\Oo; -use PDO; use PHPUnit\Framework\TestCase; use Stub\Integration\Psr\Http\Message\MessageInterfaceEx; use Stub\Oo\ConcreteStatic; @@ -27,13 +26,13 @@ public function testPDOExtending(): void $this->markTestSkipped('The PDO extension is not loaded'); } - $this->assertSame(PDO::getAvailableDrivers(), ExtendPdoClass::getAvailableDrivers()); - $this->assertSame(PDO::PARAM_STR, ExtendPdoClass::PARAM_STR); + $this->assertSame(\PDO::getAvailableDrivers(), ExtendPdoClass::getAvailableDrivers()); + $this->assertSame(\PDO::PARAM_STR, ExtendPdoClass::PARAM_STR); } public function testPDOStatementExtending(): void { - $pdo = new ExtendPdoClass('sqlite::memory:', '', '', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); + $pdo = new ExtendPdoClass('sqlite::memory:', '', '', [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]); $stmt = $pdo->prepare('SELECT CURRENT_TIME'); $this->assertInstanceof('Stub\\PdoStatement', $stmt); diff --git a/tests/Extension/Oo/Scopes/PrivateScopeTest.php b/tests/Extension/Oo/Scopes/PrivateScopeTest.php index 4c593fb5ad..b240cbb9f5 100644 --- a/tests/Extension/Oo/Scopes/PrivateScopeTest.php +++ b/tests/Extension/Oo/Scopes/PrivateScopeTest.php @@ -13,16 +13,9 @@ namespace Extension\Oo\Scopes; -use Error; use PHPUnit\Framework\Error\Notice; use PHPUnit\Framework\TestCase; use Stub\Oo\Scopes\PrivateScopeTester; -use TestScopeExtending; -use TestScopeExtendingMagic; -use TestScopePhp; -use TestScopePhpMagic; -use TestScopePhpMagicExtending; -use UserExample; final class PrivateScopeTest extends TestCase { @@ -36,13 +29,13 @@ public function testShouldCallPrivateMethod(): void */ public function testShouldNotSetPrivatePropertyObjPhp(): void { - $this->expectException(Error::class); + $this->expectException(\Error::class); $this->expectExceptionMessage( 'Cannot access private property TestScopePhp::$privateProperty' ); $tester = new PrivateScopeTester(); - $tester->setPropertyObj(new TestScopePhp(), 'privateProperty', 'test'); + $tester->setPropertyObj(new \TestScopePhp(), 'privateProperty', 'test'); } /** @@ -50,13 +43,13 @@ public function testShouldNotSetPrivatePropertyObjPhp(): void */ public function testShouldNotSetPrivatePropertyNewPhp(): void { - $this->expectException(Error::class); + $this->expectException(\Error::class); $this->expectExceptionMessage( 'Cannot access private property TestScopePhp::$privateProperty' ); $tester = new PrivateScopeTester(); - $tester->setPropertyNew(TestScopePhp::class, 'privateProperty', 'test'); + $tester->setPropertyNew(\TestScopePhp::class, 'privateProperty', 'test'); } /** @@ -64,13 +57,13 @@ public function testShouldNotSetPrivatePropertyNewPhp(): void */ public function testShouldNotSetPrivatePropertyObjInternal(): void { - $this->expectException(Error::class); + $this->expectException(\Error::class); $this->expectExceptionMessage( 'Cannot access private property TestScopeExtending::$privateProperty' ); $tester = new PrivateScopeTester(); - $tester->setPropertyObj(new TestScopeExtending(), 'privateProperty', 'test'); + $tester->setPropertyObj(new \TestScopeExtending(), 'privateProperty', 'test'); } /** @@ -78,13 +71,13 @@ public function testShouldNotSetPrivatePropertyObjInternal(): void */ public function testShouldNotSetPrivatePropertyNewInternal(): void { - $this->expectException(Error::class); + $this->expectException(\Error::class); $this->expectExceptionMessage( 'Cannot access private property TestScopeExtending::$privateProperty' ); $tester = new PrivateScopeTester(); - $tester->setPropertyNew(TestScopeExtending::class, 'privateProperty', 'test'); + $tester->setPropertyNew(\TestScopeExtending::class, 'privateProperty', 'test'); } /** @@ -92,7 +85,7 @@ public function testShouldNotSetPrivatePropertyNewInternal(): void */ public function testShouldSetPrivatePropertyObjPhp(): void { - $object = new TestScopePhpMagic(); + $object = new \TestScopePhpMagic(); $tester = new PrivateScopeTester(); $actual = $tester->setPropertyObj($object, 'privateProperty', 'test'); @@ -106,7 +99,7 @@ public function testShouldSetPrivatePropertyObjPhp(): void public function testShouldSetPrivatePropertyNewPhp(): void { $tester = new PrivateScopeTester(); - $obj = $tester->setPropertyNew(TestScopePhpMagic::class, 'privateProperty', 'test'); + $obj = $tester->setPropertyNew(\TestScopePhpMagic::class, 'privateProperty', 'test'); $this->assertEquals('test', $obj->privateProperty); $this->assertEquals(1, $obj->setCount); @@ -118,7 +111,7 @@ public function testShouldSetPrivatePropertyNewPhp(): void public function testShouldSetPrivatePropertyObjInternal(): void { $tester = new PrivateScopeTester(); - $object = new TestScopeExtendingMagic(); + $object = new \TestScopeExtendingMagic(); $actual = $tester->setPropertyObj($object, 'privateProperty', 'test'); $this->assertEquals('test', $actual); @@ -131,7 +124,7 @@ public function testShouldSetPrivatePropertyObjInternal(): void public function testShouldSetPrivatePropertyNewInternal(): void { $tester = new PrivateScopeTester(); - $obj = $tester->setPropertyNew(TestScopeExtendingMagic::class, 'privateProperty', 'test'); + $obj = $tester->setPropertyNew(\TestScopeExtendingMagic::class, 'privateProperty', 'test'); $this->assertEquals('test', $obj->privateProperty); $this->assertEquals(1, $obj->setCount); @@ -142,12 +135,12 @@ public function testShouldSetPrivatePropertyNewInternal(): void */ public function testShouldNotSetPrivatePropertyViaThis(): void { - $this->expectException(Error::class); + $this->expectException(\Error::class); $this->expectExceptionMessage( 'Cannot access private property TestScopeExtending::$privateProperty' ); - $obj = new TestScopeExtending(); + $obj = new \TestScopeExtending(); $obj->setProperty('privateProperty', 'test'); } @@ -156,7 +149,7 @@ public function testShouldNotSetPrivatePropertyViaThis(): void */ public function testShouldSetPrivatePropertyViaThis(): void { - $obj = new TestScopeExtending(); + $obj = new \TestScopeExtending(); $obj->setProperty('privateProperty2', 'test'); $this->assertEquals('test', $obj->getPrivateProperty2()); @@ -167,12 +160,12 @@ public function testShouldSetPrivatePropertyViaThis(): void */ public function testShouldNotSetPrivatePropertyExtendedMagicObjInternal(): void { - $this->expectException(Error::class); + $this->expectException(\Error::class); $this->expectExceptionMessage( 'Cannot access private property TestScopeExtendingMagic::$privateProperty2' ); - $object = new TestScopeExtendingMagic(); + $object = new \TestScopeExtendingMagic(); $tester = new PrivateScopeTester(); $this->assertEquals('private', $object->getPrivateProperty2()); @@ -184,14 +177,14 @@ public function testShouldNotSetPrivatePropertyExtendedMagicObjInternal(): void */ public function testShouldNotSetPrivatePropertyExtendedMagicNewInternal(): void { - $this->expectException(Error::class); + $this->expectException(\Error::class); $this->expectExceptionMessage( 'Cannot access private property TestScopeExtendingMagic::$privateProperty2' ); $tester = new PrivateScopeTester(); $tester->setPropertyNew( - TestScopeExtendingMagic::class, + \TestScopeExtendingMagic::class, 'privateProperty2', 'CHANGED' ); @@ -208,13 +201,13 @@ public function testShouldNotSetPrivatePropertyExtendedMagicObjPhp(): void 'Undefined property: TestScopePhpMagicExtending::$privateProperty2' ); } else { - $this->expectException(Error::class); + $this->expectException(\Error::class); $this->expectExceptionMessage( 'Cannot access private property TestScopePhpMagicExtending::$privateProperty2' ); } - $obj = new TestScopePhpMagicExtending(); + $obj = new \TestScopePhpMagicExtending(); $tester = new PrivateScopeTester(); $tester->setPropertyObj($obj, 'privateProperty2', 'test'); @@ -225,14 +218,14 @@ public function testShouldNotSetPrivatePropertyExtendedMagicObjPhp(): void */ public function testShouldNotSetPrivatePropertyExtendedMagicNewPhp(): void { - $this->expectException(Error::class); + $this->expectException(\Error::class); $this->expectExceptionMessage( 'Cannot access private property TestScopePhpMagicExtending::$privateProperty2' ); $tester = new PrivateScopeTester(); $tester->setPropertyNew( - TestScopePhpMagicExtending::class, + \TestScopePhpMagicExtending::class, 'privateProperty2', 'CHANGED' ); @@ -244,7 +237,7 @@ public function testShouldNotSetPrivatePropertyExtendedMagicNewPhp(): void public function testShouldNotGetObjectVarsPrivatePropertyObjPhp(): void { $tester = new PrivateScopeTester(); - $object = new TestScopePhp(); + $object = new \TestScopePhp(); $objectVars = $tester->getObjVars($object); $this->assertArrayNotHasKey('privateProperty', $objectVars); @@ -256,7 +249,7 @@ public function testShouldNotGetObjectVarsPrivatePropertyObjPhp(): void public function testShouldNotGetObjectVarsPrivatePropertyNewPhp(): void { $tester = new PrivateScopeTester(); - $objectVars = $tester->getNewVars(TestScopePhp::class); + $objectVars = $tester->getNewVars(\TestScopePhp::class); $this->assertArrayNotHasKey('privateProperty', $objectVars); } @@ -267,7 +260,7 @@ public function testShouldNotGetObjectVarsPrivatePropertyNewPhp(): void public function testShouldNotGetObjectVarsPrivatePropertyObjInternal(): void { $tester = new PrivateScopeTester(); - $object = new TestScopeExtending(); + $object = new \TestScopeExtending(); $objectVars = $tester->getObjVars($object); $this->assertArrayNotHasKey('privateProperty', $objectVars); @@ -279,7 +272,7 @@ public function testShouldNotGetObjectVarsPrivatePropertyObjInternal(): void public function testShouldNotGetObjectVarsPrivatePropertyNewInternal(): void { $tester = new PrivateScopeTester(); - $objectVars = $tester->getNewVars(TestScopeExtending::class); + $objectVars = $tester->getNewVars(\TestScopeExtending::class); $this->assertArrayNotHasKey('privateProperty', $objectVars); } @@ -289,7 +282,7 @@ public function testShouldNotGetObjectVarsPrivatePropertyNewInternal(): void */ public function testShouldGetAndSetPrivatePropertyUsingParentGetterAndSetter(): void { - $tester = new UserExample(); + $tester = new \UserExample(); $tester->setPrivateVariable('test'); $this->assertEquals('test', $tester->getPrivateVariable()); diff --git a/tests/Extension/Optimizers/IsPhpVersionTest.php b/tests/Extension/Optimizers/IsPhpVersionTest.php index 2cb88d0090..4313ea71b0 100644 --- a/tests/Extension/Optimizers/IsPhpVersionTest.php +++ b/tests/Extension/Optimizers/IsPhpVersionTest.php @@ -11,10 +11,8 @@ namespace Extension\Optimizers; -use Exception; use PHPUnit\Framework\TestCase; use Stub\Issue1404; -use Throwable; /** * Extension\Optimizers\IsPhpVersionTest. @@ -61,7 +59,7 @@ public function phpVersionProvider(): array * @param mixed $version * @param mixed $expected * - * @throws Exception + * @throws \Exception */ public function testOptimizer($version, $expected): void { @@ -72,7 +70,7 @@ public function testOptimizer($version, $expected): void public function testOptimizerExceptionLLU(): void { - $this->expectException(Exception::class); + $this->expectException(\Exception::class); $this->expectExceptionMessage('Could not parse PHP version'); $this->isPhpVersion(92233720368547758079); @@ -80,7 +78,7 @@ public function testOptimizerExceptionLLU(): void public function testOptimizerExceptionNegativeNumber(): void { - $this->expectException(Exception::class); + $this->expectException(\Exception::class); $this->expectExceptionMessage('Could not parse PHP version'); $this->isPhpVersion(-7); @@ -88,7 +86,7 @@ public function testOptimizerExceptionNegativeNumber(): void public function testOptimizerExceptionEmpty(): void { - $this->expectException(Exception::class); + $this->expectException(\Exception::class); $this->expectExceptionMessage('Could not parse PHP version'); /** @@ -151,7 +149,7 @@ public function releaseVersionProvider(): array * @param mixed $testName * @param mixed $version * - * @throws Exception + * @throws \Exception */ public function testIsPhpVersionVersionUsing701XX($testName, $version): void { @@ -178,7 +176,7 @@ public function minorVersionProvider(): array * @param mixed $testName * @param mixed $version * - * @throws Exception + * @throws \Exception */ public function testIsPhpVersionVersionUsing70X00($testName, $version): void { @@ -213,11 +211,11 @@ public function testZephirUsingString50600(): void } /** - * @param Throwable $error + * @param \Throwable $error * - * @throws Throwable + * @throws \Throwable */ - protected function onNotSuccessfulTest(Throwable $error): void + protected function onNotSuccessfulTest(\Throwable $error): void { $phpVer = sprintf( 'PHP_VERSION_ID:%d(%d.%d.%d)', @@ -241,13 +239,13 @@ protected function onNotSuccessfulTest(Throwable $error): void * * @return bool * - * @throws Exception + * @throws \Exception */ private function isPhpVersion($version): bool { preg_match('/^(?\d+)(?:\.(?!?\d+))?(?:\.(?!?\d+))?(?:[^Ee0-9.]+.*)?$/', $version, $matches); if (!\count($matches)) { - throw new Exception('Could not parse PHP version'); + throw new \Exception('Could not parse PHP version'); } $minorVersion = 0; diff --git a/tests/Extension/Properties/StaticPublicPropertiesTest.php b/tests/Extension/Properties/StaticPublicPropertiesTest.php index 352890bae8..95ecc6cb60 100644 --- a/tests/Extension/Properties/StaticPublicPropertiesTest.php +++ b/tests/Extension/Properties/StaticPublicPropertiesTest.php @@ -49,9 +49,9 @@ public function testIssues2020(): void $this->assertEquals(-1, StaticPublicProperties::$someSub); // PHP Notice: A non well formed numeric value encountered - //\Stub\Properties\StaticPublicProperties::testAddAndSub2(); - //$this->assertEquals(2, \Stub\Properties\StaticPublicProperties::$someAdd); - //$this->assertEquals(-2, \Stub\Properties\StaticPublicProperties::$someSub); + // \Stub\Properties\StaticPublicProperties::testAddAndSub2(); + // $this->assertEquals(2, \Stub\Properties\StaticPublicProperties::$someAdd); + // $this->assertEquals(-2, \Stub\Properties\StaticPublicProperties::$someSub); StaticPublicProperties::testAddAndSub3(); $this->assertEquals(2, StaticPublicProperties::$someAdd); diff --git a/tests/Extension/ReflectionTest.php b/tests/Extension/ReflectionTest.php index 15da5ed41e..fad207f0fb 100644 --- a/tests/Extension/ReflectionTest.php +++ b/tests/Extension/ReflectionTest.php @@ -14,9 +14,6 @@ namespace Extension; use PHPUnit\Framework\TestCase; -use ReflectionClass; -use ReflectionFunction; -use ReflectionParameter; use Stub\Reflection as StubReflection; final class ReflectionTest extends TestCase @@ -25,14 +22,14 @@ public function testMethods(): void { $class = new StubReflection(); - $this->assertInstanceOf(ReflectionClass::class, $class->getReflectionClass()); - $this->assertInstanceOf(ReflectionFunction::class, $class->getReflectionFunction()); + $this->assertInstanceOf(\ReflectionClass::class, $class->getReflectionClass()); + $this->assertInstanceOf(\ReflectionFunction::class, $class->getReflectionFunction()); $this->assertNull($class->getReflectionParameter()); - $class->setReflectionParameter(new ReflectionParameter(function ($test) { + $class->setReflectionParameter(new \ReflectionParameter(function ($test) { return 1; }, 0)); - $this->assertInstanceOf(ReflectionParameter::class, $class->getReflectionParameter()); + $this->assertInstanceOf(\ReflectionParameter::class, $class->getReflectionParameter()); } } diff --git a/tests/Extension/RequiresTest.php b/tests/Extension/RequiresTest.php index 99bd7ad134..099e0b32a3 100644 --- a/tests/Extension/RequiresTest.php +++ b/tests/Extension/RequiresTest.php @@ -16,8 +16,6 @@ use PHPUnit\Framework\TestCase; use Stub\Requires; -use function defined; - final class RequiresTest extends TestCase { private Requires $test; @@ -34,9 +32,9 @@ public function testRequireExternal1(): void $this->test->requireExternal1(__DIR__.'/../fixtures/require-me-1.php') ); - $this->assertFalse(defined('REQUIRE_ME')); + $this->assertFalse(\defined('REQUIRE_ME')); $this->test->requireExternal1(__DIR__.'/../fixtures/require-me-2.php'); - $this->assertTrue(defined('REQUIRE_ME')); + $this->assertTrue(\defined('REQUIRE_ME')); } /** @@ -88,10 +86,10 @@ public function testRequireOnce(): void $this->test->requireOnce(__DIR__.'/../fixtures/require-me-before-once.php') ); - $this->assertFalse(defined('REQUIRE_ONCE_ME')); + $this->assertFalse(\defined('REQUIRE_ONCE_ME')); $this->test->requireOnce(__DIR__.'/../fixtures/require-me-once.php'); - $this->assertTrue(defined('REQUIRE_ONCE_ME')); + $this->assertTrue(\defined('REQUIRE_ONCE_ME')); $this->test->requireOnce(__DIR__.'/../fixtures/require-me-once.php'); - $this->assertTrue(defined('REQUIRE_ONCE_ME')); + $this->assertTrue(\defined('REQUIRE_ONCE_ME')); } } diff --git a/tests/Extension/TypeHinting/AbstractTest.php b/tests/Extension/TypeHinting/AbstractTest.php index aa782f1f10..8db2cbc3c1 100644 --- a/tests/Extension/TypeHinting/AbstractTest.php +++ b/tests/Extension/TypeHinting/AbstractTest.php @@ -14,7 +14,6 @@ namespace Extension\TypeHinting; use PHPUnit\Framework\TestCase; -use TestConcreteClass; final class AbstractTest extends TestCase { @@ -23,7 +22,7 @@ final class AbstractTest extends TestCase */ public function testShouldCreateCompatibleChildClassUsingTypeHintedParams(): void { - $childClass = new TestConcreteClass(); + $childClass = new \TestConcreteClass(); $this->assertEquals( [[1667], '/', true, null], @@ -41,7 +40,7 @@ public function testShouldCreateCompatibleChildClassUsingTypeHintedParams(): voi */ public function testShouldCreateCompatibleChildClassWithMultipleReturnTypesHint(): void { - $childClass = new TestConcreteClass(); + $childClass = new \TestConcreteClass(); $this->assertEquals('TestConcreteClass::returnOneOfScalar', $childClass->returnOneOfScalar()); } @@ -50,7 +49,7 @@ public function testShouldCreateCompatibleChildClassWithMultipleReturnTypesHint( */ public function testShouldCreateCompatibleChildClassWithScalarType(): void { - $childClass = new TestConcreteClass(); + $childClass = new \TestConcreteClass(); $this->assertEquals(1, $childClass->returnInt()); $this->assertEquals(1, $childClass->returnUint()); diff --git a/tests/Extension/Types/MixedTypeTest.php b/tests/Extension/Types/MixedTypeTest.php index 162edba89c..f544f56d84 100644 --- a/tests/Extension/Types/MixedTypeTest.php +++ b/tests/Extension/Types/MixedTypeTest.php @@ -22,7 +22,7 @@ public function testReturnsOfMixedType(): void { $returns = new MixedType(); - $this->assertEquals((new \stdClass()), $returns->returnMixedObject()); + $this->assertEquals(new \stdClass(), $returns->returnMixedObject()); $this->assertSame([], $returns->returnMixedArray()); $this->assertSame('mixed string', $returns->returnMixedString()); $this->assertSame(1, $returns->returnMixedInt()); @@ -38,16 +38,16 @@ public function testReturnsOfMixedType(): void $this->assertNotNull($returns->returnMixedBool()); $this->assertNull($returns->returnMixedNull()); - $this->assertEquals((new \stdClass()), $returns->returnMixed74()); + $this->assertEquals(new \stdClass(), $returns->returnMixed74()); $this->assertSame('string', $returns->returnMixed74(true)); - $this->assertEquals((new \stdClass()), $returns->returnMixed74(false)); + $this->assertEquals(new \stdClass(), $returns->returnMixed74(false)); } public function testParamsOfMixedType(): void { $returns = new MixedType(); - $this->assertEquals((new \stdClass()), $returns->paramMixed((new \stdClass()))); + $this->assertEquals(new \stdClass(), $returns->paramMixed(new \stdClass())); $this->assertSame([], $returns->paramMixed([])); $this->assertSame('mixed string', $returns->paramMixed('mixed string')); $this->assertSame(1, $returns->paramMixed(1)); @@ -55,14 +55,14 @@ public function testParamsOfMixedType(): void $this->assertTrue($returns->paramMixed(true)); $this->assertNull($returns->paramMixed(null)); - $this->assertEquals([(new \stdClass()), []], $returns->paramMixedTwo((new \stdClass()), [])); + $this->assertEquals([new \stdClass(), []], $returns->paramMixedTwo(new \stdClass(), [])); $this->assertSame([[], 'mixed string'], $returns->paramMixedTwo([], 'mixed string')); $this->assertSame([1, 3.14], $returns->paramMixedTwo(1, 3.14)); $this->assertSame([3.14, true], $returns->paramMixedTwo(3.14, true)); $this->assertSame([true, null], $returns->paramMixedTwo(true, null)); $this->assertSame([null, null], $returns->paramMixedTwo(null, null)); - $this->assertEquals([1337, 'object', (new \stdClass())], $returns->paramMixedWithMulti(1337, 'object', (new \stdClass()))); + $this->assertEquals([1337, 'object', new \stdClass()], $returns->paramMixedWithMulti(1337, 'object', new \stdClass())); $this->assertSame([1337, 'array', []], $returns->paramMixedWithMulti(1337, 'array', [])); $this->assertSame([1337, 'string', 'mixed string'], $returns->paramMixedWithMulti(1337, 'string', 'mixed string')); $this->assertSame([1337, 'int', 123], $returns->paramMixedWithMulti(1337, 'int', 123)); @@ -75,7 +75,7 @@ public function testParamsAndReturnsOfMixedType(): void { $returns = new MixedType(); - $this->assertEquals((new \stdClass()), $returns->paramAndReturnMixed((new \stdClass()))); + $this->assertEquals(new \stdClass(), $returns->paramAndReturnMixed(new \stdClass())); $this->assertSame([], $returns->paramAndReturnMixed([])); $this->assertSame('mixed string', $returns->paramAndReturnMixed('mixed string')); $this->assertSame(1, $returns->paramAndReturnMixed(1)); diff --git a/tests/Extension/Types/ObjTypeTest.php b/tests/Extension/Types/ObjTypeTest.php index cf3539fdf3..e77883d5ad 100644 --- a/tests/Extension/Types/ObjTypeTest.php +++ b/tests/Extension/Types/ObjTypeTest.php @@ -14,7 +14,6 @@ namespace Extension\Types; use PHPUnit\Framework\TestCase; -use stdClass; use Stub\Types\Obj; final class ObjTypeTest extends TestCase @@ -24,7 +23,7 @@ public function testIntFalse(): void $class = new Obj(); $this->assertNull($class->nullableObjectReturnNull()); - $this->assertInstanceOf(stdClass::class, $class->nullableObjectReturnObj()); - $this->assertInstanceOf(stdClass::class, $class->objectReturn()); + $this->assertInstanceOf(\stdClass::class, $class->nullableObjectReturnObj()); + $this->assertInstanceOf(\stdClass::class, $class->objectReturn()); } } diff --git a/tests/Extension/UnsetTest.php b/tests/Extension/UnsetTest.php index f448537875..6f8ed957b5 100644 --- a/tests/Extension/UnsetTest.php +++ b/tests/Extension/UnsetTest.php @@ -49,7 +49,7 @@ public function xtestUnsetValueFromProperty(): void public function xtestStdClassUnset(): void { - $equalsStdClass = new \StdClass(); + $equalsStdClass = new \stdClass(); $equalsStdClass->property1 = 12345; $equalsStdClass->property3 = 12345; diff --git a/tests/Zephir/CompilerFile/CheckDependenciesTest.php b/tests/Zephir/CompilerFile/CheckDependenciesTest.php index cf88d15bda..acf9e52d43 100644 --- a/tests/Zephir/CompilerFile/CheckDependenciesTest.php +++ b/tests/Zephir/CompilerFile/CheckDependenciesTest.php @@ -15,7 +15,6 @@ use PHPUnit\Framework\TestCase; use Psr\Log\Test\TestLogger; -use ReflectionException; use Zephir\AliasManager; use Zephir\Backend\Backend; use Zephir\Compiler; @@ -29,7 +28,7 @@ final class CheckDependenciesTest extends TestCase { /** - * @throws ReflectionException + * @throws \ReflectionException */ public function testExtendsClassThatDoesNotExist(): void { diff --git a/tests/Zephir/CompilerFile/CheckPathSeparatorTest.php b/tests/Zephir/CompilerFile/CheckPathSeparatorTest.php index c5dd8fc521..d3c113e3a8 100644 --- a/tests/Zephir/CompilerFile/CheckPathSeparatorTest.php +++ b/tests/Zephir/CompilerFile/CheckPathSeparatorTest.php @@ -22,6 +22,6 @@ public function testExtendsClassThatDoesNotExist(): void $configM4Path = realpath(__DIR__.'/../../../ext/config.m4'); $configM4Contents = file_get_contents($configM4Path); - $this->assertTrue(strpos($configM4Contents, 'stub/oo/abstractstatic.zep.c') !== false); + $this->assertTrue(str_contains($configM4Contents, 'stub/oo/abstractstatic.zep.c')); } } diff --git a/tests/Zephir/ConfigTest.php b/tests/Zephir/ConfigTest.php index e7debd114c..a434673bb1 100644 --- a/tests/Zephir/ConfigTest.php +++ b/tests/Zephir/ConfigTest.php @@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase; use Zephir\Config; + use function Zephir\is_windows; final class ConfigTest extends TestCase diff --git a/tests/Zephir/Stubs/GeneratorTest.php b/tests/Zephir/Stubs/GeneratorTest.php index e607da7317..efd88defe2 100644 --- a/tests/Zephir/Stubs/GeneratorTest.php +++ b/tests/Zephir/Stubs/GeneratorTest.php @@ -14,14 +14,14 @@ namespace Zephir\Test\Stubs; use PHPUnit\Framework\TestCase; -use ReflectionException; use Zephir\AliasManager; -use Zephir\Class\Property; use Zephir\Class\Constant; use Zephir\Class\Definition\Definition; -use Zephir\Class\Method\Parameters; use Zephir\Class\Method\Method; +use Zephir\Class\Method\Parameters; +use Zephir\Class\Property; use Zephir\Stubs\Generator; + use function Zephir\is_windows; class GeneratorTest extends TestCase @@ -47,7 +47,7 @@ protected function setUp(): void * * @return mixed * - * @throws ReflectionException + * @throws \ReflectionException */ private function getMethod(string $name) { @@ -238,14 +238,15 @@ public function propertyProvider(): array /** * @dataProvider propertyProvider + * * @covers \Zephir\Stubs\Generator::buildProperty * * @param array $visibility * @param string $type - * @param $value + * @param $value * @param string $expected * - * @throws ReflectionException + * @throws \ReflectionException */ public function testShouldBuildProperty(array $visibility, string $type, $value, string $expected): void { @@ -330,10 +331,10 @@ public function constantProvider(): array * @dataProvider constantProvider * * @param string $type - * @param $value + * @param $value * @param string $expected * - * @throws ReflectionException + * @throws \ReflectionException */ public function testShouldBuildConstant(string $type, $value, string $expected): void { diff --git a/tests/Zephir/Stubs/MethodDocBlockTest.php b/tests/Zephir/Stubs/MethodDocBlockTest.php index 2a396a7b32..794b68f90b 100644 --- a/tests/Zephir/Stubs/MethodDocBlockTest.php +++ b/tests/Zephir/Stubs/MethodDocBlockTest.php @@ -16,8 +16,8 @@ use PHPUnit\Framework\TestCase; use Zephir\AliasManager; use Zephir\Class\Definition\Definition; -use Zephir\Class\Method\Parameters; use Zephir\Class\Method\Method; +use Zephir\Class\Method\Parameters; use Zephir\StatementsBlock; use Zephir\Stubs\MethodDocBlock; @@ -45,14 +45,14 @@ public function prepareMethod(array $params): MethodDocBlock /** * ClassMethod constructor. * - * @param Definition $classDefinition - * @param array $visibility - * @param string $name - * @param Parameters|null $parameters - * @param StatementsBlock|null $statements - * @param string|null $docblock - * @param array|null $returnType - * @param array|null $original + * @param Definition $classDefinition + * @param array $visibility + * @param string $name + * @param Parameters|null $parameters + * @param StatementsBlock|null $statements + * @param string|null $docblock + * @param array|null $returnType + * @param array|null $original */ $methodVisibility = $params['method']['visibility']; $methodName = $params['method']['name']; diff --git a/tests/Zephir/TypesTest.php b/tests/Zephir/TypesTest.php index ca9bb7f409..0729181637 100644 --- a/tests/Zephir/TypesTest.php +++ b/tests/Zephir/TypesTest.php @@ -285,7 +285,7 @@ public function testShouldResolveCompatibleTypeForCollections(array $returnTypes $typesList = []; $collections = []; foreach ($returnTypes as $type) { - if (false !== strpos($type, '[]')) { + if (str_contains($type, '[]')) { $typesList[] = $this->variableReturnTypeDefinition([$type], 1)[0]; $collectionType = trim($type, '<>'); $collections[$collectionType] = $collectionType;