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
ListCollection 100.00% 6 / 6 100.00% 3 / 3 4 100.00% 1 / 1
 fromList 100.00% 4 / 4 100.00% 1 / 1 2
 withAppendedElement 100.00% 1 / 1 100.00% 1 / 1 1
 arrangeElements 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Contracts\Collection;
6
7/**
8 * @template T
9 * @extends TypedCollection<int, T>
10 */
11abstract readonly class ListCollection extends TypedCollection
12{
13    /** @param iterable<T> $elements */
14    public static function fromList(iterable $elements): static
15    {
16        $list = [];
17
18        foreach ($elements as $element) {
19            $list[] = $element;
20        }
21
22        return new static($list);
23    }
24
25    /** @param T $element */
26    protected function withAppendedElement(mixed $element): static
27    {
28        return new static([...$this->elements(), $element]);
29    }
30
31    /**
32     * @param array<int, T> $elements
33     * @return list<T>
34     */
35    protected function arrangeElements(array $elements): array
36    {
37        return array_values($elements);
38    }
39}