Skip to content

Commit 4784273

Browse files
committed
Added proxy method to fix deprecation warnings
1 parent fc18507 commit 4784273

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

hooks/TestCaseHandler.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public static function afterStatementAnalysis(
207207
Type::getArray(),
208208
]);
209209

210-
foreach ($provider_return_type->getTypes() as $type) {
210+
foreach (self::getAtomics($provider_return_type) as $type) {
211211
if (!$type->isIterable($codebase)) {
212212
IssueBuffer::accepts(new Issue\InvalidReturnType(
213213
'Providers must return ' . $expected_provider_return_type->getId()
@@ -320,7 +320,7 @@ function (
320320
};
321321

322322
/** @var Type\Atomic\TArray|Type\Atomic\ObjectLike|Type\Atomic\TList $dataset_type */
323-
$dataset_type = $provider_return_type->type_params[1]->getTypes()['array'];
323+
$dataset_type = self::getAtomics($provider_return_type->type_params[1])['array'];
324324

325325
if ($dataset_type instanceof Type\Atomic\TArray) {
326326
// check that all of the required (?) params accept value type
@@ -372,7 +372,7 @@ function (
372372

373373
assert(null !== $param->type);
374374
if ($param->is_variadic) {
375-
$param_types = $param->type->getTypes();
375+
$param_types = self::getAtomics($param->type);
376376
$variadic_param_type = new Type\Union(array_values($param_types));
377377

378378
// check remaining argument types
@@ -395,6 +395,18 @@ function (
395395
}
396396
}
397397

398+
/** @return Type\Atomic[] */
399+
private static function getAtomics(Type\Union $union): array
400+
{
401+
if (method_exists($union, 'getAtomicTypes')) {
402+
/** @var Type\Atomic[] annotated for versions missing the method */
403+
return $union->getAtomicTypes();
404+
} else {
405+
/** @psalm-suppress DeprecatedMethod annotated for newer versions that deprecated the method */
406+
return $union->getTypes();
407+
}
408+
}
409+
398410
private static function unionizeIterables(Codebase $codebase, Type\Union $iterables): Type\Atomic\TIterable
399411
{
400412
/** @var Type\Union[] $key_types */
@@ -403,7 +415,7 @@ private static function unionizeIterables(Codebase $codebase, Type\Union $iterab
403415
/** @var Type\Union[] $value_types */
404416
$value_types = [];
405417

406-
foreach ($iterables->getTypes() as $type) {
418+
foreach (self::getAtomics($iterables) as $type) {
407419
if (!$type->isIterable($codebase)) {
408420
throw new \RuntimeException('should be iterable');
409421
}

0 commit comments

Comments
 (0)