Skip to content

Commit

Permalink
Handle native superglobals separately
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm committed Dec 2, 2022
1 parent a937633 commit 5c856d7
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/Analyser/MutatingScope.php
Expand Up @@ -2447,8 +2447,8 @@ public function enterClass(ClassReflection $classReflection): self
$this->isDeclareStrictTypes(),
null,
$this->getNamespace(),
array_merge($this->getSuperglobalExpressionTypes(), $this->getConstantTypes(), ['$this' => $thisHolder]),
array_merge($this->getSuperglobalExpressionTypes(), $this->getNativeConstantTypes(), ['$this' => $thisHolder]),
array_merge($this->getSuperglobalTypes(), $this->getConstantTypes(), ['$this' => $thisHolder]),
array_merge($this->getNativeSuperglobalTypes(), $this->getNativeConstantTypes(), ['$this' => $thisHolder]),
[],
null,
null,
Expand Down Expand Up @@ -2684,8 +2684,8 @@ private function enterFunctionLike(
$this->isDeclareStrictTypes(),
$functionReflection,
$this->getNamespace(),
array_merge($this->getSuperglobalExpressionTypes(), $this->getConstantTypes(), $expressionTypes),
array_merge($this->getSuperglobalExpressionTypes(), $this->getNativeConstantTypes(), $nativeExpressionTypes),
array_merge($this->getSuperglobalTypes(), $this->getConstantTypes(), $expressionTypes),
array_merge($this->getNativeSuperglobalTypes(), $this->getNativeConstantTypes(), $nativeExpressionTypes),
);
}

Expand All @@ -2697,8 +2697,8 @@ public function enterNamespace(string $namespaceName): self
$this->isDeclareStrictTypes(),
null,
$namespaceName,
$this->getSuperglobalExpressionTypes(),
$this->getSuperglobalExpressionTypes(),
$this->getSuperglobalTypes(),
$this->getNativeSuperglobalTypes(),
);
}

Expand Down Expand Up @@ -2922,8 +2922,8 @@ private function enterAnonymousFunctionWithoutReflection(
$this->isDeclareStrictTypes(),
$this->getFunction(),
$this->getNamespace(),
array_merge($this->getSuperglobalExpressionTypes(), $this->getConstantTypes(), $expressionTypes),
array_merge($this->getSuperglobalExpressionTypes(), $this->getNativeConstantTypes(), $nativeTypes),
array_merge($this->getSuperglobalTypes(), $this->getConstantTypes(), $expressionTypes),
array_merge($this->getNativeSuperglobalTypes(), $this->getNativeConstantTypes(), $nativeTypes),
[],
$this->inClosureBindScopeClass,
new TrivialParametersAcceptor(),
Expand Down Expand Up @@ -4991,18 +4991,33 @@ private function getNativeConstantTypes(): array
}

/** @return array<string, ExpressionTypeHolder> */
private function getSuperglobalExpressionTypes(): array
private function getSuperglobalTypes(): array
{
$superglobalExpressionTypes = [];
$superglobalTypes = [];
$exprStrings = ['$GLOBALS', '$_SERVER', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_REQUEST', '$_ENV'];
foreach ($this->expressionTypes as $exprString => $typeHolder) {
if (!in_array($exprString, $exprStrings, true)) {
continue;
}

$superglobalExpressionTypes[$exprString] = $typeHolder;
$superglobalTypes[$exprString] = $typeHolder;
}
return $superglobalExpressionTypes;
return $superglobalTypes;
}

/** @return array<string, ExpressionTypeHolder> */
private function getNativeSuperglobalTypes(): array
{
$superglobalTypes = [];
$exprStrings = ['$GLOBALS', '$_SERVER', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_REQUEST', '$_ENV'];
foreach ($this->nativeExpressionTypes as $exprString => $typeHolder) {
if (!in_array($exprString, $exprStrings, true)) {
continue;
}

$superglobalTypes[$exprString] = $typeHolder;
}
return $superglobalTypes;
}

}

0 comments on commit 5c856d7

Please sign in to comment.