Conditions | 4 |
Paths | 6 |
Total Lines | 131 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
160 | protected static function createClientRoot( \Aimeos\MShop\Context\Item\Iface $context, |
||
161 | \Aimeos\MW\View\Iface $view, array $templatePaths, $path, $name = null ) |
||
162 | { |
||
163 | /** admin/jsonadm/name |
||
164 | * Class name of the used JSON API client implementation |
||
165 | * |
||
166 | * Each default JSON API client can be replace by an alternative imlementation. |
||
167 | * To use this implementation, you have to set the last part of the class |
||
168 | * name as configuration value so the client factory knows which class it |
||
169 | * has to instantiate. |
||
170 | * |
||
171 | * For example, if the name of the default class is |
||
172 | * |
||
173 | * \Aimeos\Admin\JsonAdm\Standard |
||
174 | * |
||
175 | * and you want to replace it with your own version named |
||
176 | * |
||
177 | * \Aimeos\Admin\JsonAdm\Mycntl |
||
178 | * |
||
179 | * then you have to set the this configuration option: |
||
180 | * |
||
181 | * admin/jsonadm/name = Mycntl |
||
182 | * |
||
183 | * The value is the last part of your own class name and it's case sensitive, |
||
184 | * so take care that the configuration value is exactly named like the last |
||
185 | * part of the class name. |
||
186 | * |
||
187 | * The allowed characters of the class name are A-Z, a-z and 0-9. No other |
||
188 | * characters are possible! You should always start the last part of the class |
||
189 | * name with an upper case character and continue only with lower case characters |
||
190 | * or numbers. Avoid chamel case names like "MyCntl"! |
||
191 | * |
||
192 | * @param string Last part of the class name |
||
193 | * @since 2015.12 |
||
194 | * @category Developer |
||
195 | */ |
||
196 | if( $name === null ) { |
||
197 | $name = $context->getConfig()->get( 'admin/jsonadm/name', 'Standard' ); |
||
198 | } |
||
199 | |||
200 | if( ctype_alnum( $name ) === false ) |
||
201 | { |
||
202 | $classname = is_string( $name ) ? '\\Aimeos\\Admin\\JsonAdm\\' . $name : '<not a string>'; |
||
203 | throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Invalid class name "%1$s"', $classname ) ); |
||
204 | } |
||
205 | |||
206 | $iface = '\\Aimeos\\Admin\\JsonAdm\\Iface'; |
||
207 | $classname = '\\Aimeos\\Admin\\JsonAdm\\' . $name; |
||
208 | |||
209 | $client = self::createClientBase( $classname, $iface, $context, $view, $templatePaths, $path ); |
||
210 | |||
211 | /** admin/jsonadm/decorators/excludes |
||
212 | * Excludes decorators added by the "common" option from the JSON API clients |
||
213 | * |
||
214 | * Decorators extend the functionality of a class by adding new aspects |
||
215 | * (e.g. log what is currently done), executing the methods of the underlying |
||
216 | * class only in certain conditions (e.g. only for logged in users) or |
||
217 | * modify what is returned to the caller. |
||
218 | * |
||
219 | * This option allows you to remove a decorator added via |
||
220 | * "admin/jsonadm/common/decorators/default" before they are wrapped |
||
221 | * around the Jsonadm client. |
||
222 | * |
||
223 | * admin/jsonadm/decorators/excludes = array( 'decorator1' ) |
||
224 | * |
||
225 | * This would remove the decorator named "decorator1" from the list of |
||
226 | * common decorators ("\Aimeos\Admin\JsonAdm\Common\Decorator\*") added via |
||
227 | * "admin/jsonadm/common/decorators/default" for the JSON API client. |
||
228 | * |
||
229 | * @param array List of decorator names |
||
230 | * @since 2016.01 |
||
231 | * @category Developer |
||
232 | * @see admin/jsonadm/common/decorators/default |
||
233 | * @see admin/jsonadm/decorators/global |
||
234 | * @see admin/jsonadm/decorators/local |
||
235 | */ |
||
236 | |||
237 | /** admin/jsonadm/decorators/global |
||
238 | * Adds a list of globally available decorators only to the Jsonadm client |
||
239 | * |
||
240 | * Decorators extend the functionality of a class by adding new aspects |
||
241 | * (e.g. log what is currently done), executing the methods of the underlying |
||
242 | * class only in certain conditions (e.g. only for logged in users) or |
||
243 | * modify what is returned to the caller. |
||
244 | * |
||
245 | * This option allows you to wrap global decorators |
||
246 | * ("\Aimeos\Admin\Jsonadm\Common\Decorator\*") around the Jsonadm |
||
247 | * client. |
||
248 | * |
||
249 | * admin/jsonadm/product/decorators/global = array( 'decorator1' ) |
||
250 | * |
||
251 | * This would add the decorator named "decorator1" defined by |
||
252 | * "\Aimeos\Admin\Jsonadm\Common\Decorator\Decorator1" only to the |
||
253 | * "product" Jsonadm client. |
||
254 | * |
||
255 | * @param array List of decorator names |
||
256 | * @since 2016.01 |
||
257 | * @category Developer |
||
258 | * @see admin/jsonadm/common/decorators/default |
||
259 | * @see admin/jsonadm/decorators/excludes |
||
260 | * @see admin/jsonadm/decorators/local |
||
261 | */ |
||
262 | |||
263 | /** admin/jsonadm/decorators/local |
||
264 | * Adds a list of local decorators only to the Jsonadm client |
||
265 | * |
||
266 | * Decorators extend the functionality of a class by adding new aspects |
||
267 | * (e.g. log what is currently done), executing the methods of the underlying |
||
268 | * class only in certain conditions (e.g. only for logged in users) or |
||
269 | * modify what is returned to the caller. |
||
270 | * |
||
271 | * This option allows you to wrap local decorators |
||
272 | * ("\Aimeos\Admin\Jsonadm\Product\Decorator\*") around the Jsonadm |
||
273 | * client. |
||
274 | * |
||
275 | * admin/jsonadm/product/decorators/local = array( 'decorator2' ) |
||
276 | * |
||
277 | * This would add the decorator named "decorator2" defined by |
||
278 | * "\Aimeos\Admin\Jsonadm\Product\Decorator\Decorator2" only to the |
||
279 | * "product" Jsonadm client. |
||
280 | * |
||
281 | * @param array List of decorator names |
||
282 | * @since 2016.01 |
||
283 | * @category Developer |
||
284 | * @see admin/jsonadm/common/decorators/default |
||
285 | * @see admin/jsonadm/decorators/excludes |
||
286 | * @see admin/jsonadm/decorators/global |
||
287 | */ |
||
288 | |||
289 | return self::addClientDecorators( $client, $context, $view, $templatePaths, $path ); |
||
290 | } |
||
291 | } |
||
292 |