Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php declare(strict_types=1); |
||
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()) |
|
58 | |||
59 | /** |
||
60 | * Crew |
||
61 | * @return \Generator |
||
62 | */ |
||
63 | 20 | View Code Duplication | public function getCrew() : \Generator |
73 | |||
74 | /** |
||
75 | * Cast |
||
76 | * @return \Generator |
||
77 | */ |
||
78 | 18 | View Code Duplication | public function getCast() : \Generator |
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.