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 namespace Comodojo\RpcServer\Request; |
||
36 | class Parameters { |
||
37 | |||
38 | /** |
||
39 | * Array of provided parameters |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | private $parameters = []; |
||
44 | |||
45 | /** |
||
46 | * Supported capabilities |
||
47 | * |
||
48 | * @var Capabilities |
||
49 | */ |
||
50 | private $capabilities; |
||
51 | |||
52 | /** |
||
53 | * Implemented methods |
||
54 | * |
||
55 | * @var Methods |
||
56 | */ |
||
57 | private $methods; |
||
58 | |||
59 | /** |
||
60 | * Predefined errors |
||
61 | * |
||
62 | * @var Errors |
||
63 | */ |
||
64 | private $errors; |
||
65 | |||
66 | /** |
||
67 | * Current RPC protocol (json|rpc) |
||
68 | * |
||
69 | * @var string |
||
70 | */ |
||
71 | private $protocol; |
||
72 | |||
73 | /** |
||
74 | * Current logger |
||
75 | * |
||
76 | * @var LoggerInterface |
||
77 | */ |
||
78 | private $logger; |
||
79 | |||
80 | /** |
||
81 | * Class constructor |
||
82 | * |
||
83 | * @param Capabilities $capabilities |
||
84 | * @param Methods $methods |
||
85 | * @param Errors $errors |
||
86 | * @param LoggerInterface $logger |
||
87 | * @param string $protocol |
||
88 | */ |
||
89 | 84 | public function __construct( |
|
108 | |||
109 | /** |
||
110 | * Set provided parameters |
||
111 | * |
||
112 | * @param array $parameters |
||
113 | * |
||
114 | * @return Parameters |
||
115 | */ |
||
116 | 78 | final public function setParameters(array $parameters = []) { |
|
123 | |||
124 | /** |
||
125 | * Get capabilities object |
||
126 | * |
||
127 | * @deprecated |
||
128 | * @see Parameters::getCapabilities() |
||
129 | * @return Capabilities |
||
130 | */ |
||
131 | 21 | public function capabilities() { |
|
136 | |||
137 | /** |
||
138 | * Get capabilities object |
||
139 | * |
||
140 | * @deprecated |
||
141 | * @see Parameters::getCapabilities() |
||
142 | * @return Capabilities |
||
143 | */ |
||
144 | 21 | public function getCapabilities() { |
|
149 | |||
150 | /** |
||
151 | * Get methods object |
||
152 | * |
||
153 | * @deprecated |
||
154 | * @see Parameters::getMethods() |
||
155 | * @return Methods |
||
156 | */ |
||
157 | 84 | public function methods() { |
|
162 | |||
163 | /** |
||
164 | * Get methods object |
||
165 | * |
||
166 | * @return Methods |
||
167 | */ |
||
168 | 84 | public function getMethods() { |
|
173 | |||
174 | /** |
||
175 | * Get errors object |
||
176 | * |
||
177 | * @deprecated |
||
178 | * @see Parameters::getErrors() |
||
179 | * @return Errors |
||
180 | */ |
||
181 | 15 | public function errors() { |
|
186 | |||
187 | /** |
||
188 | * Get errors object |
||
189 | * |
||
190 | * @return Errors |
||
191 | */ |
||
192 | 15 | public function getErrors() { |
|
197 | |||
198 | /** |
||
199 | * Get current RPC protocol |
||
200 | * |
||
201 | * @deprecated |
||
202 | * @see Parameters::getProtocol() |
||
203 | * @return string |
||
204 | */ |
||
205 | 9 | public function protocol() { |
|
210 | |||
211 | /** |
||
212 | * Get current RPC protocol |
||
213 | * |
||
214 | * @return string |
||
215 | */ |
||
216 | 9 | public function getProtocol() { |
|
221 | |||
222 | /** |
||
223 | * Get current logger instance |
||
224 | * |
||
225 | * @deprecated |
||
226 | * @see Parameters::getLogger() |
||
227 | * @return LoggerInterface |
||
228 | */ |
||
229 | 6 | public function logger() { |
|
234 | |||
235 | /** |
||
236 | * Get current logger instance |
||
237 | * |
||
238 | * @return LoggerInterface |
||
239 | */ |
||
240 | 6 | public function getLogger() { |
|
245 | |||
246 | /** |
||
247 | * Get parameter(s) |
||
248 | * |
||
249 | * @param string $parameter (optional) The parameter name (null will return whole array of parameters) |
||
250 | * |
||
251 | * @return mixed |
||
252 | */ |
||
253 | 48 | View Code Duplication | public function get($parameter = null) { |
272 | |||
273 | } |
||
274 |
This method has been deprecated.