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 |
||
8 | class Salesforce |
||
9 | { |
||
10 | /** |
||
11 | * @var string |
||
12 | */ |
||
13 | protected $objName; |
||
14 | |||
15 | public $baseUrl; |
||
16 | |||
17 | public $instanceUrl; |
||
18 | |||
19 | public $client; |
||
20 | |||
21 | /** |
||
22 | * Salesforce constructor. |
||
23 | * |
||
24 | * @param ClientInterface $client |
||
25 | * @param string $url |
||
26 | * @param string $instanceUrl |
||
27 | */ |
||
28 | public function __construct(ClientInterface $client, string $url, string $instanceUrl) |
||
34 | |||
35 | /** |
||
36 | * @param string $method |
||
37 | * @param array $args |
||
38 | * @return bool|mixed|string |
||
39 | */ |
||
40 | public function __call($method, $args) |
||
66 | |||
67 | /** |
||
68 | * Create object dynamically |
||
69 | * |
||
70 | * @param $method |
||
71 | * @param $args |
||
72 | * @return bool |
||
73 | */ |
||
74 | View Code Duplication | private function callCreateOnObject($method, $args) |
|
85 | |||
86 | View Code Duplication | private function callUpdateOnObject($method, $args) |
|
97 | |||
98 | View Code Duplication | private function callDeleteOnObject($method, $args) |
|
109 | |||
110 | private function callGetOnObject($method, $args) |
||
121 | |||
122 | private function callInitObject($method) |
||
133 | } |
||
134 |
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.