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 |
||
17 | class FBUser |
||
18 | { |
||
19 | |||
20 | protected $config = []; |
||
21 | protected $client = null; |
||
22 | |||
23 | /** |
||
24 | * Message constructor. |
||
25 | * @param array $config |
||
26 | */ |
||
27 | 28 | View Code Duplication | public function __construct(array $config, Client $client) |
39 | |||
40 | /** |
||
41 | * @return array |
||
42 | */ |
||
43 | 4 | public function getConfig() |
|
47 | |||
48 | /** |
||
49 | * @return Client|null |
||
50 | */ |
||
51 | 4 | public function getClient() |
|
55 | |||
56 | |||
57 | 28 | protected function checkConfig(array $config) |
|
61 | |||
62 | |||
63 | 16 | public function getProfile($uid, $fields = ['fields' => 'first_name,last_name,profile_pic,locale,timezone,gender']) |
|
68 | |||
69 | |||
70 | 16 | public function callSendAPI($uid, $data) |
|
87 | |||
88 | } |
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.