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 Nov 24, 2022
1 parent 6991b85 commit 51ddfcc
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/Analyser/MutatingScope.php
Expand Up @@ -2446,8 +2446,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 @@ -2683,8 +2683,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 @@ -2696,8 +2696,8 @@ public function enterNamespace(string $namespaceName): self
$this->isDeclareStrictTypes(),
null,
$namespaceName,
$this->getSuperglobalExpressionTypes(),
$this->getSuperglobalExpressionTypes(),
$this->getSuperglobalTypes(),
$this->getNativeSuperglobalTypes(),
);
}

Expand Down Expand Up @@ -2921,8 +2921,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 @@ -4994,18 +4994,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 51ddfcc

Please sign in to comment.