Skip to content

Commit 8dcecaf

Browse files
committed
Add regression test for #11507
Refs phpstan/phpstan#11507
1 parent 7785596 commit 8dcecaf

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

‎tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,14 @@ public function testBug8031(): void
534534
$this->analyse([__DIR__ . '/data/bug-8031.php'], []);
535535
}
536536

537+
#[RequiresPhp('>= 8.0.0')]
538+
public function testBug11507(): void
539+
{
540+
$this->checkNullables = true;
541+
$this->checkExplicitMixed = true;
542+
$this->analyse([__DIR__ . '/data/bug-11507.php'], []);
543+
}
544+
537545
public function testBug15245(): void
538546
{
539547
$this->checkNullables = true;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php declare(strict_types = 1);
2+
3+
use function PHPStan\dumpType;
4+
5+
/**
6+
* @template TValue
7+
*/
8+
class Collection
9+
{
10+
/**
11+
* @param array<int, TValue> $items
12+
*/
13+
public function __construct(
14+
public array $items,
15+
) {}
16+
17+
/**
18+
* Run a map over each of the items.
19+
*
20+
* @template TMapValue
21+
*
22+
* @param callable(TValue, int=): TMapValue $callback
23+
* @return Collection<TMapValue>
24+
*/
25+
public function map(callable $callback)
26+
{
27+
$keys = array_keys($this->items);
28+
29+
$items = array_map($callback, $this->items);
30+
31+
$result = array_combine($keys, $items);
32+
33+
return new self($result);
34+
}
35+
}
36+
37+
/**
38+
* @param Collection<non-empty-array<string>> $collection
39+
* @return Collection<non-empty-array<string>>
40+
*/
41+
function foo(Collection $collection)
42+
{
43+
return $collection->map(function (array $item) {
44+
$item['foo'] = '100';
45+
46+
return $item;
47+
});
48+
}

0 commit comments

Comments
 (0)