| 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 extends \mrcnpdlk\Xmdb\Model\Title | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |      * @var | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     public $rated; | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |      * @var string | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     public $awards; | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |      * @var string | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |     public $poster; | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |      * @var \mrcnpdlk\Xmdb\Model\Omdb\Rating[] | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |     public $ratings = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      * @var int|null | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     public $metascore; | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      * @var string | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     public $type; | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |      * @var integer | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     public $totalSeasons; | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |      * @var string | null | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     public $dvd; | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |      * @var string | null | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     public $boxOffice; | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      * @var string | null | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |     public $production; | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |      * @var string | null | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     public $website; | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      * @param \stdClass $oData | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |      * @return static | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     public static function create(\stdClass $oData) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $oTitle                   = new static(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $oTitle->title            = $oData->Title; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $oTitle->titleOrg         = $oData->Title; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $oTitle->releaseYear      = $oData->Year; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $oTitle->releaseDate      = $oData->Released !== 'N/A' ? Carbon::parse($oData->Released)->format('Y-m-d') : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $oTitle->runtime          = (int)$oData->Runtime; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $oTitle->genres           = explode(', ', $oData->Genre); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $oTitle->directors        = $oData->Director === 'N/A' ? [] : explode(', ', $oData->Director); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $oTitle->writers          = explode(', ', $oData->Writer); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $oTitle->actors           = explode(', ', $oData->Actors); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $oTitle->plot             = $oData->Plot; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $oTitle->language         = $oData->Language; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $oTitle->countriesDisplay = $oData->Country; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $oTitle->awards           = $oData->Awards; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $oTitle->poster           = $oData->Poster; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $oTitle->metascore        = $oData->Metascore === 'N/A' ? null : (int)$oData->Metascore; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $oTitle->imdbRating       = (float)$oData->imdbRating; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $oTitle->imdbVotes        = (int)preg_replace('/,/', '', $oData->imdbVotes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $oTitle->imdbId           = $oData->imdbID; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $oTitle->type             = $oData->Type; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $oTitle->totalSeasons     = !isset($oData->totalSeasons) || $oData->totalSeasons === 'N/A' ? null : (int)$oData->totalSeasons; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $oTitle->dvd              = isset($oData->DVD) && $oData->DVD !== 'N/A' ? Carbon::parse($oData->DVD)->format('Y-m-d') : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $oTitle->boxOffice        = !isset($oData->BoxOffice) || $oData->BoxOffice === 'N/A' ? null : $oData->BoxOffice; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $oTitle->production       = !isset($oData->Production) || $oData->Production === 'N/A' ? null : $oData->Production; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $oTitle->website          = !isset($oData->Website) || $oData->Website === 'N/A' ? null : $oData->Website; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $oTitle->genresDisplay    = implode(', ', $oTitle->genres); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         $oTitle->directorsDisplay = implode(', ', $oTitle->directors); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         $oTitle->writersDisplay   = implode(', ', $oTitle->writers); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         $oTitle->actorsDisplay    = implode(', ', $oTitle->actors); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $oTitle->countries        = explode(', ', $oTitle->countriesDisplay); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         foreach ((array)$oData->Ratings as $rating) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             $oTitle->ratings[] = new Rating($rating->Source, $rating->Value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         return $oTitle; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 104 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 105 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 106 |  |  |  | 
            
                        
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.