Completed
Push — master ( 259b4f...1970e3 )
by Marcin
03:08
created

Title   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 13
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 142
ccs 0
cts 31
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
F create() 0 33 13
1
<?php
2
/**
3
 * Created by Marcin.
4
 * Date: 09.12.2017
5
 * Time: 23:15
6
 */
7
8
namespace mrcnpdlk\Xmdb\Model\Omdb;
9
10
11
use Carbon\Carbon;
12
13
class Title
14
{
15
    /**
16
     * @var string
17
     */
18
    public $title;
19
    /**
20
     * @var string
21
     */
22
    public $imdbId;
23
    /**
24
     * @var float|null
25
     */
26
    public $imdbRating;
27
    /**
28
     * @var int|null
29
     */
30
    public $imdbVotes;
31
    /**
32
     * @var string
33
     */
34
    public $year;
35
    /**
36
     * @var
37
     */
38
    public $rated;
39
    /**
40
     * @var string
41
     */
42
    public $released;
43
    /**
44
     * @var string
45
     */
46
    public $runtime;
47
    /**
48
     * @var string[]
49
     */
50
    public $genre = [];
51
    /**
52
     * @var string[]
53
     */
54
    public $director = [];
55
    /**
56
     * @var string[]
57
     */
58
    public $writer = [];
59
    /**
60
     * @var string[]
61
     */
62
    public $actors = [];
63
    /**
64
     * @var string
65
     */
66
    public $plot;
67
    /**
68
     * @var string
69
     */
70
    public $language;
71
    /**
72
     * @var string
73
     */
74
    public $country;
75
    /**
76
     * @var string
77
     */
78
    public $awards;
79
    /**
80
     * @var string
81
     */
82
    public $poster;
83
    /**
84
     * @var \mrcnpdlk\Xmdb\Model\Omdb\Rating[]
85
     */
86
    public $ratings = [];
87
    /**
88
     * @var int|null
89
     */
90
    public $metascore;
91
    /**
92
     * @var string
93
     */
94
    public $type;
95
    /**
96
     * @var integer
97
     */
98
    public $totalSeasons;
99
    /**
100
     * @var string | null
101
     */
102
    public $dvd;
103
    /**
104
     * @var string | null
105
     */
106
    public $boxOffice;
107
    /**
108
     * @var string | null
109
     */
110
    public $production;
111
    /**
112
     * @var string | null
113
     */
114
    public $website;
115
116
    /**
117
     * @param \stdClass $oData
118
     *
119
     * @return static
120
     */
121
    public static function create(\stdClass $oData)
122
    {
123
        $oTitle               = new static();
124
        $oTitle->title        = $oData->Title;
125
        $oTitle->year         = $oData->Year;
126
        $oTitle->released     = Carbon::parse($oData->Released)->format('Y-m-d');
127
        $oTitle->runtime      = $oData->Runtime;
128
        $oTitle->genre        = explode(', ', $oData->Genre);
129
        $oTitle->director     = $oData->Director === 'N/A' ? null : explode(', ', $oData->Director);
130
        $oTitle->writer       = explode(', ', $oData->Writer);
131
        $oTitle->actors       = explode(', ', $oData->Actors);
132
        $oTitle->plot         = $oData->Plot;
133
        $oTitle->language     = $oData->Language;
134
        $oTitle->country      = $oData->Country;
135
        $oTitle->awards       = $oData->Awards;
136
        $oTitle->poster       = $oData->Poster;
137
        $oTitle->metascore    = $oData->Metascore === 'N/A' ? null : (int)$oData->Metascore;
138
        $oTitle->imdbRating   = (float)$oData->imdbRating;
139
        $oTitle->imdbVotes    = (int)preg_replace('/,/', '', $oData->imdbVotes);
140
        $oTitle->imdbId       = $oData->imdbID;
141
        $oTitle->type         = $oData->Type;
142
        $oTitle->totalSeasons = !isset($oData->totalSeasons) || $oData->totalSeasons === 'N/A' ? null : (int)$oData->totalSeasons;
143
        $oTitle->dvd          = isset($oData->DVD) ? Carbon::parse($oData->DVD)->format('Y-m-d') : null;
144
        $oTitle->boxOffice    = !isset($oData->BoxOffice) || $oData->BoxOffice === 'N/A' ? null : $oData->BoxOffice;
145
        $oTitle->production   = !isset($oData->Production) || $oData->Production === 'N/A' ? null : $oData->Production;
146
        $oTitle->website      = !isset($oData->Website) || $oData->Website === 'N/A' ? null : $oData->Website;
147
148
        foreach ($oData->Ratings as $rating) {
149
            $oTitle->ratings[] = new Rating($rating->Source, $rating->Value);
150
        }
151
152
        return $oTitle;
153
    }
154
}
155