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;
13
14abstract class AbstractTypedCollection extends AbstractCollection
15{
16    public function __construct(array $collection = [])
17    {
18        Assert::thatAll($collection)->isInstanceOf($this->type());
19
20        parent::__construct($collection);
21    }
22
23    public function add(mixed $element): void
24    {
25        Assert::that($element)->isInstanceOf($this->type());
26
27        parent::add($element);
28    }
29
30    abstract protected function type(): string;
31}