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 |
||
14 | class LanguagesClient extends NStackClient |
||
15 | { |
||
16 | /** @var string */ |
||
17 | protected $path = 'geographic/languages'; |
||
18 | |||
19 | /** |
||
20 | * index |
||
21 | * |
||
22 | * @param int $page |
||
23 | * @param int $limit |
||
24 | * @return array |
||
25 | * @throws FailedToParseException |
||
26 | */ |
||
27 | 1 | View Code Duplication | public function index($page = 1, $limit = 500): array |
46 | |||
47 | /** |
||
48 | * search |
||
49 | * |
||
50 | * @param String $term |
||
51 | * @param int $page |
||
52 | * @param int $limit |
||
53 | * @return array |
||
54 | * @throws FailedToParseException |
||
55 | */ |
||
56 | 1 | View Code Duplication | public function search(String $term, $page = 1, $limit = 500): array |
76 | } |
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.