Skip to content

Commit 8a39cd2

Browse files
committed
Remove deprecated instanceof Type checks
1 parent 949f032 commit 8a39cd2

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/bitExpert/PHPStan/Magento/Type/ObjectManagerDynamicReturnTypeExtension.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,15 @@ public function getTypeFromMethodCall(
6464
/** @var \PhpParser\Node\Arg[] $args */
6565
$args = $methodCall->args;
6666
$argType = $scope->getType($args[0]->value);
67-
if (!$argType instanceof ConstantStringType) {
67+
if ($argType->getConstantStrings() === []) {
6868
return $mixedType;
6969
}
70-
return TypeCombinator::addNull(new ObjectType($argType->getValue()));
70+
71+
$types = [];
72+
foreach ($argType->getConstantStrings() as $constantString) {
73+
$types[] = TypeCombinator::addNull(new ObjectType($constantString->getValue()));
74+
}
75+
76+
return TypeCombinator::union(...$types);
7177
}
7278
}

src/bitExpert/PHPStan/Magento/Type/TestFrameworkObjectManagerDynamicReturnTypeExtension.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,16 @@ private function getTypeForGetObjectMethodCall(
9292
/** @var \PhpParser\Node\Arg[] $args */
9393
$args = $methodCall->args;
9494
$argType = $scope->getType($args[0]->value);
95-
if (!$argType instanceof ConstantStringType) {
95+
if ($argType->getConstantStrings() === []) {
9696
return $mixedType;
9797
}
98-
return TypeCombinator::addNull(new ObjectType($argType->getValue()));
98+
99+
$types = [];
100+
foreach ($argType->getConstantStrings() as $constantString) {
101+
$types[] = TypeCombinator::addNull(new ObjectType($constantString->getValue()));
102+
}
103+
104+
return TypeCombinator::union(...$types);
99105
}
100106

101107
/**

0 commit comments

Comments
 (0)