forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-11507.php
More file actions
50 lines (41 loc) · 904 Bytes
/
bug-11507.php
File metadata and controls
50 lines (41 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php // lint >= 8.0
declare(strict_types = 1);
namespace Bug11507;
/**
* @template TValue
*/
class Collection
{
/**
* @param array<int, TValue> $items
*/
public function __construct(
public array $items,
) {}
/**
* Run a map over each of the items.
*
* @template TMapValue
*
* @param callable(TValue, int=): TMapValue $callback
* @return Collection<TMapValue>
*/
public function map(callable $callback): Collection
{
$keys = array_keys($this->items);
$items = array_map($callback, $this->items);
$result = array_combine($keys, $items);
return new self($result);
}
}
/**
* @param Collection<non-empty-array<string>> $collection
* @return Collection<non-empty-array<string>>
*/
function foo(Collection $collection): Collection
{
return $collection->map(function (array $item) {
$item['foo'] = '100';
return $item;
});
}