Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/Type/Accessory/NonEmptyArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ public function getConstantStrings(): array

public function accepts(Type $type, bool $strictTypes): AcceptsResult
{
if ($type instanceof CompoundType) {
return $type->isAcceptedBy($this, $strictTypes);
}

$isArray = $type->isArray();
$isIterableAtLeastOnce = $type->isIterableAtLeastOnce();

Expand Down
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Functions/ClosureReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,9 @@ public function testBugFunctionMethodConstants(): void
$this->analyse([__DIR__ . '/data/bug-anonymous-function-method-constant.php'], []);
}

public function testBug13964(): void
{
$this->analyse([__DIR__ . '/data/bug-13964.php'], []);
}

}
17 changes: 17 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-13964.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Bug13964;

/** @var array<string, array<mixed>> $state */
$state = (fn()=>[])();

$state = array_map(function (array $item): array {
if (array_key_exists('type', $item) && array_key_exists('data', $item)) {
return $item;
}

return [
'type' => 'hello',
'data' => [],
];
}, $state);
26 changes: 26 additions & 0 deletions tests/PHPStan/Type/IntersectionTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use PHPStan\Type\Accessory\AccessoryArrayListType;
use PHPStan\Type\Accessory\AccessoryLowercaseStringType;
use PHPStan\Type\Accessory\AccessoryUppercaseStringType;
use PHPStan\Type\Accessory\HasOffsetType;
use PHPStan\Type\Accessory\HasOffsetValueType;
use PHPStan\Type\Accessory\HasPropertyType;
use PHPStan\Type\Accessory\NonEmptyArrayType;
use PHPStan\Type\Accessory\OversizedArrayType;
Expand Down Expand Up @@ -70,6 +72,30 @@ public static function dataAccepts(): Iterator
new CallableType(),
TrinaryLogic::createMaybe(),
];

yield [
TypeCombinator::intersect(
new ArrayType(new MixedType(), new MixedType()),
new NonEmptyArrayType(),
),
TypeCombinator::intersect(
new ArrayType(new MixedType(), new MixedType()),
new HasOffsetType(new ConstantStringType('some-key')),
),
TrinaryLogic::createYes(),
];

yield [
TypeCombinator::intersect(
new ArrayType(new MixedType(), new MixedType()),
new NonEmptyArrayType(),
),
TypeCombinator::intersect(
new ArrayType(new MixedType(), new MixedType()),
new HasOffsetValueType(new ConstantStringType('some-key'), new IntegerType()),
),
TrinaryLogic::createYes(),
];
}

#[DataProvider('dataAccepts')]
Expand Down
Loading