diff --git a/src/Analyser/DirectInternalScopeFactory.php b/src/Analyser/DirectInternalScopeFactory.php index b1a27020cc..e2b88a406d 100644 --- a/src/Analyser/DirectInternalScopeFactory.php +++ b/src/Analyser/DirectInternalScopeFactory.php @@ -42,12 +42,11 @@ public function __construct( /** * @param array $expressionTypes + * @param array $nativeExpressionTypes * @param array $conditionalExpressions + * @param array<(FunctionReflection|MethodReflection)> $inFunctionCallsStack * @param array $currentlyAssignedExpressions * @param array $currentlyAllowedUndefinedExpressions - * @param array $nativeExpressionTypes - * @param array<(FunctionReflection|MethodReflection)> $inFunctionCallsStack - * */ public function create( ScopeContext $context, @@ -55,13 +54,13 @@ public function create( FunctionReflection|MethodReflection|null $function = null, ?string $namespace = null, array $expressionTypes = [], + array $nativeExpressionTypes = [], array $conditionalExpressions = [], ?string $inClosureBindScopeClass = null, ?ParametersAcceptor $anonymousFunctionReflection = null, bool $inFirstLevelStatement = true, array $currentlyAssignedExpressions = [], array $currentlyAllowedUndefinedExpressions = [], - array $nativeExpressionTypes = [], array $inFunctionCallsStack = [], bool $afterExtractCall = false, ?Scope $parentScope = null, @@ -90,13 +89,13 @@ public function create( $function, $namespace, $expressionTypes, + $nativeExpressionTypes, $conditionalExpressions, $inClosureBindScopeClass, $anonymousFunctionReflection, $inFirstLevelStatement, $currentlyAssignedExpressions, $currentlyAllowedUndefinedExpressions, - $nativeExpressionTypes, $inFunctionCallsStack, $this->treatPhpDocTypesAsCertain, $afterExtractCall, diff --git a/src/Analyser/InternalScopeFactory.php b/src/Analyser/InternalScopeFactory.php index 8e5279f35b..13ed62fe68 100644 --- a/src/Analyser/InternalScopeFactory.php +++ b/src/Analyser/InternalScopeFactory.php @@ -11,10 +11,10 @@ interface InternalScopeFactory /** * @param array $expressionTypes + * @param array $nativeExpressionTypes * @param array $conditionalExpressions * @param array $currentlyAssignedExpressions * @param array $currentlyAllowedUndefinedExpressions - * @param array $nativeExpressionTypes * @param array $inFunctionCallsStack */ public function create( @@ -23,13 +23,13 @@ public function create( FunctionReflection|MethodReflection|null $function = null, ?string $namespace = null, array $expressionTypes = [], + array $nativeExpressionTypes = [], array $conditionalExpressions = [], ?string $inClosureBindScopeClass = null, ?ParametersAcceptor $anonymousFunctionReflection = null, bool $inFirstLevelStatement = true, array $currentlyAssignedExpressions = [], array $currentlyAllowedUndefinedExpressions = [], - array $nativeExpressionTypes = [], array $inFunctionCallsStack = [], bool $afterExtractCall = false, ?Scope $parentScope = null, diff --git a/src/Analyser/LazyInternalScopeFactory.php b/src/Analyser/LazyInternalScopeFactory.php index ad28564049..bd8d6d92fd 100644 --- a/src/Analyser/LazyInternalScopeFactory.php +++ b/src/Analyser/LazyInternalScopeFactory.php @@ -39,10 +39,10 @@ public function __construct( /** * @param array $expressionTypes + * @param array $nativeExpressionTypes * @param array $conditionalExpressions * @param array $currentlyAssignedExpressions * @param array $currentlyAllowedUndefinedExpressions - * @param array $nativeExpressionTypes * @param array<(FunctionReflection|MethodReflection)> $inFunctionCallsStack * */ @@ -52,13 +52,13 @@ public function create( FunctionReflection|MethodReflection|null $function = null, ?string $namespace = null, array $expressionTypes = [], + array $nativeExpressionTypes = [], array $conditionalExpressions = [], ?string $inClosureBindScopeClass = null, ?ParametersAcceptor $anonymousFunctionReflection = null, bool $inFirstLevelStatement = true, array $currentlyAssignedExpressions = [], array $currentlyAllowedUndefinedExpressions = [], - array $nativeExpressionTypes = [], array $inFunctionCallsStack = [], bool $afterExtractCall = false, ?Scope $parentScope = null, @@ -87,13 +87,13 @@ public function create( $function, $namespace, $expressionTypes, + $nativeExpressionTypes, $conditionalExpressions, $inClosureBindScopeClass, $anonymousFunctionReflection, $inFirstLevelStatement, $currentlyAssignedExpressions, $currentlyAllowedUndefinedExpressions, - $nativeExpressionTypes, $inFunctionCallsStack, $this->treatPhpDocTypesAsCertain, $afterExtractCall, diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index e9285e7970..ff232708b5 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -177,13 +177,13 @@ public function __construct( private FunctionReflection|ExtendedMethodReflection|null $function = null, ?string $namespace = null, private array $expressionTypes = [], + private array $nativeExpressionTypes = [], private array $conditionalExpressions = [], private ?string $inClosureBindScopeClass = null, private ?ParametersAcceptor $anonymousFunctionReflection = null, private bool $inFirstLevelStatement = true, private array $currentlyAssignedExpressions = [], private array $currentlyAllowedUndefinedExpressions = [], - private array $nativeExpressionTypes = [], private array $inFunctionCallsStack = [], private bool $treatPhpDocTypesAsCertain = true, private bool $afterExtractCall = false, @@ -315,13 +315,13 @@ public function afterExtractCall(): self $this->getFunction(), $this->getNamespace(), $this->expressionTypes, + $this->nativeExpressionTypes, [], $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->isInFirstLevelStatement(), $this->currentlyAssignedExpressions, $this->currentlyAllowedUndefinedExpressions, - $this->nativeExpressionTypes, $this->inFunctionCallsStack, true, $this->parentScope, @@ -370,13 +370,13 @@ public function afterClearstatcacheCall(): self $this->getFunction(), $this->getNamespace(), $expressionTypes, + $this->nativeExpressionTypes, $this->conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->isInFirstLevelStatement(), $this->currentlyAssignedExpressions, $this->currentlyAllowedUndefinedExpressions, - $this->nativeExpressionTypes, $this->inFunctionCallsStack, $this->afterExtractCall, $this->parentScope, @@ -451,13 +451,13 @@ public function afterOpenSslCall(string $openSslFunctionName): self $this->getFunction(), $this->getNamespace(), $expressionTypes, + $this->nativeExpressionTypes, $this->conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->isInFirstLevelStatement(), $this->currentlyAssignedExpressions, $this->currentlyAllowedUndefinedExpressions, - $this->nativeExpressionTypes, $this->inFunctionCallsStack, $this->afterExtractCall, $this->parentScope, @@ -2160,13 +2160,13 @@ public function doNotTreatPhpDocTypesAsCertain(): Scope $this->function, $this->namespace, $this->expressionTypes, + $this->nativeExpressionTypes, $this->conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->inFirstLevelStatement, $this->currentlyAssignedExpressions, $this->currentlyAllowedUndefinedExpressions, - $this->nativeExpressionTypes, $this->inFunctionCallsStack, false, $this->afterExtractCall, @@ -2199,13 +2199,13 @@ private function promoteNativeTypes(): self $this->function, $this->namespace, $expressionTypes, + $this->nativeExpressionTypes, $this->conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->inFirstLevelStatement, $this->currentlyAssignedExpressions, $this->currentlyAllowedUndefinedExpressions, - $this->nativeExpressionTypes, $this->inFunctionCallsStack, $this->afterExtractCall, $this->parentScope, @@ -2380,13 +2380,13 @@ public function pushInFunctionCall($reflection): self $this->getFunction(), $this->getNamespace(), $this->expressionTypes, + $this->nativeExpressionTypes, $this->conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->isInFirstLevelStatement(), $this->currentlyAssignedExpressions, $this->currentlyAllowedUndefinedExpressions, - $this->nativeExpressionTypes, $stack, $this->afterExtractCall, $this->parentScope, @@ -2409,13 +2409,13 @@ public function popInFunctionCall(): self $this->getFunction(), $this->getNamespace(), $this->expressionTypes, + $this->nativeExpressionTypes, $this->conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->isInFirstLevelStatement(), $this->currentlyAssignedExpressions, $this->currentlyAllowedUndefinedExpressions, - $this->nativeExpressionTypes, $stack, $this->afterExtractCall, $this->parentScope, @@ -2473,15 +2473,15 @@ public function enterClass(ClassReflection $classReflection): self array_merge($this->getConstantTypes(), [ '$this' => $thisHolder, ]), + array_merge($this->getNativeConstantTypes(), [ + '$this' => $thisHolder, + ]), [], null, null, true, [], [], - array_merge($this->getNativeConstantTypes(), [ - '$this' => $thisHolder, - ]), [], false, $classReflection->isAnonymous() ? $this : null, @@ -2502,13 +2502,10 @@ public function enterTrait(ClassReflection $traitReflection): self $this->getFunction(), $namespace, $this->expressionTypes, + $this->nativeExpressionTypes, [], $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, - true, - [], - [], - $this->nativeExpressionTypes, ); } @@ -2715,12 +2712,6 @@ private function enterFunctionLike( $functionReflection, $this->getNamespace(), array_merge($this->getConstantTypes(), $expressionTypes), - [], - null, - null, - true, - [], - [], array_merge($this->getNativeConstantTypes(), $nativeExpressionTypes), ); } @@ -2755,6 +2746,7 @@ public function enterClosureBind(?Type $thisType, string $scopeClass): self $this->getFunction(), $this->getNamespace(), $expressionTypes, + [], $this->conditionalExpressions, $scopeClass, $this->anonymousFunctionReflection, @@ -2776,6 +2768,7 @@ public function restoreOriginalScopeAfterClosureBind(self $originalScope): self $this->getFunction(), $this->getNamespace(), $expressionTypes, + [], $this->conditionalExpressions, $originalScope->inClosureBindScopeClass, $this->anonymousFunctionReflection, @@ -2793,6 +2786,7 @@ public function enterClosureCall(Type $thisType): self $this->getFunction(), $this->getNamespace(), $expressionTypes, + [], $this->conditionalExpressions, $thisType instanceof TypeWithClassName ? $thisType->getClassName() : null, $this->anonymousFunctionReflection, @@ -2827,13 +2821,13 @@ public function enterAnonymousFunction( $scope->getFunction(), $scope->getNamespace(), $scope->expressionTypes, + $scope->nativeExpressionTypes, [], $scope->inClosureBindScopeClass, $anonymousFunctionReflection, true, [], [], - $scope->nativeExpressionTypes, [], false, $this, @@ -2937,13 +2931,13 @@ private function enterAnonymousFunctionWithoutReflection( $this->getFunction(), $this->getNamespace(), array_merge($this->getConstantTypes(), $expressionTypes), + array_merge($this->getNativeConstantTypes(), $nativeTypes), [], $this->inClosureBindScopeClass, new TrivialParametersAcceptor(), true, [], [], - array_merge($this->getNativeConstantTypes(), $nativeTypes), [], false, $this, @@ -3004,6 +2998,7 @@ public function enterArrowFunction(Expr\ArrowFunction $arrowFunction, ?array $ca $scope->getFunction(), $scope->getNamespace(), $scope->expressionTypes, + [], $scope->conditionalExpressions, $scope->inClosureBindScopeClass, $anonymousFunctionReflection, @@ -3011,7 +3006,6 @@ public function enterArrowFunction(Expr\ArrowFunction $arrowFunction, ?array $ca [], [], [], - [], $scope->afterExtractCall, $scope->parentScope, ); @@ -3062,13 +3056,13 @@ private function enterArrowFunctionWithoutReflection(Expr\ArrowFunction $arrowFu $arrowFunctionScope->getFunction(), $arrowFunctionScope->getNamespace(), $this->invalidateStaticExpressions($arrowFunctionScope->expressionTypes), + $arrowFunctionScope->nativeExpressionTypes, $arrowFunctionScope->conditionalExpressions, $arrowFunctionScope->inClosureBindScopeClass, null, true, [], [], - $arrowFunctionScope->nativeExpressionTypes, [], $arrowFunctionScope->afterExtractCall, $arrowFunctionScope->parentScope, @@ -3191,13 +3185,13 @@ public function enterExpressionAssign(Expr $expr): self $this->getFunction(), $this->getNamespace(), $this->expressionTypes, + $this->nativeExpressionTypes, $this->conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->isInFirstLevelStatement(), $currentlyAssignedExpressions, $this->currentlyAllowedUndefinedExpressions, - $this->nativeExpressionTypes, [], $this->afterExtractCall, $this->parentScope, @@ -3221,13 +3215,13 @@ public function exitExpressionAssign(Expr $expr): self $this->getFunction(), $this->getNamespace(), $this->expressionTypes, + $this->nativeExpressionTypes, $this->conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->isInFirstLevelStatement(), $currentlyAssignedExpressions, $this->currentlyAllowedUndefinedExpressions, - $this->nativeExpressionTypes, [], $this->afterExtractCall, $this->parentScope, @@ -3262,13 +3256,13 @@ public function setAllowedUndefinedExpression(Expr $expr): self $this->getFunction(), $this->getNamespace(), $this->expressionTypes, + $this->nativeExpressionTypes, $this->conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->isInFirstLevelStatement(), $this->currentlyAssignedExpressions, $currentlyAllowedUndefinedExpressions, - $this->nativeExpressionTypes, [], $this->afterExtractCall, $this->parentScope, @@ -3292,13 +3286,13 @@ public function unsetAllowedUndefinedExpression(Expr $expr): self $this->getFunction(), $this->getNamespace(), $this->expressionTypes, + $this->nativeExpressionTypes, $this->conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->isInFirstLevelStatement(), $this->currentlyAssignedExpressions, $currentlyAllowedUndefinedExpressions, - $this->nativeExpressionTypes, [], $this->afterExtractCall, $this->parentScope, @@ -3430,13 +3424,13 @@ public function specifyExpressionType(Expr $expr, Type $type, Type $nativeType): $this->getFunction(), $this->getNamespace(), $expressionTypes, + $nativeTypes, $this->conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->inFirstLevelStatement, $this->currentlyAssignedExpressions, $this->currentlyAllowedUndefinedExpressions, - $nativeTypes, $this->inFunctionCallsStack, $this->afterExtractCall, $this->parentScope, @@ -3508,13 +3502,13 @@ public function invalidateExpression(Expr $expressionToInvalidate, bool $require $this->getFunction(), $this->getNamespace(), $expressionTypes, + $nativeExpressionTypes, $newConditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->inFirstLevelStatement, $this->currentlyAssignedExpressions, $this->currentlyAllowedUndefinedExpressions, - $nativeExpressionTypes, [], $this->afterExtractCall, $this->parentScope, @@ -3587,13 +3581,13 @@ private function invalidateMethodsOnExpression(Expr $expressionToInvalidate): se $this->getFunction(), $this->getNamespace(), $expressionTypes, + $nativeExpressionTypes, $this->conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->inFirstLevelStatement, $this->currentlyAssignedExpressions, $this->currentlyAllowedUndefinedExpressions, - $nativeExpressionTypes, [], $this->afterExtractCall, $this->parentScope, @@ -3749,13 +3743,13 @@ public function filterBySpecifiedTypes(SpecifiedTypes $specifiedTypes): self $scope->getFunction(), $scope->getNamespace(), $scope->expressionTypes, + $scope->nativeExpressionTypes, $newConditionalExpressions, $scope->inClosureBindScopeClass, $scope->anonymousFunctionReflection, $scope->inFirstLevelStatement, $scope->currentlyAssignedExpressions, $scope->currentlyAllowedUndefinedExpressions, - $scope->nativeExpressionTypes, $scope->inFunctionCallsStack, $scope->afterExtractCall, $scope->parentScope, @@ -3775,13 +3769,13 @@ public function addConditionalExpressions(string $exprString, array $conditional $this->getFunction(), $this->getNamespace(), $this->expressionTypes, + $this->nativeExpressionTypes, $conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->inFirstLevelStatement, $this->currentlyAssignedExpressions, $this->currentlyAllowedUndefinedExpressions, - $this->nativeExpressionTypes, $this->inFunctionCallsStack, $this->afterExtractCall, $this->parentScope, @@ -3804,13 +3798,13 @@ public function exitFirstLevelStatements(): self $this->getFunction(), $this->getNamespace(), $this->expressionTypes, + $this->nativeExpressionTypes, $this->conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, false, $this->currentlyAssignedExpressions, $this->currentlyAllowedUndefinedExpressions, - $this->nativeExpressionTypes, $this->inFunctionCallsStack, $this->afterExtractCall, $this->parentScope, @@ -3857,13 +3851,13 @@ public function mergeWith(?self $otherScope): self $this->getFunction(), $this->getNamespace(), $mergedExpressionTypes, + $this->mergeVariableHolders($this->nativeExpressionTypes, $otherScope->nativeExpressionTypes), $conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->inFirstLevelStatement, [], [], - $this->mergeVariableHolders($this->nativeExpressionTypes, $otherScope->nativeExpressionTypes), [], $this->afterExtractCall && $otherScope->afterExtractCall, $this->parentScope, @@ -4011,17 +4005,17 @@ public function processFinallyScope(self $finallyScope, self $originalFinallySco $finallyScope->expressionTypes, $originalFinallyScope->expressionTypes, ), + $this->processFinallyScopeVariableTypeHolders( + $this->nativeExpressionTypes, + $finallyScope->nativeExpressionTypes, + $originalFinallyScope->nativeExpressionTypes, + ), $this->conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->inFirstLevelStatement, [], [], - $this->processFinallyScopeVariableTypeHolders( - $this->nativeExpressionTypes, - $finallyScope->nativeExpressionTypes, - $originalFinallyScope->nativeExpressionTypes, - ), [], $this->afterExtractCall, $this->parentScope, @@ -4109,13 +4103,13 @@ public function processClosureScope( $this->getFunction(), $this->getNamespace(), $expressionTypes, + $nativeExpressionTypes, $this->conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->inFirstLevelStatement, [], [], - $nativeExpressionTypes, $this->inFunctionCallsStack, $this->afterExtractCall, $this->parentScope, @@ -4157,13 +4151,13 @@ public function processAlwaysIterableForeachScopeWithoutPollute(self $finalScope $this->getFunction(), $this->getNamespace(), $expressionTypes, + $nativeTypes, $this->conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->inFirstLevelStatement, [], [], - $nativeTypes, [], $this->afterExtractCall, $this->parentScope, @@ -4187,13 +4181,13 @@ public function generalizeWith(self $otherScope): self $this->getFunction(), $this->getNamespace(), $variableTypeHolders, + $nativeTypes, $this->conditionalExpressions, $this->inClosureBindScopeClass, $this->anonymousFunctionReflection, $this->inFirstLevelStatement, [], [], - $nativeTypes, [], $this->afterExtractCall, $this->parentScope,