Skip to content

Commit a56ab53

Browse files
committed
Rework exactInstantiation a bit
1 parent 20042cb commit a56ab53

File tree

1 file changed

+4
-39
lines changed

1 file changed

+4
-39
lines changed

src/Analyser/MutatingScope.php

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
16901690
);
16911691
} elseif ($node instanceof New_) {
16921692
if ($node->class instanceof Name) {
1693-
$type = $this->exactInstantiation($node, $node->class->toString());
1693+
$type = $this->exactInstantiation($node, $node->class);
16941694
if ($type !== null) {
16951695
return $type;
16961696
}
@@ -2778,30 +2778,6 @@ private function getTypeFromArrayDimFetch(
27782778
return $offsetAccessibleType->getOffsetValueType($offsetType);
27792779
}
27802780

2781-
private function resolveExactName(string $name): ?string
2782-
{
2783-
switch (strtolower($name)) {
2784-
case 'self':
2785-
if (!$this->isInClass()) {
2786-
return null;
2787-
}
2788-
return $this->getClassReflection()->getName();
2789-
case 'parent':
2790-
if (!$this->isInClass()) {
2791-
return null;
2792-
}
2793-
$currentClassReflection = $this->getClassReflection();
2794-
if ($currentClassReflection->getParentClass() !== null) {
2795-
return $currentClassReflection->getParentClass()->getName();
2796-
}
2797-
return null;
2798-
case 'static':
2799-
return null;
2800-
}
2801-
2802-
return $name;
2803-
}
2804-
28052781
/** @api */
28062782
public function resolveName(Name $name): string
28072783
{
@@ -5814,22 +5790,11 @@ public function debug(): array
58145790
return $descriptions;
58155791
}
58165792

5817-
/**
5818-
* @param non-empty-string $className
5819-
*/
5820-
private function exactInstantiation(New_ $node, string $className): ?Type
5793+
private function exactInstantiation(New_ $node, Name $className): ?Type
58215794
{
5822-
$resolvedClassName = $this->resolveExactName($className);
5795+
$resolvedClassName = $this->resolveName($className);
58235796
$isStatic = false;
5824-
if ($resolvedClassName === null) {
5825-
if (strtolower($className) !== 'static') {
5826-
return null;
5827-
}
5828-
5829-
if (!$this->isInClass()) {
5830-
return null;
5831-
}
5832-
$resolvedClassName = $this->getClassReflection()->getName();
5797+
if ($className->toLowerString() === 'static') {
58335798
$isStatic = true;
58345799
}
58355800

0 commit comments

Comments
 (0)