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 |
||
21 | final class SetlistService |
||
22 | { |
||
23 | /** |
||
24 | * @var ConnectionInterface |
||
25 | */ |
||
26 | private $connection; |
||
27 | |||
28 | public function __construct(ConnectionInterface $connection) |
||
32 | |||
33 | /** |
||
34 | * Get setlist information. |
||
35 | * |
||
36 | * @throws ApiException |
||
37 | * @throws NotFoundException |
||
38 | */ |
||
39 | public function getSetlist(string $setlistId): Setlist |
||
45 | |||
46 | /** |
||
47 | * Get setlist information by version id. |
||
48 | * |
||
49 | * @throws ApiException |
||
50 | * @throws NotFoundException |
||
51 | */ |
||
52 | public function getSetlistByVersion(string $versionId): Setlist |
||
58 | |||
59 | /** |
||
60 | * Get artist setlists. |
||
61 | * |
||
62 | * @throws ApiException |
||
63 | * @throws NotFoundException |
||
64 | * |
||
65 | * @return Setlist[] |
||
66 | */ |
||
67 | View Code Duplication | public function getArtistSetlists(string $mbid, int $page = 1): array |
|
81 | |||
82 | /** |
||
83 | * Get venue setlists. |
||
84 | * |
||
85 | * @throws ApiException |
||
86 | * @throws NotFoundException |
||
87 | * |
||
88 | * @return Setlist[] |
||
89 | */ |
||
90 | View Code Duplication | public function getVenueSetlists(string $venueId, int $page = 1): array |
|
104 | |||
105 | /** |
||
106 | * Search for setlists. |
||
107 | * |
||
108 | * @throws ApiException |
||
109 | * @throws NotFoundException |
||
110 | */ |
||
111 | public function search(SetlistSearchBuilder $builder): SetlistSearchResult |
||
121 | } |
||
122 |
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.