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 IndexResponse implements ApiResponse, PagingProvider |
|
|
|||
22 | { |
||
23 | use PaginationResponse; |
||
24 | |||
25 | /** |
||
26 | * Array to store a list of whitelist items from |
||
27 | * index response. |
||
28 | * |
||
29 | * @var Whitelist[] |
||
30 | */ |
||
31 | private $items = []; |
||
32 | |||
33 | /** |
||
34 | * Store the total number of whitelists items. |
||
35 | * |
||
36 | * @var int |
||
37 | */ |
||
38 | private $totalCount; |
||
39 | |||
40 | private function __construct() |
||
43 | |||
44 | public static function create(array $data): self |
||
60 | |||
61 | /** |
||
62 | * @return Whitelist[] |
||
63 | */ |
||
64 | public function getItems(): array |
||
68 | |||
69 | public function getTotalCount(): int |
||
77 | } |
||
78 |
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.