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 |
||
29 | class InspectorPooler extends ClientPooler |
||
30 | { |
||
31 | /** |
||
32 | * getPoolerType |
||
33 | * |
||
34 | * @see ClientPoolerInterface |
||
35 | */ |
||
36 | public function getPoolerType() |
||
40 | |||
41 | /** |
||
42 | * getClient |
||
43 | * |
||
44 | * @see ClientPooler |
||
45 | * @param null|string $identifier |
||
46 | * @return Inspector |
||
47 | */ |
||
48 | public function getClient($identifier = null) |
||
56 | |||
57 | /** |
||
58 | * createClient |
||
59 | * |
||
60 | * @see ClientPooler |
||
61 | * @return Inspector |
||
62 | * @throws FoundationException |
||
63 | */ |
||
64 | protected function createClient($identifier) |
||
73 | |||
74 | /** |
||
75 | * createBuiltinClient |
||
76 | * |
||
77 | * Return an instance of a builtin inspector from its short name. Throws an |
||
78 | * exception if the built in inspector does not exist. |
||
79 | * |
||
80 | * @param string $identifier |
||
81 | * @throws FoundationException |
||
82 | * @return ClientInterface |
||
83 | */ |
||
84 | private function createBuiltinClient($identifier) |
||
103 | |||
104 | /** |
||
105 | * createCustomClient |
||
106 | * |
||
107 | * Load a custom inspector client. Throws an exception if class cannot be |
||
108 | * loaded or is not a ClientInterface. |
||
109 | * |
||
110 | * @param string $identifier |
||
111 | * @throws FoundationException |
||
112 | * @return ClientInterface |
||
113 | */ |
||
114 | View Code Duplication | private function createCustomClient($identifier) |
|
140 | } |
||
141 |
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.