Skip to content

Commit fe8354a

Browse files
herndlmondrejmirtes
authored andcommitted
Migrate to new Type::getArrays()
1 parent a882a6e commit fe8354a

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
use PHPStan\Type\StringType;
5050
use PHPStan\Type\Type;
5151
use PHPStan\Type\TypeCombinator;
52-
use PHPStan\Type\TypeUtils;
5352
use PHPStan\Type\TypeWithClassName;
5453
use ReflectionObject;
5554
use Traversable;
@@ -886,15 +885,15 @@ private function arrayOrIterable(
886885
): SpecifiedTypes
887886
{
888887
$currentType = TypeCombinator::intersect($scope->getType($expr), new IterableType(new MixedType(), new MixedType()));
889-
$arrayTypes = TypeUtils::getArrays($currentType);
888+
$arrayTypes = $currentType->getArrays();
890889
if (count($arrayTypes) > 0) {
891890
$newArrayTypes = [];
892891
foreach ($arrayTypes as $arrayType) {
893892
if ($arrayType instanceof ConstantArrayType) {
894893
$builder = ConstantArrayTypeBuilder::createEmpty();
895894
foreach ($arrayType->getKeyTypes() as $i => $keyType) {
896895
$valueType = $arrayType->getValueTypes()[$i];
897-
$builder->setOffsetValueType($keyType, $typeCallback($valueType));
896+
$builder->setOffsetValueType($keyType, $typeCallback($valueType), $arrayType->isOptionalKey($i));
898897
}
899898
$newArrayTypes[] = $builder->getArray();
900899
} else {

tests/Type/WebMozartAssert/data/collection.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,22 +98,26 @@ public function allNotInstanceOf(array $a, array $b, array $c): void
9898
assertType('array<PHPStan\Type\WebMozartAssert\CollectionFoo>', $c);
9999
}
100100

101-
/**
102-
* @param (int|null)[] $a
103-
*/
104-
public function allNotNull(array $a): void
101+
public function allNotNull(array $arr): void
105102
{
106-
Assert::allNotNull($a);
107-
assertType('array<int>', $a);
103+
/** @var (int|null)[] $arr */
104+
Assert::allNotNull($arr);
105+
assertType('array<int>', $arr);
106+
107+
/** @var array{baz: float|null}|array{foo?: string|null, bar: int|null} $arr */
108+
Assert::allNotNull($arr);
109+
assertType('array{baz: float}|array{foo?: string, bar: int}', $arr);
108110
}
109111

110-
/**
111-
* @param array{-1|1, -2|2, -3|3} $a
112-
*/
113-
public function allNotSame(array $a): void
112+
public function allNotSame(array $arr): void
114113
{
115-
Assert::allNotSame($a, -1);
116-
assertType('array{1, -2|2, -3|3}', $a);
114+
/** @var array{-1|1, -2|2, -3|3} $arr */
115+
Assert::allNotSame($arr, -1);
116+
assertType('array{1, -2|2, -3|3}', $arr);
117+
118+
/** @var array{-1, -2, -3}|array{1, 2, 3} $arr */
119+
Assert::allNotSame($arr, -1);
120+
assertType('array{*NEVER*, -2, -3}|array{1, 2, 3}', $arr);
117121
}
118122

119123
public function allSubclassOf(array $a, iterable $b, $c): void

0 commit comments

Comments
 (0)