Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| TraitCollectionMutation | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| add | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| remove | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| clear | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | // ╔════════════════════════════════════════════════════════════╗ |
| 4 | // ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║ |
| 5 | // ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com> ║ |
| 6 | // ╚════════════════════════════════════════════════════════════╝ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace Phexium\Domain\Collection\Trait; |
| 11 | |
| 12 | trait TraitCollectionMutation |
| 13 | { |
| 14 | public function add(mixed $element): void |
| 15 | { |
| 16 | $this->collection[] = $element; |
| 17 | } |
| 18 | |
| 19 | public function remove(mixed $element): bool |
| 20 | { |
| 21 | $key = array_search($element, $this->collection, strict: true); |
| 22 | |
| 23 | if ($key === false) { |
| 24 | return false; |
| 25 | } |
| 26 | |
| 27 | unset($this->collection[$key]); |
| 28 | |
| 29 | return true; |
| 30 | } |
| 31 | |
| 32 | public function clear(): void |
| 33 | { |
| 34 | $this->collection = []; |
| 35 | } |
| 36 | } |