-
Notifications
You must be signed in to change notification settings - Fork 0
/
DatasetEntityCollection.php
44 lines (36 loc) · 1.14 KB
/
DatasetEntityCollection.php
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
<?php
declare(strict_types=1);
namespace Heptacom\HeptaConnect\Dataset\Base;
use Heptacom\HeptaConnect\Dataset\Base\Contract\DatasetEntityContract;
use Heptacom\HeptaConnect\Dataset\Base\Support\AbstractObjectCollection;
/**
* @extends AbstractObjectCollection<DatasetEntityContract>
*/
class DatasetEntityCollection extends AbstractObjectCollection
{
/**
* @return iterable<class-string<DatasetEntityContract>, static>
*/
public function groupByType(): iterable
{
/** @var array<class-string<DatasetEntityContract>, DatasetEntityContract[]> $groups */
$groups = [];
/** @var DatasetEntityContract $item */
foreach ($this->items as $item) {
$groups[$item::class][] = $item;
}
/** @var DatasetEntityContract[] $group */
foreach ($groups as $type => $group) {
$grouped = $this->withoutItems();
$grouped->push($group);
yield $type => $grouped;
}
}
/**
* @psalm-return Contract\DatasetEntityContract::class
*/
protected function getT(): string
{
return DatasetEntityContract::class;
}
}