Passed
Push — master ( 392926...b4a664 )
by Darko
13:01
created

MovieResource   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 31
c 1
b 0
f 0
dl 0
loc 58
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 26 4
A getCoverUrl() 0 7 3
A getBackdropUrl() 0 7 3
1
<?php
2
3
namespace App\Http\Resources;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Http\Resources\Json\JsonResource;
7
8
/**
9
 * Movie API Resource for transforming movie data.
10
 */
11
class MovieResource extends JsonResource
12
{
13
    /**
14
     * Transform the resource into an array.
15
     *
16
     * @return array<string, mixed>
17
     */
18
    public function toArray(Request $request): array
19
    {
20
        return [
21
            'id' => $this->id,
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
22
            'imdbid' => $this->imdbid,
0 ignored issues
show
Bug Best Practice introduced by
The property imdbid does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
23
            'tmdbid' => $this->tmdbid,
0 ignored issues
show
Bug Best Practice introduced by
The property tmdbid does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
24
            'traktid' => $this->traktid,
0 ignored issues
show
Bug Best Practice introduced by
The property traktid does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
25
            'title' => $this->title,
0 ignored issues
show
Bug Best Practice introduced by
The property title does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
26
            'year' => $this->year,
0 ignored issues
show
Bug Best Practice introduced by
The property year does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
27
            'rating' => $this->rating,
0 ignored issues
show
Bug Best Practice introduced by
The property rating does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
28
            'rtrating' => $this->rtrating,
0 ignored issues
show
Bug Best Practice introduced by
The property rtrating does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
29
            'tagline' => $this->tagline,
0 ignored issues
show
Bug Best Practice introduced by
The property tagline does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
30
            'plot' => $this->plot,
0 ignored issues
show
Bug Best Practice introduced by
The property plot does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
31
            'genre' => $this->genre,
0 ignored issues
show
Bug Best Practice introduced by
The property genre does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
32
            'type' => $this->type,
0 ignored issues
show
Bug Best Practice introduced by
The property type does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
33
            'director' => $this->director,
0 ignored issues
show
Bug Best Practice introduced by
The property director does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
34
            'actors' => $this->actors,
0 ignored issues
show
Bug Best Practice introduced by
The property actors does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
35
            'language' => $this->language,
0 ignored issues
show
Bug Best Practice introduced by
The property language does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
36
            'cover' => $this->cover ? true : false,
0 ignored issues
show
Bug Best Practice introduced by
The property cover does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
37
            'backdrop' => $this->backdrop ? true : false,
0 ignored issues
show
Bug Best Practice introduced by
The property backdrop does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
38
            'trailer' => $this->trailer,
0 ignored issues
show
Bug Best Practice introduced by
The property trailer does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
39
            'cover_url' => $this->getCoverUrl(),
40
            'backdrop_url' => $this->getBackdropUrl(),
41
            'imdb_url' => $this->imdbid ? 'https://www.imdb.com/title/tt'.$this->imdbid.'/' : null,
42
            'created_at' => $this->created_at?->toIso8601String(),
0 ignored issues
show
Bug Best Practice introduced by
The property created_at does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
43
            'updated_at' => $this->updated_at?->toIso8601String(),
0 ignored issues
show
Bug Best Practice introduced by
The property updated_at does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
44
        ];
45
    }
46
47
    /**
48
     * Get the cover image URL.
49
     */
50
    protected function getCoverUrl(): ?string
51
    {
52
        if (! $this->cover || ! $this->imdbid) {
0 ignored issues
show
Bug Best Practice introduced by
The property cover does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property imdbid does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
53
            return null;
54
        }
55
56
        return url('/covers/movies/'.$this->imdbid.'-cover.jpg');
57
    }
58
59
    /**
60
     * Get the backdrop image URL.
61
     */
62
    protected function getBackdropUrl(): ?string
63
    {
64
        if (! $this->backdrop || ! $this->imdbid) {
0 ignored issues
show
Bug Best Practice introduced by
The property imdbid does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property backdrop does not exist on App\Http\Resources\MovieResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
65
            return null;
66
        }
67
68
        return url('/covers/movies/'.$this->imdbid.'-backdrop.jpg');
69
    }
70
}
71
72