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

Title::create()   F

Complexity

Conditions 13
Paths 4096

Size

Total Lines 33
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 182

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 33
ccs 0
cts 31
cp 0
rs 2.7716
cc 13
eloc 28
nc 4096
nop 1
crap 182

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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