Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| TraitCollectionCore | |
100.00% |
9 / 9 |
|
100.00% |
7 / 7 |
9 | |
100.00% |
1 / 1 |
| items | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| values | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| first | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| last | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| count | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isEmpty | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getIterator | |
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 | use ArrayIterator; |
| 13 | use Traversable; |
| 14 | |
| 15 | trait TraitCollectionCore |
| 16 | { |
| 17 | public function items(): array |
| 18 | { |
| 19 | return $this->collection; |
| 20 | } |
| 21 | |
| 22 | public function values(): array |
| 23 | { |
| 24 | return array_values($this->collection); |
| 25 | } |
| 26 | |
| 27 | public function first(): mixed |
| 28 | { |
| 29 | $key = array_key_first($this->collection); |
| 30 | |
| 31 | return $key !== null ? $this->collection[$key] : false; |
| 32 | } |
| 33 | |
| 34 | public function last(): mixed |
| 35 | { |
| 36 | $key = array_key_last($this->collection); |
| 37 | |
| 38 | return $key !== null ? $this->collection[$key] : false; |
| 39 | } |
| 40 | |
| 41 | public function count(): int |
| 42 | { |
| 43 | return count($this->collection); |
| 44 | } |
| 45 | |
| 46 | public function isEmpty(): bool |
| 47 | { |
| 48 | return $this->count() === 0; |
| 49 | } |
| 50 | |
| 51 | public function getIterator(): Traversable |
| 52 | { |
| 53 | return new ArrayIterator($this->collection); |
| 54 | } |
| 55 | } |