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 |
||
10 | class ZanoxEx extends ZanoxOara |
||
11 | { |
||
12 | /** |
||
13 | * Call protected/private method of a class. |
||
14 | * |
||
15 | * @param object &$object Instantiated object that we will run method on. |
||
16 | * @param string $methodName Method name to call |
||
17 | * @param array $parameters Array of parameters to pass into method. |
||
18 | * |
||
19 | * @return mixed Method return. |
||
20 | */ |
||
21 | View Code Duplication | public function invokeMethod(&$object,$methodName, array $parameters = array()) |
|
28 | |||
29 | /** |
||
30 | * Call protected/private property of a class. |
||
31 | * @param $object |
||
32 | * @param $propertyName |
||
33 | * |
||
34 | * @return mixed |
||
35 | */ |
||
36 | View Code Duplication | public function invokeProperty(&$object,$propertyName) |
|
43 | /** |
||
44 | * get Sales updated/created on the date passed |
||
45 | * @param $date |
||
46 | * @param $page |
||
47 | * @param $pageSize |
||
48 | * @param int $iteration |
||
49 | * |
||
50 | * @return array |
||
51 | */ |
||
52 | protected function getSales($date, $page, $pageSize, $iteration = 0) |
||
67 | |||
68 | public function getProducts(array $params = [], $iteration = 0) |
||
91 | |||
92 | public function getApiClient(){ |
||
95 | } |
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.