Passed
Push — master ( d4e337...e0198f )
by Martin
02:43
created

CollectionTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 18 3
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace KingsonDe\Marshal\Data;
6
7
trait CollectionTrait {
8
9 6
    public function build(): array {
10 6
        $output = [];
11
12 6
        $data = $this->getData();
13
        /** @var \Traversable $modelCollection */
14 6
        $modelCollection = \array_shift($data);
15
16 6
        foreach ($modelCollection as $model) {
17 6
            $item = $this->mapData($model, ...$data);
18
19 6
            if (!\is_array($item)) {
20 1
                continue;
21
            }
22
23 6
            $output[] = $item;
24
        }
25
26 6
        return $output;
27
    }
28
29
    abstract protected function getData(): array;
30
31
    /**
32
     * @param mixed $model
33
     * @param array $data
34
     * @return array|null
35
     */
36
    abstract protected function mapData($model, ...$data);
37
}