Skip to content

Commit 323d155

Browse files
phpstan-botclaude
andcommitted
Add scope parameter to InternalThrowPoint::createFromPublic instead of replaceScope
Move the scope replacement into createFromPublic() as an optional parameter, removing the separate replaceScope() method as suggested in code review. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4afa331 commit 323d155

2 files changed

Lines changed: 7 additions & 10 deletions

File tree

src/Analyser/ExprHandler/NewHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
190190
$constructorResult = $node;
191191
}, StatementContext::createTopLevel());
192192
if ($constructorResult !== null) {
193-
$throwPoints = array_map(static fn (ThrowPoint $point): InternalThrowPoint => InternalThrowPoint::createFromPublic($point)->replaceScope($scope), $constructorResult->getStatementResult()->getThrowPoints());
193+
$throwPoints = array_map(static fn (ThrowPoint $point): InternalThrowPoint => InternalThrowPoint::createFromPublic($point, $scope), $constructorResult->getStatementResult()->getThrowPoints());
194194
$impurePoints = $constructorResult->getImpurePoints();
195195
}
196196
} else {

src/Analyser/InternalThrowPoint.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ public static function createImplicit(MutatingScope $scope, Node $node): self
5050
return new self($scope, new ObjectType(Throwable::class), $node, explicit: false, canContainAnyThrowable: true);
5151
}
5252

53-
public static function createFromPublic(ThrowPoint $throwPoint): self
53+
public static function createFromPublic(ThrowPoint $throwPoint, ?MutatingScope $scope = null): self
5454
{
55-
$scope = $throwPoint->getScope();
56-
if (!$scope instanceof MutatingScope) {
57-
throw new ShouldNotHappenException();
55+
if ($scope === null) {
56+
$scope = $throwPoint->getScope();
57+
if (!$scope instanceof MutatingScope) {
58+
throw new ShouldNotHappenException();
59+
}
5860
}
5961

6062
return new self($scope, $throwPoint->getType(), $throwPoint->getNode(), $throwPoint->isExplicit(), $throwPoint->canContainAnyThrowable());
@@ -88,11 +90,6 @@ public function canContainAnyThrowable(): bool
8890
return $this->canContainAnyThrowable;
8991
}
9092

91-
public function replaceScope(MutatingScope $scope): self
92-
{
93-
return new self($scope, $this->type, $this->node, $this->explicit, $this->canContainAnyThrowable);
94-
}
95-
9693
public function subtractCatchType(Type $catchType): self
9794
{
9895
return new self($this->scope, TypeCombinator::remove($this->type, $catchType), $this->node, $this->explicit, $this->canContainAnyThrowable);

0 commit comments

Comments
 (0)