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 | /** |
||
16 | * @var SalesforceAuth |
||
17 | */ |
||
18 | private $auth; |
||
19 | |||
20 | /** |
||
21 | * Salesforce constructor. |
||
22 | * |
||
23 | * @param $client |
||
24 | * @param SalesforceAuth $auth |
||
25 | */ |
||
26 | public function __construct($client, SalesforceAuth $auth) |
||
31 | |||
32 | |||
33 | public function __call($method, $args) |
||
53 | |||
54 | View Code Duplication | private function callCreateOnObject($method, $args) |
|
65 | |||
66 | View Code Duplication | private function callUpdateOnObject($method, $args) |
|
77 | |||
78 | View Code Duplication | private function callDeleteOnObject($method, $args) |
|
89 | |||
90 | View Code Duplication | private function callGetOnObject($method, $args) |
|
101 | |||
102 | /** |
||
103 | * Run report. |
||
104 | * |
||
105 | * @param $params |
||
106 | * |
||
107 | * @return mixed |
||
108 | */ |
||
109 | public function runReport($params) |
||
118 | } |
||
119 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: