Skip to content

Commit 91d3962

Browse files
Improve
1 parent 021e818 commit 91d3962

File tree

4 files changed

+17
-32
lines changed

4 files changed

+17
-32
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
use PHPStan\Type\TypeTraverser;
198198
use PHPStan\Type\TypeUtils;
199199
use PHPStan\Type\UnionType;
200+
use PHPStan\Type\VerbosityLevel;
200201
use ReflectionProperty;
201202
use Throwable;
202203
use Traversable;
@@ -4260,18 +4261,6 @@ private function getMethodThrowPoint(MethodReflection $methodReflection, Paramet
42604261

42614262
if ($throwType !== null) {
42624263
if (!$throwType->isVoid()->yes()) {
4263-
if ($throwType instanceof StaticType) {
4264-
$classReflections = $scope->getType($methodCall->var)->getObjectClassReflections();
4265-
if (count($classReflections) > 0) {
4266-
$types = [];
4267-
foreach ($classReflections as $classReflection) {
4268-
$types[] = $throwType->changeBaseClass($classReflection);
4269-
}
4270-
4271-
$throwType = TypeCombinator::union(...$types);
4272-
}
4273-
}
4274-
42754264
return ThrowPoint::createExplicit($scope, $throwType, $methodCall, true);
42764265
}
42774266
} elseif ($this->implicitThrows) {
@@ -4345,25 +4334,6 @@ private function getStaticMethodThrowPoint(MethodReflection $methodReflection, P
43454334
if ($methodReflection->getThrowType() !== null) {
43464335
$throwType = $methodReflection->getThrowType();
43474336
if (!$throwType->isVoid()->yes()) {
4348-
if ($throwType instanceof StaticType) {
4349-
if ($methodCall->class instanceof Name) {
4350-
if ($this->reflectionProvider->hasClass($methodCall->class->name)) {
4351-
$throwType = $throwType->changeBaseClass($this->reflectionProvider->getClass($methodCall->class->name));
4352-
}
4353-
} else {
4354-
$classReflections = $scope->getType($methodCall->class)->getObjectClassReflections();
4355-
4356-
if (count($classReflections) > 0) {
4357-
$types = [];
4358-
foreach ($classReflections as $classReflection) {
4359-
$types[] = $throwType->changeBaseClass($classReflection);
4360-
}
4361-
4362-
$throwType = TypeCombinator::union(...$types);
4363-
}
4364-
}
4365-
}
4366-
43674337
return ThrowPoint::createExplicit($scope, $throwType, $methodCall, true);
43684338
}
43694339
} elseif ($this->implicitThrows) {

src/Reflection/Dummy/ChangedTypeMethodReflection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function __construct(
2626
private array $variants,
2727
private ?array $namedArgumentsVariants,
2828
private ?Type $selfOutType,
29+
private ?Type $throwType,
2930
)
3031
{
3132
}
@@ -122,7 +123,7 @@ public function isBuiltin(): TrinaryLogic
122123

123124
public function getThrowType(): ?Type
124125
{
125-
return $this->reflection->getThrowType();
126+
return $this->throwType;
126127
}
127128

128129
public function hasSideEffects(): TrinaryLogic

src/Reflection/Type/CallbackUnresolvedMethodPrototypeReflection.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use PHPStan\Type\ThisType;
1414
use PHPStan\Type\Type;
1515
use PHPStan\Type\TypeCombinator;
16+
use PHPStan\Type\VerbosityLevel;
17+
1618
use function array_map;
1719

1820
final class CallbackUnresolvedMethodPrototypeReflection implements UnresolvedMethodPrototypeReflection
@@ -125,13 +127,18 @@ private function transformMethodWithStaticType(ClassReflection $declaringClass,
125127
$namedArgumentVariants = $namedArgumentVariants !== null
126128
? array_map($variantFn, $namedArgumentVariants)
127129
: null;
130+
$throwType = $method->getThrowType();
131+
$throwType = $throwType !== null
132+
? $this->transformStaticType($throwType)
133+
: null;
128134

129135
return new ChangedTypeMethodReflection(
130136
$declaringClass,
131137
$method,
132138
$variants,
133139
$namedArgumentVariants,
134140
$selfOutType,
141+
$throwType
135142
);
136143
}
137144

src/Reflection/Type/CalledOnTypeUnresolvedMethodPrototypeReflection.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use PHPStan\Type\ThisType;
1616
use PHPStan\Type\Type;
1717
use PHPStan\Type\TypeTraverser;
18+
use PHPStan\Type\VerbosityLevel;
19+
1820
use function array_map;
1921
use function count;
2022

@@ -120,13 +122,18 @@ private function transformMethodWithStaticType(ClassReflection $declaringClass,
120122
$namedArgumentsVariants = $namedArgumentsVariants !== null
121123
? array_map($variantFn, $namedArgumentsVariants)
122124
: null;
125+
$throwType = $method->getThrowType();
126+
$throwType = $throwType !== null
127+
? $this->transformStaticType($throwType)
128+
: null;
123129

124130
return new ChangedTypeMethodReflection(
125131
$declaringClass,
126132
$method,
127133
$variants,
128134
$namedArgumentsVariants,
129135
$selfOutType,
136+
$throwType
130137
);
131138
}
132139

0 commit comments

Comments
 (0)