Conditions | 6 |
Paths | 7 |
Total Lines | 57 |
Code Lines | 13 |
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 |
||
34 | public static function createClient( \Aimeos\MShop\Context\Item\Iface $context, array $templatePaths, $path, $name = null ) |
||
35 | { |
||
36 | if( is_string( $path ) === false || preg_match( '#^[a-zA-Z0-9/]+$#', $path ) !== 1 ) { |
||
37 | throw new \Aimeos\Client\JsonApi\Exception( sprintf( 'Invalid client "%1$s"', $path ), 400 ); |
||
38 | } |
||
39 | |||
40 | /** client/jsonapi/customer/address/name |
||
41 | * Class name of the used customer/address client implementation |
||
42 | * |
||
43 | * Each default JSON API client can be replace by an alternative imlementation. |
||
44 | * To use this implementation, you have to set the last part of the class |
||
45 | * name as configuration value so the client factory knows which class it |
||
46 | * has to instantiate. |
||
47 | * |
||
48 | * For example, if the name of the default class is |
||
49 | * |
||
50 | * \Aimeos\Client\JsonApi\Customer\Address\Standard |
||
51 | * |
||
52 | * and you want to replace it with your own version named |
||
53 | * |
||
54 | * \Aimeos\Client\JsonApi\Customer\Address\Mycustomer/address |
||
55 | * |
||
56 | * then you have to set the this configuration option: |
||
57 | * |
||
58 | * client/jsonapi/customer/address/name = Mycustomer/address |
||
59 | * |
||
60 | * The value is the last part of your own class name and it's case sensitive, |
||
61 | * so take care that the configuration value is exactly named like the last |
||
62 | * part of the class name. |
||
63 | * |
||
64 | * The allowed characters of the class name are A-Z, a-z and 0-9. No other |
||
65 | * characters are possible! You should always start the last part of the class |
||
66 | * name with an upper case character and continue only with lower case characters |
||
67 | * or numbers. Avoid chamel case names like "MyAddress"! |
||
68 | * |
||
69 | * @param string Last part of the class name |
||
70 | * @since 2017.03 |
||
71 | * @category Developer |
||
72 | */ |
||
73 | if( $name === null ) { |
||
74 | $name = $context->getConfig()->get( 'client/jsonapi/customer/address/name', 'Standard' ); |
||
75 | } |
||
76 | |||
77 | if( ctype_alnum( $name ) === false ) |
||
78 | { |
||
79 | $classname = is_string( $name ) ? '\\Aimeos\\Client\\JsonApi\\Customer\\Address\\' . $name : '<not a string>'; |
||
80 | throw new \Aimeos\Client\JsonApi\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); |
||
81 | } |
||
82 | |||
83 | $view = $context->getView(); |
||
84 | $iface = '\\Aimeos\\Client\\JsonApi\\Iface'; |
||
85 | $classname = '\\Aimeos\\Client\\JsonApi\\Customer\\Address\\' . $name; |
||
86 | |||
87 | $client = self::createClientBase( $classname, $iface, $context, $view, $templatePaths, $path ); |
||
88 | |||
89 | return self::addClientDecorators( $client, $context, $view, $templatePaths, $path ); |
||
90 | } |
||
91 | |||
94 |