Completed
Push — master ( 9f513c...408a9b )
by Valentyn
04:02
created

MovieTransformer::process()   B

Complexity

Conditions 6
Paths 13

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 6.0163

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 12
cts 13
cp 0.9231
rs 8.9137
c 0
b 0
f 0
cc 6
nc 13
nop 1
crap 6.0163
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
        if (isset($data['userWatchedMovie'])) {
34
            $data['isWatched'] = $data['userWatchedMovie'] !== null;
35
        }
36
37 17
        if (isset($data['tmdb.id'])) {
38 17
            $data['tmdb']['id'] = $data['tmdb.id'];
39 17
            $data['tmdb']['voteAverage'] = $data['tmdb.voteAverage'];
40 17
            $data['tmdb']['voteCount'] = $data['tmdb.voteCount'];
41
        }
42
43 17
        foreach ($this->hiddenFields as $hiddenField) {
44 17
            if (isset($data[$hiddenField])) {
45 17
                unset($data[$hiddenField]);
46
            }
47
        }
48
49 17
        return $data;
50
    }
51
}