Skip to content

Commit 974b2fb

Browse files
herndlmondrejmirtes
authored andcommitted
Migrate to new Type::getArrays()
1 parent bb1ae66 commit 974b2fb

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Type/BeberleiAssert/AssertHelper.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use PHPStan\Type\StringType;
2929
use PHPStan\Type\Type;
3030
use PHPStan\Type\TypeCombinator;
31-
use PHPStan\Type\TypeUtils;
3231
use ReflectionObject;
3332
use function array_key_exists;
3433
use function count;
@@ -177,15 +176,15 @@ private static function arrayOrIterable(
177176
): SpecifiedTypes
178177
{
179178
$currentType = TypeCombinator::intersect($scope->getType($expr), new IterableType(new MixedType(), new MixedType()));
180-
$arrayTypes = TypeUtils::getArrays($currentType);
179+
$arrayTypes = $currentType->getArrays();
181180
if (count($arrayTypes) > 0) {
182181
$newArrayTypes = [];
183182
foreach ($arrayTypes as $arrayType) {
184183
if ($arrayType instanceof ConstantArrayType) {
185184
$builder = ConstantArrayTypeBuilder::createEmpty();
186185
foreach ($arrayType->getKeyTypes() as $i => $keyType) {
187186
$valueType = $arrayType->getValueTypes()[$i];
188-
$builder->setOffsetValueType($keyType, $typeCallback($valueType));
187+
$builder->setOffsetValueType($keyType, $typeCallback($valueType), $arrayType->isOptionalKey($i));
189188
}
190189
$newArrayTypes[] = $builder->getArray();
191190
} else {

tests/Type/BeberleiAssert/data/data.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
8383
Assertion::allNotNull($w);
8484
\PHPStan\Testing\assertType('array<int>', $w);
8585

86+
/** @var array{baz: float|null}|array{foo?: string|null, bar: int|null} $w */
87+
$w = doFoo();
88+
Assertion::allNotNull($w);
89+
\PHPStan\Testing\assertType('array{baz: float}|array{foo?: string, bar: int}', $w);
90+
8691
Assertion::same($x, 1);
8792
\PHPStan\Testing\assertType('1', $x);
8893

0 commit comments

Comments
 (0)