Passed
Pull Request — master (#4)
by Morten Poul
05:31 queued 02:55
created

TransformsResources   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 12
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transformItem() 0 3 1
A transformCollection() 0 4 1
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