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