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 | View Code Duplication | final class VenueService |
|
|
|||
22 | { |
||
23 | /** |
||
24 | * @var ConnectionInterface |
||
25 | */ |
||
26 | private $connection; |
||
27 | |||
28 | public function __construct(ConnectionInterface $connection) |
||
32 | |||
33 | /** |
||
34 | * Get the metadata for an artist. |
||
35 | * |
||
36 | * @throws ApiException |
||
37 | * @throws NotFoundException |
||
38 | */ |
||
39 | public function getVenue(string $venueId): Venue |
||
45 | |||
46 | /** |
||
47 | * Search for venues. |
||
48 | * |
||
49 | * @throws ApiException |
||
50 | * @throws NotFoundException |
||
51 | */ |
||
52 | public function search(VenueSearchBuilder $builder): VenueSearchResult |
||
62 | } |
||
63 |
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.