From bacf48ce52844e41efea72c040368f4b804f7c42 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev <1695147@gmail.com> Date: Sat, 23 Nov 2024 15:49:13 +0000 Subject: [PATCH] #2440 - Fix compatibility with PHP 8.4 in source --- prototypes/memcache.php | 2 +- prototypes/memcached.php | 10 +-- src/Backend/Backend.php | 2 +- src/Builder/Operators/CastOperatorBuilder.php | 4 +- .../Operators/UnaryOperatorBuilder.php | 2 +- src/Cache/Manager.php | 2 +- src/Call.php | 2 +- src/Class/Definition/Definition.php | 8 +- src/Class/Method/Method.php | 8 +- src/Class/Property.php | 2 +- src/CompilationContext.php | 2 +- src/Compiler.php | 2 +- src/CompilerFileAnonymous.php | 30 ++------ src/Console/Command/InitCommand.php | 2 +- src/Expression.php | 2 +- .../Builder/Factory/OperatorsFactory.php | 74 ++++--------------- .../Builder/Factory/StatementsFactory.php | 64 ++++------------ .../Operators/AssignPropertyOperator.php | 2 +- .../Builder/Operators/BinaryOperator.php | 57 +++----------- .../Builder/Operators/RawOperator.php | 29 ++------ .../Statements/CallFunctionStatement.php | 19 +---- .../Builder/Statements/IfStatement.php | 67 +++-------------- .../Builder/Statements/LetStatement.php | 36 +-------- .../Builder/Statements/RawStatement.php | 29 ++------ .../Builder/Statements/StatementsBlock.php | 41 ++-------- src/Expression/Closure.php | 5 +- src/Expression/Constants.php | 2 +- src/Expression/NativeArray.php | 2 +- src/Expression/NativeArrayAccess.php | 16 +--- src/Expression/PropertyAccess.php | 21 ++---- src/Expression/PropertyDynamicAccess.php | 13 +--- src/Expression/StaticConstantAccess.php | 12 +-- src/Expression/StaticPropertyAccess.php | 2 +- src/FunctionDefinition.php | 2 +- src/Name.php | 4 +- src/Operators/AbstractOperator.php | 2 +- src/Statements/ForStatement.php | 2 +- src/Statements/Let/ExportSymbol.php | 6 +- src/Statements/LetStatement.php | 4 +- src/StatementsBlock.php | 2 +- src/StaticCall.php | 13 +--- src/SymbolTable.php | 10 +-- src/Types/Types.php | 2 +- src/Variable/Variable.php | 2 +- 44 files changed, 143 insertions(+), 477 deletions(-) diff --git a/prototypes/memcache.php b/prototypes/memcache.php index d0c31ef46..7ae83ae69 100644 --- a/prototypes/memcache.php +++ b/prototypes/memcache.php @@ -26,7 +26,7 @@ public function pconnect($host, $port) { } - public function addserver($host, $port = 11211, $persistent = null, $weight = null, $timeout = null, $retry_interval = null, $status = null, callable $failure_callback = null, $timeoutms = null) + public function addserver($host, $port = 11211, $persistent = null, $weight = null, $timeout = null, $retry_interval = null, $status = null, ?callable $failure_callback = null, $timeoutms = null) { } diff --git a/prototypes/memcached.php b/prototypes/memcached.php index 92d7f6c0d..33b2731e6 100644 --- a/prototypes/memcached.php +++ b/prototypes/memcached.php @@ -142,7 +142,7 @@ public function getResultMessage() * * @return mixed */ - public function get($key, callable $cache_cb = null, &$cas_token = null) + public function get($key, ?callable $cache_cb = null, &$cas_token = null) { } @@ -156,7 +156,7 @@ public function get($key, callable $cache_cb = null, &$cas_token = null) * * @return mixed */ - public function getByKey($server_key, $key, callable $cache_cb = null, &$cas_token = null) + public function getByKey($server_key, $key, ?callable $cache_cb = null, &$cas_token = null) { } @@ -169,7 +169,7 @@ public function getByKey($server_key, $key, callable $cache_cb = null, &$cas_tok * * @return mixed */ - public function getMulti(array $keys, array &$cas_tokens = null, $flags = null) + public function getMulti(array $keys, ?array &$cas_tokens = null, $flags = null) { } @@ -196,7 +196,7 @@ public function getMultiByKey($server_key, array $keys, &$cas_tokens = null, $fl * * @return bool */ - public function getDelayed(array $keys, $with_cas = null, callable $value_cb = null) + public function getDelayed(array $keys, $with_cas = null, ?callable $value_cb = null) { } @@ -210,7 +210,7 @@ public function getDelayed(array $keys, $with_cas = null, callable $value_cb = n * * @return bool */ - public function getDelayedByKey($server_key, array $keys, $with_cas = null, callable $value_cb = null) + public function getDelayedByKey($server_key, array $keys, $with_cas = null, ?callable $value_cb = null) { } diff --git a/src/Backend/Backend.php b/src/Backend/Backend.php index d7f09bc5c..07c5d459e 100644 --- a/src/Backend/Backend.php +++ b/src/Backend/Backend.php @@ -1643,7 +1643,7 @@ public function ifVariableValueUndefined2( * * @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); diff --git a/src/Builder/Operators/CastOperatorBuilder.php b/src/Builder/Operators/CastOperatorBuilder.php index 97386a1d6..a02ce95fe 100644 --- a/src/Builder/Operators/CastOperatorBuilder.php +++ b/src/Builder/Operators/CastOperatorBuilder.php @@ -27,9 +27,9 @@ class CastOperatorBuilder extends AbstractOperatorBuilder public function __construct( string $left, FunctionCallBuilder $right, - string $file = null, + ?string $file = null, int $line = 0, - int $char = 0 + int $char = 0, ) { $this->leftOperand = $left; $this->rightOperand = $right; diff --git a/src/Builder/Operators/UnaryOperatorBuilder.php b/src/Builder/Operators/UnaryOperatorBuilder.php index f0844101a..501325016 100644 --- a/src/Builder/Operators/UnaryOperatorBuilder.php +++ b/src/Builder/Operators/UnaryOperatorBuilder.php @@ -24,7 +24,7 @@ class UnaryOperatorBuilder extends AbstractOperatorBuilder public function __construct( protected string $operator, protected $leftExpression, - string $file = null, + ?string $file = null, int $line = 0, int $char = 0, ) { diff --git a/src/Cache/Manager.php b/src/Cache/Manager.php index 143cc9d5a..29c7238bd 100644 --- a/src/Cache/Manager.php +++ b/src/Cache/Manager.php @@ -81,7 +81,7 @@ public function getStaticMethodCache(): ?StaticMethodCache /** * Sets the CallGathererPass. */ - public function setGatherer(CallGathererPass $gatherer = null): void + public function setGatherer(?CallGathererPass $gatherer = null): void { $this->gatherer = $gatherer; } diff --git a/src/Call.php b/src/Call.php index 8e97d584d..40a0bcaaa 100644 --- a/src/Call.php +++ b/src/Call.php @@ -718,7 +718,7 @@ public function getResolvedTypes(): array * * @return Variable|null */ - public function getSymbolVariable(bool $useTemp = false, CompilationContext $compilationContext = null): ?Variable + public function getSymbolVariable(bool $useTemp = false, ?CompilationContext $compilationContext = null): ?Variable { $symbolVariable = $this->symbolVariable; diff --git a/src/Class/Definition/Definition.php b/src/Class/Definition/Definition.php index 6865fbb3d..fe63ae005 100644 --- a/src/Class/Definition/Definition.php +++ b/src/Class/Definition/Definition.php @@ -135,7 +135,7 @@ final class Definition extends AbstractDefinition */ protected string $type = self::TYPE_CLASS; - 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; @@ -182,7 +182,7 @@ public function addInitMethod(StatementsBlock $statementsBlock): void * * @throws CompilerException */ - public function addMethod(Method $method, array $statement = null): void + public function addMethod(Method $method, array $statement = []): void { $methodName = strtolower($method->getName()); if (isset($this->methods[$methodName])) { @@ -782,7 +782,7 @@ public function getCNamespace(): string * * @throws Exception */ - public function getClassEntry(CompilationContext $compilationContext = null): string + public function getClassEntry(?CompilationContext $compilationContext = null): string { if ($this->external) { if ($compilationContext === null) { @@ -1368,7 +1368,7 @@ public function setType(string $type): void * * @throws CompilerException */ - public function updateMethod(Method $method, array $statement = null): void + public function updateMethod(Method $method, array $statement = []): void { $methodName = strtolower($method->getName()); if (!isset($this->methods[$methodName])) { diff --git a/src/Class/Method/Method.php b/src/Class/Method/Method.php index 29eb09245..ecf60115d 100644 --- a/src/Class/Method/Method.php +++ b/src/Class/Method/Method.php @@ -136,7 +136,7 @@ public function __construct( protected ?Parameters $parameters = null, protected ?StatementsBlock $statements = null, protected ?string $docblock = null, - array $returnType = null, + ?array $returnType = null, protected ?array $expression = [], array $staticVariables = [], ) { @@ -709,7 +709,7 @@ public function checkStrictType(array $parameter, CompilationContext $compilatio * * @throws CompilerException */ - public function checkVisibility(array $visibility, string $name, array $original = null): void + public function checkVisibility(array $visibility, string $name, array $original = []): void { if (count($visibility) > 1) { if (in_array('public', $visibility) && in_array('protected', $visibility)) { @@ -1578,7 +1578,7 @@ public function detectParam(array $parameter, CompilationContext $compilationCon /** * 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( @@ -2248,7 +2248,7 @@ public function setName(string $name): void * * @param array|null $returnType */ - public function setReturnTypes(array $returnType = null): void + public function setReturnTypes(?array $returnType = null): void { $this->returnTypesRaw = $returnType; if (null === $returnType) { diff --git a/src/Class/Property.php b/src/Class/Property.php index 66c7ce127..f205195b4 100644 --- a/src/Class/Property.php +++ b/src/Class/Property.php @@ -57,7 +57,7 @@ public function __construct( /** * 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)) { throw new CompilerException( diff --git a/src/CompilationContext.php b/src/CompilationContext.php index b189e607b..5247a8f6b 100644 --- a/src/CompilationContext.php +++ b/src/CompilationContext.php @@ -126,7 +126,7 @@ class CompilationContext /** * Lookup a class from a given class name. */ - public function classLookup(string $className, array $statement = null): AbstractDefinition + public function classLookup(string $className, array $statement = []): AbstractDefinition { if (!in_array($className, ['self', 'static', 'parent'])) { $className = $this->getFullName($className); diff --git a/src/Compiler.php b/src/Compiler.php index 4c691e2be..992cce489 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -268,7 +268,7 @@ public function checkIfPhpized(): 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; diff --git a/src/CompilerFileAnonymous.php b/src/CompilerFileAnonymous.php index d81899144..2d1487950 100644 --- a/src/CompilerFileAnonymous.php +++ b/src/CompilerFileAnonymous.php @@ -37,10 +37,7 @@ final class CompilerFileAnonymous implements FileInterface use CompilerTrait; use LoggerAwareTrait; - protected Definition $classDefinition; protected ?string $compiledFile = null; - protected Config $config; - protected ?CompilationContext $context = null; protected bool $external = false; protected array $headerCBlocks = []; protected ?string $namespace = null; @@ -52,21 +49,18 @@ final class CompilerFileAnonymous implements FileInterface * @param Config $config * @param CompilationContext|null $context */ - public function __construct(Definition $classDefinition, Config $config, CompilationContext $context = null) - { - $this->classDefinition = $classDefinition; - $this->config = $config; - $this->context = $context; - $this->logger = new NullLogger(); + public function __construct( + protected Definition $classDefinition, + protected Config $config, + protected ?CompilationContext $context = null + ) { + $this->logger = new NullLogger(); } /** * Compiles the file. * - * @param Compiler $compiler - * @param StringsManager $stringsManager - * - * @throws Exception + * @throws Exception|ReflectionException */ public function compile(Compiler $compiler, StringsManager $stringsManager): void { @@ -74,7 +68,6 @@ public function compile(Compiler $compiler, StringsManager $stringsManager): voi * Compilation context stores common objects required by compilation entities. */ $compilationContext = new CompilationContext(); - if ($this->context) { $compilationContext->aliasManager = $this->context->aliasManager; } else { @@ -151,17 +144,12 @@ public function getClassDefinition(): Definition /** * Returns the path to the compiled file. - * - * @return string */ - public function getCompiledFile() + public function getCompiledFile(): string { return $this->compiledFile; } - /** - * @return bool - */ public function isExternal(): bool { return $this->external; @@ -181,8 +169,6 @@ public function preCompile(Compiler $compiler): void /** * Sets if the class belongs to an external dependency or not. - * - * @param bool $external */ public function setIsExternal($external): void { diff --git a/src/Console/Command/InitCommand.php b/src/Console/Command/InitCommand.php index 42a4a4bfe..503136b8d 100644 --- a/src/Console/Command/InitCommand.php +++ b/src/Console/Command/InitCommand.php @@ -119,7 +119,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int * * @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); diff --git a/src/Expression.php b/src/Expression.php index 9619d3c8e..bcf7d2dbb 100644 --- a/src/Expression.php +++ b/src/Expression.php @@ -582,7 +582,7 @@ public function setEvalMode(bool $evalMode): void * @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; diff --git a/src/Expression/Builder/Factory/OperatorsFactory.php b/src/Expression/Builder/Factory/OperatorsFactory.php index adbf873ec..c1664bbdb 100644 --- a/src/Expression/Builder/Factory/OperatorsFactory.php +++ b/src/Expression/Builder/Factory/OperatorsFactory.php @@ -27,17 +27,10 @@ public function __construct(protected BuilderFactory $factory) { } - /** - * @param null $variable - * @param null $property - * @param AbstractBuilder|null $expression - * - * @return AssignPropertyOperator - */ public function assignProperty( $variable = null, $property = null, - AbstractBuilder $expression = null + ?AbstractBuilder $expression = null ): AssignPropertyOperator { $assignProperty = new AssignPropertyOperator($variable, $property, $expression); $assignProperty->setType($assignProperty::TYPE_ASSIGN_OBJECT_PROPERTY); @@ -45,17 +38,10 @@ public function assignProperty( return $assignProperty; } - /** - * @param null $variable - * @param null $property - * @param AbstractBuilder|null $expression - * - * @return AssignPropertyOperator - */ public function assignStaticProperty( $variable = null, $property = null, - AbstractBuilder $expression = null + ?AbstractBuilder $expression = null ): AssignPropertyOperator { $assignProperty = $this->assignProperty($variable, $property, $expression); $assignProperty->setType($assignProperty::TYPE_ASSIGN_STATIC_PROPERTY); @@ -63,39 +49,22 @@ public function assignStaticProperty( return $assignProperty; } - /** - * @param null $variable - * @param AbstractBuilder|null $expression - * - * @return AssignVariableOperator - */ - public function assignVariable($variable = null, AbstractBuilder $expression = null): AssignVariableOperator - { + public function assignVariable( + ?string $variable = null, + ?AbstractBuilder $expression = null + ): AssignVariableOperator { return new AssignVariableOperator($variable, $expression); } - /** - * @param null $operator - * @param AbstractBuilder|null $leftExpression - * @param AbstractBuilder|null $rightExpression - * - * @return BinaryOperator - */ public function binary( $operator = null, - AbstractBuilder $leftExpression = null, - AbstractBuilder $rightExpression = null - ) { + ?AbstractBuilder $leftExpression = null, + ?AbstractBuilder $rightExpression = null + ): BinaryOperator { return new BinaryOperator($operator, $leftExpression, $rightExpression); } - /** - * @param $type - * @param AbstractBuilder $expression - * - * @return RawOperator - */ - public function cast($type, AbstractBuilder $expression) + public function cast(string $type, AbstractBuilder $expression): RawOperator { return $this->raw([ 'type' => BinaryOperator::OPERATOR_CAST, @@ -104,13 +73,7 @@ public function cast($type, AbstractBuilder $expression) ]); } - /** - * @param $type - * @param AbstractBuilder $expression - * - * @return RawOperator - */ - public function hint($type, AbstractBuilder $expression) + public function hint(string $type, AbstractBuilder $expression): RawOperator { return $this->raw([ 'type' => BinaryOperator::OPERATOR_TYPE_HINT, @@ -119,23 +82,12 @@ public function hint($type, AbstractBuilder $expression) ]); } - /** - * @param array $expression - * - * @return RawOperator - */ - public function raw(array $expression) + public function raw(array $expression): RawOperator { return new RawOperator($expression); } - /** - * @param string|null $operator - * @param AbstractBuilder|null $expression - * - * @return UnaryOperator - */ - public function unary($operator = null, AbstractBuilder $expression = null) + public function unary(?string $operator = null, ?AbstractBuilder $expression = null): UnaryOperator { return new UnaryOperator($operator, $expression); } diff --git a/src/Expression/Builder/Factory/StatementsFactory.php b/src/Expression/Builder/Factory/StatementsFactory.php index 6148a8be9..0f65cc62a 100644 --- a/src/Expression/Builder/Factory/StatementsFactory.php +++ b/src/Expression/Builder/Factory/StatementsFactory.php @@ -28,69 +28,38 @@ public function __construct(protected BuilderFactory $factory) { } - /** - * @param array|null $statements - * - * @return StatementsBlock - */ - public function block(array $statements = null) + public function block(?array $statements = null): StatementsBlock { return new StatementsBlock($statements); } - /** - * @param string $name - * @param array|null $parameters - * @param int $type - * - * @return CallFunctionStatement - */ - public function functionCall($name, $parameters = null, $type = CallFunctionStatement::TYPE_CALL_DIRECT) - { + public function functionCall( + string $name, + ?array $parameters = null, + int $type = CallFunctionStatement::TYPE_CALL_DIRECT + ): CallFunctionStatement { return new CallFunctionStatement($name, $parameters, $type); } - /** - * @param AbstractOperator|null $condition - * @param StatementsBlock|null $statements - * @param StatementsBlock|null $elseStatements - * - * @return IfStatement - */ public function ifX( - AbstractOperator $condition = null, - StatementsBlock $statements = null, - StatementsBlock $elseStatements = null - ) { + ?AbstractOperator $condition = null, + ?StatementsBlock $statements = null, + ?StatementsBlock $elseStatements = null + ): IfStatement { return new IfStatement($condition, $statements, $elseStatements); } - /** - * @param array|null $assignments - * - * @return LetStatement - */ - public function let(array $assignments = null) + public function let(?array $assignments = null): LetStatement { return new LetStatement($assignments); } - /** - * @param array $expression - * - * @return RawStatement - */ - public function raw(array $expression) + public function raw(array $expression): RawStatement { return new RawStatement($expression); } - /** - * @param string $value - * - * @return RawStatement - */ - public function rawC($value) + public function rawC(string $value): RawStatement { return $this->raw([ 'type' => 'cblock', @@ -98,12 +67,7 @@ public function rawC($value) ]); } - /** - * @param AbstractBuilder $expression - * - * @return RawStatement - */ - public function returnX(AbstractBuilder $expression) + public function returnX(AbstractBuilder $expression): RawStatement { return $this->raw([ 'type' => 'return', diff --git a/src/Expression/Builder/Operators/AssignPropertyOperator.php b/src/Expression/Builder/Operators/AssignPropertyOperator.php index ed1cb6b16..895045c11 100644 --- a/src/Expression/Builder/Operators/AssignPropertyOperator.php +++ b/src/Expression/Builder/Operators/AssignPropertyOperator.php @@ -24,7 +24,7 @@ class AssignPropertyOperator extends AssignVariableOperator public const TYPE_ASSIGN_STATIC_PROPERTY = 'static-property'; private string $type = self::TYPE_ASSIGN_OBJECT_PROPERTY; - public function __construct($variable = null, private $property = null, AbstractBuilder $expression = null) + public function __construct($variable = null, private $property = null, ?AbstractBuilder $expression = null) { parent::__construct($variable, $expression); diff --git a/src/Expression/Builder/Operators/BinaryOperator.php b/src/Expression/Builder/Operators/BinaryOperator.php index 29ee39314..d66b19ad0 100644 --- a/src/Expression/Builder/Operators/BinaryOperator.php +++ b/src/Expression/Builder/Operators/BinaryOperator.php @@ -115,19 +115,11 @@ class BinaryOperator extends AbstractOperator // x [{expr}] public const OPERATOR_TYPE_HINT = 'type-hint'; - private $leftExpression; - private $operator; - private $rightExpression; - - /** - * @param null $operator - * @param AbstractBuilder|null $leftExpression - * @param AbstractBuilder|null $rightExpression - */ + public function __construct( - $operator = null, - AbstractBuilder $leftExpression = null, - AbstractBuilder $rightExpression = null + private $operator = null, + private ?AbstractBuilder $leftExpression = null, + private ?AbstractBuilder $rightExpression = null ) { if (null !== $operator) { $this->setOperator($operator); @@ -142,70 +134,43 @@ public function __construct( } } - /** - * @return AbstractBuilder - */ - public function getLeftExpression() + public function getLeftExpression(): AbstractBuilder { return $this->leftExpression; } - /** - * @return string - */ - public function getOperator() + public function getOperator(): string { return $this->operator; } - /** - * @return AbstractBuilder - */ - public function getRightExpression() + public function getRightExpression(): AbstractBuilder { return $this->rightExpression; } - /** - * @param AbstractBuilder $leftExpression - * - * @return BinaryOperator - */ - public function setLeftExpression(AbstractBuilder $leftExpression) + public function setLeftExpression(AbstractBuilder $leftExpression): BinaryOperator { $this->leftExpression = $leftExpression; return $this; } - /** - * @param string $operator - * - * @return BinaryOperator - */ - public function setOperator($operator) + public function setOperator(string $operator): BinaryOperator { $this->operator = $operator; return $this; } - /** - * @param AbstractBuilder $rightExpression - * - * @return BinaryOperator - */ - public function setRightExpression(AbstractBuilder $rightExpression) + public function setRightExpression(AbstractBuilder $rightExpression): BinaryOperator { $this->rightExpression = $rightExpression; return $this; } - /** - * {@inheritdoc} - */ - protected function preBuild() + protected function preBuild(): array { return [ 'type' => $this->getOperator(), diff --git a/src/Expression/Builder/Operators/RawOperator.php b/src/Expression/Builder/Operators/RawOperator.php index cbcfbc82c..671a3b304 100644 --- a/src/Expression/Builder/Operators/RawOperator.php +++ b/src/Expression/Builder/Operators/RawOperator.php @@ -15,45 +15,28 @@ class RawOperator extends AbstractOperator { - /** - * @var array - */ - private $expression; - - /** - * @param array|null $expression - */ - public function __construct(array $expression = null) + private array $expression; + + public function __construct(?array $expression = null) { if (null !== $expression) { $this->setExpression($expression); } } - /** - * @return array - */ - public function getExpression() + public function getExpression(): array { return $this->expression; } - /** - * @param array $expression - * - * @return $this - */ - public function setExpression(array $expression) + public function setExpression(array $expression): self { $this->expression = $expression; return $this; } - /** - * @return array - */ - protected function preBuild() + protected function preBuild(): array { return $this->getExpression(); } diff --git a/src/Expression/Builder/Statements/CallFunctionStatement.php b/src/Expression/Builder/Statements/CallFunctionStatement.php index 44cc80a44..69120be8f 100644 --- a/src/Expression/Builder/Statements/CallFunctionStatement.php +++ b/src/Expression/Builder/Statements/CallFunctionStatement.php @@ -36,16 +36,10 @@ class CallFunctionStatement extends AbstractStatement * {"f"}(x, y, ... , N). */ public const TYPE_CALL_DYNAMIC_STRING = FunctionCall::CALL_DYNAMIC_STRING; - private $arguments; - private $name; - private $typeCall; - /** - * @param string|null $name - * @param array|null $parameters - * @param int $typeCall - */ - public function __construct(string $name = null, array $parameters = null, int $typeCall = self::TYPE_CALL_DIRECT) + private ?array $arguments = null; + + public function __construct(private ?string $name = null, private ?array $parameters = null, private int $typeCall = self::TYPE_CALL_DIRECT) { if (null !== $name) { $this->setName($name); @@ -96,12 +90,7 @@ public function getTypeCall() return $this->typeCall; } - /** - * @param array|null $arguments - * - * @return $this - */ - public function setArguments(array $arguments = null) + public function setArguments(?array $arguments = null): self { $this->arguments = $arguments; diff --git a/src/Expression/Builder/Statements/IfStatement.php b/src/Expression/Builder/Statements/IfStatement.php index 185b8abfe..d0e0ed735 100644 --- a/src/Expression/Builder/Statements/IfStatement.php +++ b/src/Expression/Builder/Statements/IfStatement.php @@ -16,32 +16,14 @@ use Zephir\Expression\Builder\Operators\AbstractOperator; /** - * Allows to manually build a 'if' statement AST node + * Allows to manually build an 'if' statement AST node. */ class IfStatement extends AbstractStatement { - /** - * @var AbstractOperator - */ - private $condition; - /** - * @var StatementsBlock - */ - private $elseStatements; - /** - * @var StatementsBlock - */ - private $statements; - - /** - * @param AbstractOperator|null $condition - * @param StatementsBlock|null $statements - * @param StatementsBlock|null $elseStatements - */ public function __construct( - AbstractOperator $condition = null, - StatementsBlock $statements = null, - StatementsBlock $elseStatements = null + private ?AbstractOperator $condition = null, + private ?StatementsBlock $statements = null, + private ?StatementsBlock $elseStatements = null ) { if (null !== $condition) { $this->setCondition($condition); @@ -56,70 +38,43 @@ public function __construct( } } - /** - * @return AbstractOperator - */ - public function getCondition() + public function getCondition(): ?AbstractOperator { return $this->condition; } - /** - * @return StatementsBlock - */ - public function getElseStatements() + public function getElseStatements(): ?StatementsBlock { return $this->elseStatements; } - /** - * @return StatementsBlock - */ - public function getStatements() + public function getStatements(): ?StatementsBlock { return $this->statements; } - /** - * @param AbstractOperator $condition - * - * @return $this - */ - public function setCondition(AbstractOperator $condition) + public function setCondition(AbstractOperator $condition): self { $this->condition = $condition; return $this; } - /** - * @param StatementsBlock $elseStatements - * - * @return $this - */ - public function setElseStatements(StatementsBlock $elseStatements) + public function setElseStatements(StatementsBlock $elseStatements): self { $this->elseStatements = $elseStatements; return $this; } - /** - * @param StatementsBlock $statements - * - * @return $this - */ - public function setStatements(StatementsBlock $statements) + public function setStatements(StatementsBlock $statements): self { $this->statements = $statements; return $this; } - /** - * {@inheritdoc} - */ - protected function preBuild() + protected function preBuild(): array { $expression = [ 'type' => 'if', diff --git a/src/Expression/Builder/Statements/LetStatement.php b/src/Expression/Builder/Statements/LetStatement.php index c7f224a50..7cedc5b31 100644 --- a/src/Expression/Builder/Statements/LetStatement.php +++ b/src/Expression/Builder/Statements/LetStatement.php @@ -18,54 +18,26 @@ */ class LetStatement extends AbstractStatement { - private $assignments; - - /** - * @param array|null $assignments - */ - public function __construct(array $assignments = null) + public function __construct(private ?array $assignments = null) { if (null !== $assignments) { $this->setAssignments($assignments); } } - /** - * @param mixed $assignment - * - * @return $this - */ - public function addAssignment($assignment) - { - $this->assignments[] = $assignment; - - return $this; - } - - /** - * @return mixed - */ - public function getAssignments() + public function getAssignments(): array { return $this->assignments; } - /** - * @param array $assignments - * - * @return $this - */ - public function setAssignments($assignments) + public function setAssignments(array $assignments): self { $this->assignments = $assignments; return $this; } - /** - * {@inheritdoc} - */ - protected function preBuild() + protected function preBuild(): array { return [ 'type' => 'let', diff --git a/src/Expression/Builder/Statements/RawStatement.php b/src/Expression/Builder/Statements/RawStatement.php index a687cbf9c..21506e5e2 100644 --- a/src/Expression/Builder/Statements/RawStatement.php +++ b/src/Expression/Builder/Statements/RawStatement.php @@ -15,45 +15,28 @@ class RawStatement extends AbstractStatement { - /** - * @var array - */ - private $expression; - - /** - * @param array|null $expression - */ - public function __construct(array $expression = null) + private array $expression; + + public function __construct(?array $expression = null) { if (null !== $expression) { $this->setExpression($expression); } } - /** - * @return array - */ - public function getExpression() + public function getExpression(): array { return $this->expression; } - /** - * @param array $expression - * - * @return $this - */ - public function setExpression(array $expression) + public function setExpression(array $expression): self { $this->expression = $expression; return $this; } - /** - * @return array - */ - protected function preBuild() + protected function preBuild(): array { return $this->getExpression(); } diff --git a/src/Expression/Builder/Statements/StatementsBlock.php b/src/Expression/Builder/Statements/StatementsBlock.php index d7daf014c..30a5e9e5d 100644 --- a/src/Expression/Builder/Statements/StatementsBlock.php +++ b/src/Expression/Builder/Statements/StatementsBlock.php @@ -20,62 +20,31 @@ */ class StatementsBlock extends AbstractBuilder { - private $statements; - - /** - * @param array|null $statements - */ - public function __construct(array $statements = null) + public function __construct(private ?array $statements = null) { if (null !== $statements) { $this->setStatements($statements); } } - /** - * @param $statement - * - * @return $this - */ - public function addStatement($statement) - { - $this->statements[] = $statement; - - return $this; - } - - /** - * @return array - */ - public function build() + public function build(): array { return $this->resolve($this->preBuild()); } - /** - * @return array - */ - public function getStatements() + public function getStatements(): array { return $this->statements; } - /** - * @param array $statements - * - * @return $this - */ - public function setStatements($statements) + public function setStatements(array $statements): self { $this->statements = $statements; return $this; } - /** - * @return array - */ - protected function preBuild() + protected function preBuild(): array { return $this->getStatements(); } diff --git a/src/Expression/Closure.php b/src/Expression/Closure.php index e9fc8e221..6b6213d8c 100644 --- a/src/Expression/Closure.php +++ b/src/Expression/Closure.php @@ -178,11 +178,8 @@ public function compile(array $expression, CompilationContext $compilationContex /** * 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 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; diff --git a/src/Expression/Constants.php b/src/Expression/Constants.php index cf655012f..4c753e7c8 100644 --- a/src/Expression/Constants.php +++ b/src/Expression/Constants.php @@ -212,7 +212,7 @@ public function compile(array $expression, CompilationContext $compilationContex * Sets if the variable must be resolved into a direct variable symbol * create a temporary value or ignore the return value. */ - public function setExpectReturn(bool $expecting, Variable $expectingVariable = null): void + public function setExpectReturn(bool $expecting, ?Variable $expectingVariable = null): void { $this->expecting = $expecting; $this->expectingVariable = $expectingVariable; diff --git a/src/Expression/NativeArray.php b/src/Expression/NativeArray.php index 8462476d3..fcad2c8c0 100644 --- a/src/Expression/NativeArray.php +++ b/src/Expression/NativeArray.php @@ -585,7 +585,7 @@ public function getArrayValue( * @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; diff --git a/src/Expression/NativeArrayAccess.php b/src/Expression/NativeArrayAccess.php index bdb9b30ad..4e02aa0df 100644 --- a/src/Expression/NativeArrayAccess.php +++ b/src/Expression/NativeArrayAccess.php @@ -34,11 +34,6 @@ class NativeArrayAccess /** * Compiles foo[x] = {expr}. * - * @param $expression - * @param CompilationContext $compilationContext - * - * @return CompiledExpression - * * @throws Exception * @throws ReflectionException */ @@ -98,11 +93,8 @@ public function compile($expression, CompilationContext $compilationContext) /** * 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 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; @@ -110,8 +102,6 @@ public function setExpectReturn(bool $expecting, Variable $expectingVariable = n /** * Sets whether the expression must be resolved in "noisy" mode. - * - * @param bool $noisy */ public function setNoisy(bool $noisy): void { @@ -120,8 +110,6 @@ public function setNoisy(bool $noisy): void /** * Sets if the result of the evaluated expression is read only. - * - * @param bool $readOnly */ public function setReadOnly(bool $readOnly): void { @@ -199,7 +187,6 @@ protected function accessDimensionArray( $symbolVariable = $compilationContext->symbolTable->getTempNonTrackedUninitializedVariable( 'variable', $compilationContext, - $expression ); } } @@ -207,7 +194,6 @@ protected function accessDimensionArray( $symbolVariable = $compilationContext->symbolTable->getTempNonTrackedUninitializedVariable( 'variable', $compilationContext, - $expression ); } } else { diff --git a/src/Expression/PropertyAccess.php b/src/Expression/PropertyAccess.php index 36ff9f62e..74a8b0017 100644 --- a/src/Expression/PropertyAccess.php +++ b/src/Expression/PropertyAccess.php @@ -13,8 +13,10 @@ namespace Zephir\Expression; +use ReflectionException; use Zephir\CompilationContext; use Zephir\CompiledExpression; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Traits\VariablesTrait; @@ -37,12 +39,10 @@ class PropertyAccess /** * Resolves the access to a property in an object. * - * @param array $expression - * @param CompilationContext $compilationContext - * - * @return CompiledExpression + * @throws ReflectionException + * @throws Exception */ - public function compile($expression, CompilationContext $compilationContext) + public function compile($expression, CompilationContext $compilationContext): CompiledExpression { $propertyAccess = $expression; @@ -267,11 +267,8 @@ public function compile($expression, CompilationContext $compilationContext) /** * 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 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; @@ -279,8 +276,6 @@ public function setExpectReturn(bool $expecting, Variable $expectingVariable = n /** * Sets whether the expression must be resolved in "noisy" mode. - * - * @param bool $noisy */ public function setNoisy(bool $noisy): void { @@ -289,10 +284,8 @@ public function setNoisy(bool $noisy): void /** * Sets if the result of the evaluated expression is read only. - * - * @param bool $readOnly */ - public function setReadOnly($readOnly): void + public function setReadOnly(bool $readOnly): void { $this->readOnly = $readOnly; } diff --git a/src/Expression/PropertyDynamicAccess.php b/src/Expression/PropertyDynamicAccess.php index 7c2d08a0b..41a2e4eec 100644 --- a/src/Expression/PropertyDynamicAccess.php +++ b/src/Expression/PropertyDynamicAccess.php @@ -139,11 +139,8 @@ public function compile($expression, CompilationContext $compilationContext) /** * 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 Variable|null $expectingVariable */ - public function setExpectReturn($expecting, Variable $expectingVariable = null): void + public function setExpectReturn(bool $expecting, ?Variable $expectingVariable = null): void { $this->expecting = $expecting; $this->expectingVariable = $expectingVariable; @@ -151,20 +148,16 @@ public function setExpectReturn($expecting, Variable $expectingVariable = null): /** * Sets whether the expression must be resolved in "noisy" mode. - * - * @param bool $noisy */ - public function setNoisy($noisy): void + public function setNoisy(bool $noisy): void { $this->noisy = $noisy; } /** * Sets if the result of the evaluated expression is read only. - * - * @param bool $readOnly */ - public function setReadOnly($readOnly): void + public function setReadOnly(bool $readOnly): void { $this->readOnly = $readOnly; } diff --git a/src/Expression/StaticConstantAccess.php b/src/Expression/StaticConstantAccess.php index 4181ce8ee..781b5324a 100644 --- a/src/Expression/StaticConstantAccess.php +++ b/src/Expression/StaticConstantAccess.php @@ -37,11 +37,6 @@ class StaticConstantAccess /** * Access a static constant class. * - * @param array $expression - * @param CompilationContext $compilationContext - * - * @return CompiledExpression - * * @throws Exception * @throws ReflectionException */ @@ -189,11 +184,8 @@ public function compile(array $expression, CompilationContext $compilationContex /** * 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 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; @@ -201,8 +193,6 @@ public function setExpectReturn(bool $expecting, Variable $expectingVariable = n /** * Sets if the result of the evaluated expression is read only. - * - * @param bool $readOnly */ public function setReadOnly(bool $readOnly): void { diff --git a/src/Expression/StaticPropertyAccess.php b/src/Expression/StaticPropertyAccess.php index 85b4b2c9f..dad7a0c29 100644 --- a/src/Expression/StaticPropertyAccess.php +++ b/src/Expression/StaticPropertyAccess.php @@ -184,7 +184,7 @@ public function compile(array $expression, CompilationContext $compilationContex * Sets if the variable must be resolved into a direct variable symbol * create a temporary value or ignore the return value. */ - public function setExpectReturn(bool $expecting, Variable $expectingVariable = null): void + public function setExpectReturn(bool $expecting, ?Variable $expectingVariable = null): void { $this->expecting = $expecting; $this->expectingVariable = $expectingVariable; diff --git a/src/FunctionDefinition.php b/src/FunctionDefinition.php index bc3a4efd5..2dfaef610 100644 --- a/src/FunctionDefinition.php +++ b/src/FunctionDefinition.php @@ -31,7 +31,7 @@ public function __construct( protected string $name, protected ?Parameters $parameters = null, protected ?StatementsBlock $statements = null, - array $returnType = null, + ?array $returnType = null, protected ?array $expression = [], ) { $this->setReturnTypes($returnType); diff --git a/src/Name.php b/src/Name.php index 99529c6dd..8973af902 100644 --- a/src/Name.php +++ b/src/Name.php @@ -107,8 +107,8 @@ public static function camelize(string $string): string */ public static function fetchFQN( string $class, - string $namespace = null, - AliasManager $aliasManager = null + ?string $namespace = null, + ?AliasManager $aliasManager = null ): string { /** * Absolute class/interface name diff --git a/src/Operators/AbstractOperator.php b/src/Operators/AbstractOperator.php index eba8bf31c..bf6d7d01d 100644 --- a/src/Operators/AbstractOperator.php +++ b/src/Operators/AbstractOperator.php @@ -222,7 +222,7 @@ public function isReadOnly(): bool * @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; diff --git a/src/Statements/ForStatement.php b/src/Statements/ForStatement.php index dc3a3e4f3..57bd6a11c 100644 --- a/src/Statements/ForStatement.php +++ b/src/Statements/ForStatement.php @@ -753,7 +753,7 @@ public function compileRange(array $exprRaw, CompilationContext $compilationCont public function compileStringTraverse( CompiledExpression $expression, CompilationContext $compilationContext, - Variable $exprVariable = null, + ?Variable $exprVariable = null, ): void { $codePrinter = $compilationContext->codePrinter; diff --git a/src/Statements/Let/ExportSymbol.php b/src/Statements/Let/ExportSymbol.php index dc93f8cc1..8ffb7c285 100644 --- a/src/Statements/Let/ExportSymbol.php +++ b/src/Statements/Let/ExportSymbol.php @@ -35,9 +35,9 @@ class ExportSymbol */ public function assign( $variable, - ZephirVariable $symbolVariable = null, - CompiledExpression $resolvedExpr = null, - CompilationContext $compilationContext = null, + ?ZephirVariable $symbolVariable = null, + ?CompiledExpression $resolvedExpr = null, + ?CompilationContext $compilationContext = null, $statement = null ): void { $codePrinter = $compilationContext->codePrinter; diff --git a/src/Statements/LetStatement.php b/src/Statements/LetStatement.php index 90aef5957..63d8aaf07 100644 --- a/src/Statements/LetStatement.php +++ b/src/Statements/LetStatement.php @@ -46,8 +46,6 @@ use function is_object; /** - * LetStatement. - * * Let statement is used to assign variables */ class LetStatement extends StatementAbstract @@ -65,7 +63,7 @@ public function compile(CompilationContext $compilationContext): void foreach ($statement['assignments'] as $assignment) { $variable = $assignment['variable']; - /* + /** * Get the symbol from the symbol table if necessary */ $symbolVariable = match ($assignment['assign-type']) { diff --git a/src/StatementsBlock.php b/src/StatementsBlock.php index 0c46d5137..bb3371346 100644 --- a/src/StatementsBlock.php +++ b/src/StatementsBlock.php @@ -79,7 +79,7 @@ public function __construct(protected array $statements) */ public function compile( CompilationContext $compilationContext, - bool $unreachable = null, + ?bool $unreachable = null, int $branchType = Branch::TYPE_UNKNOWN ): Branch { $compilationContext->codePrinter->increaseLevel(); diff --git a/src/StaticCall.php b/src/StaticCall.php index 1fc494343..f6d88ed19 100644 --- a/src/StaticCall.php +++ b/src/StaticCall.php @@ -355,15 +355,6 @@ 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 CompilationContext $compilationContext - * @param Variable|null $symbolVariable - * @param Method|null $method - * * @throws Exception */ protected function call( @@ -373,8 +364,8 @@ 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'])) { $context = 'SELF'; diff --git a/src/SymbolTable.php b/src/SymbolTable.php index ac0495fa6..6d1c24e93 100644 --- a/src/SymbolTable.php +++ b/src/SymbolTable.php @@ -519,7 +519,7 @@ public function getVariable(string $name, ?CompilationContext $compilationContex * * @throws CompilerException */ - public function getVariableForRead($name, CompilationContext $compilationContext = null, array $statement = null) + public function getVariableForRead(string $name, ?CompilationContext $compilationContext = null, ?array $statement = null) { /** * Validate that 'this' cannot be used in a static function @@ -704,7 +704,7 @@ public function getVariableForRead($name, CompilationContext $compilationContext * 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. */ - public function getVariableForUpdate(string $name, CompilationContext $compilationContext, array $statement = null) + public function getVariableForUpdate(string $name, CompilationContext $compilationContext, ?array $statement = null) { /** * Create superglobals just in time @@ -757,7 +757,7 @@ public function getVariableForUpdate(string $name, CompilationContext $compilati * * @throws CompilerException */ - public function getVariableForWrite($name, CompilationContext $compilationContext, array $statement = null) + public function getVariableForWrite(string $name, CompilationContext $compilationContext, ?array $statement = null) { /** * Create superglobals just in time @@ -827,7 +827,7 @@ public function getVariables(): array * * @return bool */ - public function hasVariable(string $name, CompilationContext $compilationContext = null): bool + public function hasVariable(string $name, ?CompilationContext $compilationContext = null): bool { return false !== $this->getVariable($name, $compilationContext ?: $this->compilationContext); } @@ -835,7 +835,7 @@ public function hasVariable(string $name, CompilationContext $compilationContext public function hasVariableInBranch( $name, Branch $compareBranch, - CompilationContext $compilationContext = null + ?CompilationContext $compilationContext = null ): bool { $branch = $this->resolveVariableToBranch($name, $compilationContext ?: $this->compilationContext); diff --git a/src/Types/Types.php b/src/Types/Types.php index 73c30bdb3..97f180246 100644 --- a/src/Types/Types.php +++ b/src/Types/Types.php @@ -50,7 +50,7 @@ final class Types /** * Gets PHP compatible return type from class method. */ - public function getReturnTypeAnnotation(Method $method, array $returnTypes = null): string + public function getReturnTypeAnnotation(Method $method, ?array $returnTypes = null): string { if (!$method->hasReturnTypes() && !$method->isVoid()) { return ''; diff --git a/src/Variable/Variable.php b/src/Variable/Variable.php index 06eb12226..4adcdf398 100644 --- a/src/Variable/Variable.php +++ b/src/Variable/Variable.php @@ -1049,7 +1049,7 @@ public function setType(string $type): void * @param bool $used * @param array|null $node */ - public function setUsed(bool $used, array $node = null): void + public function setUsed(bool $used, ?array $node = null): void { $this->used = $used; $this->usedNode = $node;