Skip to content

Commit afa2bdb

Browse files
Improve
1 parent 021e818 commit afa2bdb

File tree

4 files changed

+13
-32
lines changed

4 files changed

+13
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,18 @@ private function transformMethodWithStaticType(ClassReflection $declaringClass,
125125
$namedArgumentVariants = $namedArgumentVariants !== null
126126
? array_map($variantFn, $namedArgumentVariants)
127127
: null;
128+
$throwType = $method->getThrowType();
129+
$throwType = $throwType !== null
130+
? $this->transformStaticType($throwType)
131+
: null;
128132

129133
return new ChangedTypeMethodReflection(
130134
$declaringClass,
131135
$method,
132136
$variants,
133137
$namedArgumentVariants,
134138
$selfOutType,
139+
$throwType
135140
);
136141
}
137142

src/Reflection/Type/CalledOnTypeUnresolvedMethodPrototypeReflection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,18 @@ private function transformMethodWithStaticType(ClassReflection $declaringClass,
120120
$namedArgumentsVariants = $namedArgumentsVariants !== null
121121
? array_map($variantFn, $namedArgumentsVariants)
122122
: null;
123+
$throwType = $method->getThrowType();
124+
$throwType = $throwType !== null
125+
? $this->transformStaticType($throwType)
126+
: null;
123127

124128
return new ChangedTypeMethodReflection(
125129
$declaringClass,
126130
$method,
127131
$variants,
128132
$namedArgumentsVariants,
129133
$selfOutType,
134+
$throwType
130135
);
131136
}
132137

0 commit comments

Comments
 (0)