Lines 100.00% 6 / 6
Functions and Methods 100.00% 3 / 3
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
EntityAliasCollection 100.00% 6 / 6 100.00% 3 / 3 5 100.00% 1 / 1
 contains 100.00% 1 / 1 100.00% 1 / 1 1
 withAddedMembers 100.00% 4 / 4 100.00% 1 / 1 3
 withoutMembers 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Contracts\Registry\Collection;
6
7use Stewart\Contracts\Collection\ListCollection;
8use Stewart\Contracts\Registry\EntityAlias;
9
10/** @extends ListCollection<EntityAlias> */
11final readonly class EntityAliasCollection extends ListCollection
12{
13    public function contains(EntityAlias $alias): bool
14    {
15        return $this->containsWhere($alias->equals(...));
16    }
17
18    public function withAddedMembers(self $aliases): self
19    {
20        $merged = $this;
21
22        foreach ($aliases as $alias) {
23            $merged = $merged->contains($alias) ? $merged : $merged->withAppendedElement($alias);
24        }
25
26        return $merged;
27    }
28
29    public function withoutMembers(self $aliases): self
30    {
31        return $this->filter(static fn(EntityAlias $alias): bool => !$aliases->contains($alias));
32    }
33}