Collection::toArray()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 12
rs 10
cc 3
nc 1
nop 0
1
<?php
2
3
namespace Rawilk\LaravelModules;
4
5
use Illuminate\Contracts\Support\Arrayable;
6
use Illuminate\Support\Collection as BaseCollection;
7
8
class Collection extends BaseCollection
9
{
10
    public function getItems(): array
11
    {
12
        return $this->items;
13
    }
14
15
    public function toArray(): array
16
    {
17
        return array_map(static function ($value) {
18
            if ($value instanceof Module) {
19
                $attributes = $value->json()->getAttributes();
20
                $attributes['path'] = $value->getPath();
21
22
                return $attributes;
23
            }
24
25
            return $value instanceof Arrayable ? $value->toArray() : $value;
26
        }, $this->items);
27
    }
28
}
29