Passed
Pull Request — master (#4)
by Morten Poul
12:59
created

TransformsResources::transformCollection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Signifly\Shopify\Support;
4
5
use Illuminate\Support\Collection;
6
use Signifly\Shopify\REST\Resources\ApiResource;
7
8
trait TransformsResources
9
{
10
    protected function transformCollection(array $items, string $class): Collection
11
    {
12
        return collect($items)->map(function ($attributes) use ($class) {
13
            return $this->transformItem($attributes, $class);
14
        });
15
    }
16
17
    protected function transformItem(array $attributes, string $class): ApiResource
18
    {
19
        return new $class($attributes, $this);
20
    }
21
}
22