Conditions | 4 |
Paths | 5 |
Total Lines | 134 |
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 |
||
33 | public static function create( \Aimeos\MShop\Context\Item\Iface $context, string $path, string $name = null ) : \Aimeos\Client\JsonApi\Iface |
||
34 | { |
||
35 | if( ctype_alnum( $path ) === false ) { |
||
36 | throw new \Aimeos\Client\JsonApi\Exception( sprintf( 'Invalid client "%1$s"', $path ), 400 ); |
||
37 | } |
||
38 | |||
39 | /** client/jsonapi/site/name |
||
40 | * Class name of the used site client implementation |
||
41 | * |
||
42 | * Each default JSON API client can be replace by an alternative imlementation. |
||
43 | * To use this implementation, you have to set the last part of the class |
||
44 | * name as configuration value so the client factory knows which class it |
||
45 | * has to instantiate. |
||
46 | * |
||
47 | * For example, if the name of the default class is |
||
48 | * |
||
49 | * \Aimeos\Client\JsonApi\Site\Standard |
||
50 | * |
||
51 | * and you want to replace it with your own version named |
||
52 | * |
||
53 | * \Aimeos\Client\JsonApi\Site\Mysite |
||
54 | * |
||
55 | * then you have to set the this configuration option: |
||
56 | * |
||
57 | * client/jsonapi/site/name = Mysite |
||
58 | * |
||
59 | * The value is the last part of your own class name and it's case sensitive, |
||
60 | * so take care that the configuration value is exactly named like the last |
||
61 | * part of the class name. |
||
62 | * |
||
63 | * The allowed characters of the class name are A-Z, a-z and 0-9. No other |
||
64 | * characters are possible! You should always start the last part of the class |
||
65 | * name with an upper case character and continue only with lower case characters |
||
66 | * or numbers. Avoid chamel case names like "MySite"! |
||
67 | * |
||
68 | * @param string Last part of the class name |
||
69 | * @since 2021.04 |
||
70 | * @category Developer |
||
71 | */ |
||
72 | if( $name === null ) { |
||
73 | $name = $context->getConfig()->get( 'client/jsonapi/site/name', 'Standard' ); |
||
74 | } |
||
75 | |||
76 | $iface = '\\Aimeos\\Client\\JsonApi\\Iface'; |
||
77 | $classname = '\\Aimeos\\Client\\JsonApi\\Site\\' . $name; |
||
78 | |||
79 | if( ctype_alnum( $name ) === false ) { |
||
80 | throw new \Aimeos\Client\JsonApi\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); |
||
81 | } |
||
82 | |||
83 | $client = self::createClient( $classname, $iface, $context, $path ); |
||
84 | |||
85 | |||
86 | /** client/jsonapi/site/decorators/excludes |
||
87 | * Excludes decorators added by the "common" option from the JSON API clients |
||
88 | * |
||
89 | * Decorators extend the functionality of a class by adding new aspects |
||
90 | * (e.g. log what is currently done), executing the methods of the underlying |
||
91 | * class only in certain conditions (e.g. only for logged in users) or |
||
92 | * modify what is returned to the caller. |
||
93 | * |
||
94 | * This option allows you to remove a decorator added via |
||
95 | * "client/jsonapi/common/decorators/default" before they are wrapped |
||
96 | * around the JsonApi client. |
||
97 | * |
||
98 | * client/jsonapi/decorators/excludes = array( 'decorator1' ) |
||
99 | * |
||
100 | * This would remove the decorator named "decorator1" from the list of |
||
101 | * common decorators ("\Aimeos\Client\JsonApi\Common\Decorator\*") added via |
||
102 | * "client/jsonapi/common/decorators/default" for the JSON API client. |
||
103 | * |
||
104 | * @param array List of decorator names |
||
105 | * @since 2021.04 |
||
106 | * @category Developer |
||
107 | * @see client/jsonapi/common/decorators/default |
||
108 | * @see client/jsonapi/site/decorators/global |
||
109 | * @see client/jsonapi/site/decorators/local |
||
110 | */ |
||
111 | |||
112 | /** client/jsonapi/site/decorators/global |
||
113 | * Adds a list of globally available decorators only to the JsonApi client |
||
114 | * |
||
115 | * Decorators extend the functionality of a class by adding new aspects |
||
116 | * (e.g. log what is currently done), executing the methods of the underlying |
||
117 | * class only in certain conditions (e.g. only for logged in users) or |
||
118 | * modify what is returned to the caller. |
||
119 | * |
||
120 | * This option allows you to wrap global decorators |
||
121 | * ("\Aimeos\Client\JsonApi\Common\Decorator\*") around the JsonApi |
||
122 | * client. |
||
123 | * |
||
124 | * client/jsonapi/site/decorators/global = array( 'decorator1' ) |
||
125 | * |
||
126 | * This would add the decorator named "decorator1" defined by |
||
127 | * "\Aimeos\Client\JsonApi\Common\Decorator\Decorator1" only to the |
||
128 | * "site" JsonApi client. |
||
129 | * |
||
130 | * @param array List of decorator names |
||
131 | * @since 2021.04 |
||
132 | * @category Developer |
||
133 | * @see client/jsonapi/common/decorators/default |
||
134 | * @see client/jsonapi/site/decorators/excludes |
||
135 | * @see client/jsonapi/site/decorators/local |
||
136 | */ |
||
137 | |||
138 | /** client/jsonapi/site/decorators/local |
||
139 | * Adds a list of local decorators only to the JsonApi client |
||
140 | * |
||
141 | * Decorators extend the functionality of a class by adding new aspects |
||
142 | * (e.g. log what is currently done), executing the methods of the underlying |
||
143 | * class only in certain conditions (e.g. only for logged in users) or |
||
144 | * modify what is returned to the caller. |
||
145 | * |
||
146 | * This option allows you to wrap local decorators |
||
147 | * ("\Aimeos\Client\JsonApi\Site\Decorator\*") around the JsonApi |
||
148 | * client. |
||
149 | * |
||
150 | * client/jsonapi/site/decorators/local = array( 'decorator2' ) |
||
151 | * |
||
152 | * This would add the decorator named "decorator2" defined by |
||
153 | * "\Aimeos\Client\JsonApi\Site\Decorator\Decorator2" only to the |
||
154 | * "site" JsonApi client. |
||
155 | * |
||
156 | * @param array List of decorator names |
||
157 | * @since 2021.04 |
||
158 | * @category Developer |
||
159 | * @see client/jsonapi/common/decorators/default |
||
160 | * @see client/jsonapi/site/decorators/excludes |
||
161 | * @see client/jsonapi/site/decorators/global |
||
162 | */ |
||
163 | |||
164 | $client = self::addClientDecorators( $client, $context, $path ); |
||
165 | |||
166 | return $client->setView( $context->getView() ); |
||
|
|||
167 | } |
||
170 |