Skip to content

Commit 1fbad55

Browse files
committed
Inline one-line wrappers around polymorphic Type methods
Follow-up cleanup across #5611, #5612, #5613: - `FuncCallHandler::getArrayWalkResultType()` and `getArraySortDoNotPreserveListFunctionType()` were single-statement wrappers around `Type::mapValueType()` / `Type::makeListMaybe()`. Both private, both fully replaced by their polymorphic call; inline at the two/one call sites and delete the helpers. - `InstanceofHandler` and `TypeSpecifier` (the `instanceof <expr>` branch) used a throwaway `$classType = $scope->getType(...)` only to immediately overwrite it with `$result->type`. Drop the intermediate; chain the call. Pure simplification: full test suite + phpstan + cs pass.
1 parent 4863c88 commit 1fbad55

3 files changed

Lines changed: 7 additions & 17 deletions

File tree

src/Analyser/ExprHandler/FuncCallHandler.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,10 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
273273
$isAlwaysTerminating = $isAlwaysTerminating || $argsResult->isAlwaysTerminating();
274274

275275
if ($arrayWalkValueTypes !== null && $arrayWalkArrayArg !== null) {
276-
$newArrayType = $this->getArrayWalkResultType($arrayWalkOriginalArrayType, $arrayWalkValueTypes[0]);
277-
$newArrayNativeType = $this->getArrayWalkResultType($arrayWalkOriginalArrayNativeType, $arrayWalkValueTypes[1]);
276+
$arrayWalkValueType = $arrayWalkValueTypes[0];
277+
$arrayWalkValueNativeType = $arrayWalkValueTypes[1];
278+
$newArrayType = $arrayWalkOriginalArrayType->mapValueType(static fn (Type $type): Type => $arrayWalkValueType);
279+
$newArrayNativeType = $arrayWalkOriginalArrayNativeType->mapValueType(static fn (Type $type): Type => $arrayWalkValueNativeType);
278280

279281
$scope = $nodeScopeResolver->processVirtualAssign(
280282
$scope,
@@ -478,7 +480,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
478480
$storage,
479481
$stmt,
480482
$arrayArg,
481-
new NativeTypeExpr($this->getArraySortDoNotPreserveListFunctionType($scope->getType($arrayArg)), $this->getArraySortDoNotPreserveListFunctionType($scope->getNativeType($arrayArg))),
483+
new NativeTypeExpr($scope->getType($arrayArg)->makeListMaybe(), $scope->getNativeType($arrayArg)->makeListMaybe()),
482484
$nodeCallback,
483485
)->getScope();
484486
}
@@ -721,16 +723,6 @@ static function (?Type $offsetType, Type $valueType, bool $optional) use (&$arra
721723
return $arrayType;
722724
}
723725

724-
private function getArraySortDoNotPreserveListFunctionType(Type $type): Type
725-
{
726-
return $type->makeListMaybe();
727-
}
728-
729-
private function getArrayWalkResultType(Type $arrayType, Type $newValueType): Type
730-
{
731-
return $arrayType->mapValueType(static fn (Type $type): Type => $newValueType);
732-
}
733-
734726
public function resolveType(MutatingScope $scope, Expr $expr): Type
735727
{
736728
if ($expr->name instanceof Expr) {

src/Analyser/ExprHandler/InstanceofHandler.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ public function resolveType(MutatingScope $scope, Expr $expr): Type
9191
$classType = new ObjectType($className);
9292
}
9393
} else {
94-
$classType = $scope->getType($expr->class);
95-
$result = $classType->toObjectTypeForInstanceofCheck();
94+
$result = $scope->getType($expr->class)->toObjectTypeForInstanceofCheck();
9695
$classType = $result->type;
9796
$uncertainty = $result->uncertainty;
9897
}

src/Analyser/TypeSpecifier.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ public function specifyTypesInCondition(
164164
return $this->create($exprNode, $type, $context, $scope)->setRootExpr($expr);
165165
}
166166

167-
$classType = $scope->getType($expr->class);
168-
$result = $classType->toObjectTypeForInstanceofCheck();
167+
$result = $scope->getType($expr->class)->toObjectTypeForInstanceofCheck();
169168
$type = $result->type;
170169
$uncertainty = $result->uncertainty;
171170

0 commit comments

Comments
 (0)