Skip to content

Commit 3e971c8

Browse files
committed
fix
1 parent 2fe6341 commit 3e971c8

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

src/Analyser/MutatingScope.php

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,7 @@ public function hasConstant(Name $name): bool
610610
return $this->fileHasCompilerHaltStatementCalls();
611611
}
612612

613-
if (!$name->isFullyQualified() && $this->getNamespace() !== null) {
614-
if ($this->hasExpressionType(new ConstFetch(new FullyQualified([$this->getNamespace(), $name->toString()])))->yes()) {
615-
return true;
616-
}
617-
}
618-
if ($this->hasExpressionType(new ConstFetch(new FullyQualified($name->toString())))->yes()) {
613+
if ($this->getGlobalConstantType($name) !== null) {
619614
return true;
620615
}
621616

@@ -5685,6 +5680,25 @@ private function getConstantTypes(): array
56855680
return $constantTypes;
56865681
}
56875682

5683+
private function getGlobalConstantType(Name $name): ?Type
5684+
{
5685+
$fetches = [];
5686+
if (!$name->isFullyQualified() && $this->getNamespace() !== null) {
5687+
$fetches[] = new ConstFetch(new FullyQualified([$this->getNamespace(), $name->toString()]));
5688+
}
5689+
5690+
$fetches[] = new ConstFetch(new FullyQualified($name->toString()));
5691+
$fetches[] = new ConstFetch($name);
5692+
5693+
foreach($fetches as $constFetch) {
5694+
if ($this->hasExpressionType($constFetch)->yes()) {
5695+
return $this->getType($constFetch);
5696+
}
5697+
}
5698+
5699+
return null;
5700+
}
5701+
56885702
/**
56895703
* @return array<string, ExpressionTypeHolder>
56905704
*/
@@ -5727,15 +5741,15 @@ public function getIterableValueType(Type $iteratee): Type
57275741

57285742
public function getPhpVersion(): PhpVersions
57295743
{
5730-
$name = new Name('PHP_VERSION_ID');
5731-
if (!$this->hasConstant($name)) {
5732-
if (is_array($this->configPhpVersion)) {
5733-
return new PhpVersions(IntegerRangeType::fromInterval($this->configPhpVersion['min'], $this->configPhpVersion['max']));
5734-
}
5735-
return new PhpVersions(new ConstantIntegerType($this->phpVersion->getVersionId()));
5744+
$constType = $this->getGlobalConstantType(new Name('PHP_VERSION_ID'));
5745+
if ($constType !== null) {
5746+
return new PhpVersions($constType);
57365747
}
57375748

5738-
return new PhpVersions($this->getType(new ConstFetch($name)));
5749+
if (is_array($this->configPhpVersion)) {
5750+
return new PhpVersions(IntegerRangeType::fromInterval($this->configPhpVersion['min'], $this->configPhpVersion['max']));
5751+
}
5752+
return new PhpVersions(new ConstantIntegerType($this->phpVersion->getVersionId()));
57395753
}
57405754

57415755
}

0 commit comments

Comments
 (0)