Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractTypedCollection
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 add
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 type
n/a
0 / 0
n/a
0 / 0
0
1<?php
2
3// ╔════════════════════════════════════════════════════════════╗
4// ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║
5// ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com>     ║
6// ╚════════════════════════════════════════════════════════════╝
7
8declare(strict_types=1);
9
10namespace Phexium\Domain\Collection;
11
12use Assert\Assert;
13use Override;
14
15abstract class AbstractTypedCollection extends AbstractCollection
16{
17    public function __construct(array $collection = [])
18    {
19        Assert::thatAll($collection)->isInstanceOf($this->type());
20
21        parent::__construct($collection);
22    }
23
24    #[Override]
25    public function add(mixed $element): void
26    {
27        Assert::that($element)->isInstanceOf($this->type());
28
29        parent::add($element);
30    }
31
32    abstract protected function type(): string;
33}