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 |
||
11 | class MockClass |
||
12 | { |
||
13 | 2 | public function __construct() |
|
16 | |||
17 | public function __destruct() |
||
20 | |||
21 | public function __get($name) |
||
24 | |||
25 | /** |
||
26 | * @desc MethodParser to logging |
||
27 | * @param string $message |
||
28 | */ |
||
29 | private function _toLog($message) |
||
33 | |||
34 | public function getConstValue() |
||
38 | |||
39 | /** |
||
40 | * @WebMethod |
||
41 | * @desc to sum two integers |
||
42 | * @param int $a |
||
43 | * @param int $b |
||
44 | * @return int |
||
45 | */ |
||
46 | 1 | public function sum($a, $b) |
|
50 | |||
51 | /** |
||
52 | * @WebMethod |
||
53 | * @param object $object1 @string=$name @int=$id |
||
54 | * @return object $return @string=$new_name @int=$new_id |
||
55 | */ |
||
56 | View Code Duplication | public function arrayTest($object1) |
|
63 | |||
64 | /** |
||
65 | * @WebMethod |
||
66 | * @param wrapper $wrap @className=\Mocks\MockUserWrapper |
||
67 | * @return bool |
||
68 | */ |
||
69 | public function methodWithWrapper($wrap) |
||
73 | |||
74 | /** |
||
75 | * @WebMethod |
||
76 | * @return wrapper[] $mockUsers @className=\Mocks\MockUserWrapper |
||
77 | */ |
||
78 | 1 | public function arrayOfMockUser() |
|
96 | |||
97 | /** |
||
98 | * @WebMethod |
||
99 | * noReturnFunction |
||
100 | * |
||
101 | * @param int $a |
||
102 | */ |
||
103 | 1 | public function noReturnFunction($a) |
|
107 | |||
108 | /** |
||
109 | * @WebMethod |
||
110 | * voidReturnFunction |
||
111 | * |
||
112 | * @param int $a |
||
113 | * @return void |
||
114 | */ |
||
115 | 1 | public function voidReturnFunction($a) |
|
119 | } |
||
120 |