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

MovieTransformer   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 45
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A list() 0 15 1
B process() 0 24 6
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
}