Completed
Push — master ( 408a9b...358b85 )
by Valentyn
04:06
created

MovieTransformer::process()   B

Complexity

Conditions 7
Paths 25

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 12
cts 12
cp 1
rs 8.6346
c 0
b 0
f 0
cc 7
nc 25
nop 1
crap 7
1
<?php
2
3
namespace App\Movies\Transformer;
4
5
use App\Transformer\Transformer;
6
7
class MovieTransformer implements Transformer
8
{
9
    private $hiddenFields = [];
10
11 17
    public static function list(): self
12
    {
13 17
        $transformer = new self();
14 17
        $transformer->hiddenFields = [
15
            'budget',
16
            'genres',
17
            'imdbId',
18
            'overview',
19
            'runtime',
20
            'tmdb.id',
21
            'tmdb.voteAverage',
22
            'tmdb.voteCount',
23
        ];
24 17
        return $transformer;
25
    }
26
27 17
    public function process(array $data): array
28
    {
29 17
        if (!isset($data['id'])) {
30 17
            return $data;
31
        }
32
33 17
        $data['isWatched'] = isset($data['userWatchedMovie']) && $data['userWatchedMovie'] ? true : false;
34
35 17
        if (isset($data['tmdb.id'])) {
36 17
            $data['tmdb']['id'] = $data['tmdb.id'];
37 17
            $data['tmdb']['voteAverage'] = $data['tmdb.voteAverage'];
38 17
            $data['tmdb']['voteCount'] = $data['tmdb.voteCount'];
39
        }
40
41 17
        foreach ($this->hiddenFields as $hiddenField) {
42 17
            if (isset($data[$hiddenField])) {
43 17
                unset($data[$hiddenField]);
44
            }
45
        }
46
47 17
        return $data;
48
    }
49
}