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 |
||
9 | class Laposta |
||
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | private $apiKey; |
||
15 | |||
16 | /** |
||
17 | * @var Client |
||
18 | */ |
||
19 | private $client; |
||
20 | |||
21 | public function __construct($apiKey = null, $client = null) |
||
39 | |||
40 | /** |
||
41 | * @return List_[] |
||
42 | */ |
||
43 | public function getLists() |
||
55 | |||
56 | /** |
||
57 | * @param $listId |
||
58 | * @return bool|List_ |
||
59 | */ |
||
60 | public function getList($listId) |
||
68 | |||
69 | View Code Duplication | public function createList(List_ $list) |
|
82 | |||
83 | View Code Duplication | public function updateList(List_ $list) |
|
94 | |||
95 | private function get($uri, $options = []) |
||
99 | |||
100 | private function post($uri, $options = []) |
||
104 | |||
105 | private function request($method, $uri, $options = []) |
||
117 | } |
||
118 |
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.