Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Dec 20, 2024
1 parent 92ad9d2 commit a2aeea1
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,7 @@ public function hasConstant(Name $name): bool
return $this->fileHasCompilerHaltStatementCalls();
}

if (!$name->isFullyQualified() && $this->getNamespace() !== null) {
if ($this->hasExpressionType(new ConstFetch(new FullyQualified([$this->getNamespace(), $name->toString()])))->yes()) {
return true;
}
}
if ($this->hasExpressionType(new ConstFetch(new FullyQualified($name->toString())))->yes()) {
if ($this->getGlobalConstantType($name) !== null) {
return true;
}

Expand Down Expand Up @@ -5686,6 +5681,25 @@ private function getConstantTypes(): array
return $constantTypes;
}

private function getGlobalConstantType(Name $name): ?Type
{
$fetches = [];
if (!$name->isFullyQualified() && $this->getNamespace() !== null) {
$fetches[] = new ConstFetch(new FullyQualified([$this->getNamespace(), $name->toString()]));
}

$fetches[] = new ConstFetch(new FullyQualified($name->toString()));
$fetches[] = new ConstFetch($name);

foreach($fetches as $constFetch) {
if ($this->hasExpressionType($constFetch)->yes()) {
return $this->getType($constFetch);
}
}

return null;
}

/**
* @return array<string, ExpressionTypeHolder>
*/
Expand Down Expand Up @@ -5728,15 +5742,15 @@ public function getIterableValueType(Type $iteratee): Type

public function getPhpVersion(): PhpVersions
{
$name = new Name('PHP_VERSION_ID');
if (!$this->hasConstant($name)) {
if (is_array($this->configPhpVersion)) {
return new PhpVersions(IntegerRangeType::fromInterval($this->configPhpVersion['min'], $this->configPhpVersion['max']));
}
return new PhpVersions(new ConstantIntegerType($this->phpVersion->getVersionId()));
$constType = $this->getGlobalConstantType(new Name('PHP_VERSION_ID'));
if ($constType !== null) {
return new PhpVersions($constType);
}

return new PhpVersions($this->getType(new ConstFetch($name)));
if (is_array($this->configPhpVersion)) {
return new PhpVersions(IntegerRangeType::fromInterval($this->configPhpVersion['min'], $this->configPhpVersion['max']));
}
return new PhpVersions(new ConstantIntegerType($this->phpVersion->getVersionId()));
}

}

0 comments on commit a2aeea1

Please sign in to comment.