Skip to content

Commit a2aeea1

Browse files
committed
fix
1 parent 92ad9d2 commit a2aeea1

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

@@ -5686,6 +5681,25 @@ private function getConstantTypes(): array
56865681
return $constantTypes;
56875682
}
56885683

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

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

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

57425756
}

0 commit comments

Comments
 (0)