| Total Complexity | 14 |
| Total Lines | 65 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class Collection implements ArrayAccess, JsonSerializable, Stringable |
||
| 10 | { |
||
| 11 | public function __construct(protected $items = []) |
||
| 12 | { |
||
| 13 | } |
||
| 14 | |||
| 15 | public function join(string $separator = ' '): string |
||
| 16 | { |
||
| 17 | return implode($separator, \array_map(function ($item) { |
||
| 18 | return \is_array($item) ? '['.\implode(', ', $item).']' : $item; |
||
| 19 | }, $this->items)); |
||
| 20 | } |
||
| 21 | |||
| 22 | public function map(callable $callback): Collection |
||
| 25 | } |
||
| 26 | |||
| 27 | public function all(): array |
||
| 28 | { |
||
| 29 | return $this->items; |
||
| 30 | } |
||
| 31 | |||
| 32 | public function toArray(): array |
||
| 33 | { |
||
| 34 | return $this->all(); |
||
| 35 | } |
||
| 36 | |||
| 37 | public function toJson(int $options = 0): string |
||
| 38 | { |
||
| 39 | return json_encode($this->all(), $options); |
||
| 40 | } |
||
| 41 | |||
| 42 | public function __toString() |
||
| 43 | { |
||
| 44 | return $this->join(); |
||
| 45 | } |
||
| 46 | |||
| 47 | public function offsetExists(mixed $offset): bool |
||
| 50 | } |
||
| 51 | |||
| 52 | public function offsetGet(mixed $offset): mixed |
||
| 53 | { |
||
| 54 | return $this->items[$offset] ?? null; |
||
| 55 | } |
||
| 56 | |||
| 57 | public function offsetSet(mixed $offset, mixed $value): void |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | public function offsetUnset(mixed $offset): void |
||
| 67 | { |
||
| 68 | unset($this->items[$offset]); |
||
| 69 | } |
||
| 70 | |||
| 71 | public function jsonSerialize(): mixed |
||
| 74 | } |
||
| 75 | } |
||
| 76 |