| 1 |  |  | <?php declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * This file is part of the Tmdb package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * (c) Vincent Faliès <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @author Vincent Faliès <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @copyright Copyright (c) 2017 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | namespace VfacTmdb\Abstracts\Items; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use VfacTmdb\Abstracts\Item; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use VfacTmdb\Exceptions\TmdbException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use VfacTmdb\Interfaces\TmdbInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * abstract item class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @package Tmdb | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @author Vincent Faliès <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * @copyright Copyright (c) 2017 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | abstract class PeopleItemCredit extends Item | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * People item crew class name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     public $crew_class; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * People item cast class name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     public $cast_class; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * Constructor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @param TmdbInterface $tmdb | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @param string $item_type (possible value : movie / tv) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @param int $item_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * @param array $options | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 46 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 47 | 40 |  |     public function __construct(TmdbInterface $tmdb, string $item_type, int $item_id, array $options = array()) | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         try { | 
            
                                                                        
                            
            
                                    
            
            
                | 50 | 40 |  |             $this->tmdb   = $tmdb; | 
            
                                                                        
                            
            
                                    
            
            
                | 51 | 40 |  |             $this->logger = $tmdb->getLogger(); | 
            
                                                                        
                            
            
                                    
            
            
                | 52 | 40 |  |             $this->params = $this->tmdb->checkOptions($options); | 
            
                                                                        
                            
            
                                    
            
            
                | 53 | 40 |  |             $this->data   = $this->tmdb->getRequest('person/' . $item_id . '/' . $item_type . '_credits', $this->params); | 
            
                                                                        
                            
            
                                    
            
            
                | 54 | 2 |  |         } catch (TmdbException $ex) { | 
            
                                                                        
                            
            
                                    
            
            
                | 55 | 2 |  |             throw $ex; | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 57 | 38 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * Crew | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @return \Generator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 63 | 20 | View Code Duplication |     public function getCrew() : \Generator | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 20 |  |         if (!empty($this->data->crew)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 20 |  |             foreach ($this->data->crew as $c) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 20 |  |                 $crew_class = $this->crew_class; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 20 |  |                 $crew = new $crew_class($this->tmdb, $c); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 20 |  |                 yield $crew; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 2 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * Cast | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @return \Generator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 78 | 18 | View Code Duplication |     public function getCast() : \Generator | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 18 |  |         if (!empty($this->data->cast)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 18 |  |             foreach ($this->data->cast as $c) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 18 |  |                 $cast_class = $this->cast_class; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 18 |  |                 $cast = new $cast_class($this->tmdb, $c); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 18 |  |                 yield $cast; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 | 2 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 88 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.