Skip to content

Commit 1c5c636

Browse files
herndlmondrejmirtes
authored andcommitted
Adapt MixedType::isConstantArray()
1 parent 788bd0b commit 1c5c636

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

src/Type/MixedType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ public function isArray(): TrinaryLogic
472472

473473
public function isConstantArray(): TrinaryLogic
474474
{
475-
return TrinaryLogic::createMaybe();
475+
return $this->isArray();
476476
}
477477

478478
public function isOversizedArray(): TrinaryLogic

tests/PHPStan/Type/MixedTypeTest.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,80 @@ public function testSubstractedIsArray(MixedType $mixedType, Type $typeToSubtrac
240240
);
241241
}
242242

243+
public function dataSubstractedIsConstantArray(): array
244+
{
245+
return [
246+
[
247+
new MixedType(),
248+
new ArrayType(new IntegerType(), new StringType()),
249+
TrinaryLogic::createMaybe(),
250+
],
251+
[
252+
new MixedType(),
253+
new ArrayType(new StringType(), new StringType()),
254+
TrinaryLogic::createMaybe(),
255+
],
256+
[
257+
new MixedType(),
258+
new ArrayType(new MixedType(), new MixedType()),
259+
TrinaryLogic::createNo(),
260+
],
261+
[
262+
new MixedType(),
263+
new ConstantArrayType(
264+
[new ConstantIntegerType(1)],
265+
[new ConstantStringType('hello')],
266+
),
267+
TrinaryLogic::createMaybe(),
268+
],
269+
[
270+
new MixedType(),
271+
new ConstantArrayType([], []),
272+
TrinaryLogic::createMaybe(),
273+
],
274+
[
275+
new MixedType(),
276+
new UnionType([new FloatType(), new ArrayType(new MixedType(), new MixedType())]),
277+
TrinaryLogic::createNo(),
278+
],
279+
[
280+
new MixedType(),
281+
new UnionType([new FloatType(), new ArrayType(new StringType(), new MixedType())]),
282+
TrinaryLogic::createMaybe(),
283+
],
284+
[
285+
new MixedType(),
286+
new UnionType([new FloatType(), new IntegerType()]),
287+
TrinaryLogic::createMaybe(),
288+
],
289+
[
290+
new MixedType(),
291+
new FloatType(),
292+
TrinaryLogic::createMaybe(),
293+
],
294+
[
295+
new MixedType(true),
296+
new FloatType(),
297+
TrinaryLogic::createMaybe(),
298+
],
299+
];
300+
}
301+
302+
/**
303+
* @dataProvider dataSubstractedIsConstantArray
304+
*/
305+
public function testSubstractedIsConstantArray(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void
306+
{
307+
$subtracted = $mixedType->subtract($typeToSubtract);
308+
$actualResult = $subtracted->isConstantArray();
309+
310+
$this->assertSame(
311+
$expectedResult->describe(),
312+
$actualResult->describe(),
313+
sprintf('%s -> isConstantArray()', $subtracted->describe(VerbosityLevel::precise())),
314+
);
315+
}
316+
243317
public function dataSubstractedIsString(): array
244318
{
245319
return [

0 commit comments

Comments
 (0)