Conditions | 3 |
Paths | 4 |
Total Lines | 131 |
Code Lines | 10 |
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 |
||
116 | * This option allows you to wrap local decorators |
||
117 | * ("\Aimeos\Admin\Jsonadm\Product\Decorator\*") around the Jsonadm |
||
118 | * client. |
||
119 | * |
||
120 | * admin/jsonadm/product/decorators/local = array( 'decorator2' ) |
||
121 | * |
||
122 | * This would add the decorator named "decorator2" defined by |
||
123 | * "\Aimeos\Admin\Jsonadm\Product\Decorator\Decorator2" only to the |
||
124 | * "product" Jsonadm client. |
||
125 | * |
||
126 | * @param array List of decorator names |
||
127 | * @since 2016.01 |
||
128 | * @category Developer |
||
129 | * @see admin/jsonadm/common/decorators/default |
||
130 | * @see admin/jsonadm/decorators/excludes |
||
131 | * @see admin/jsonadm/decorators/global |
||
132 | */ |
||
133 | |||
134 | |||
135 | private static $objects = []; |
||
136 | |||
137 | |||
138 | /** |
||
139 | * Creates the required client specified by the given path of client names. |
||
140 | * |
||
141 | * Clients are created by providing only the domain name, e.g. "product" |
||
142 | * for the \Aimeos\Admin\JsonAdm\Product\Standard or a path of names to |
||
143 | * retrieve a specific sub-client, e.g. "product/type" for the |
||
144 | * \Aimeos\Admin\JsonAdm\Product\Type\Standard client. |
||
145 | * |
||
146 | * @param \Aimeos\MShop\ContextIface $context Context object required by clients |
||
147 | * @param \Aimeos\Bootstrap $aimeos Aimeos Bootstrap object |
||
148 | * @param string $path Name of the client separated by slashes, e.g "product/property" |
||
149 | * @param string|null $name Name of the client implementation ("Standard" if null) |
||
150 | * @return \Aimeos\Admin\JsonAdm\Iface JSON admin instance |
||
151 | * @throws \Aimeos\Admin\JsonAdm\Exception If the given path is invalid |
||
152 | */ |
||
153 | public static function create( \Aimeos\MShop\ContextIface $context, |
||
154 | \Aimeos\Bootstrap $aimeos, string $path, string $name = null ) : \Aimeos\Admin\JsonAdm\Iface |
||
155 | { |
||
156 | if( preg_match( '/^[a-z0-9\/]+$/', $path ) !== 1 ) { |
||
157 | throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Invalid component path "%1$s"', $path, 404 ) ); |
||
158 | } |
||
159 | |||
160 | empty( $path = trim( $path, '/' ) ) ?: $path .= '/'; |
||
161 | |||
162 | $view = $context->view(); |
||
163 | $config = $context->config(); |
||
164 | |||
165 | if( $view->access( $config->get( 'admin/jsonadm/resource/' . $path . 'groups', [] ) ) !== true ) { |
||
166 | throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Not allowed to access JsonAdm "%1$s" client', $path ), 403 ); |
||
|
|||
167 | } |
||
168 | |||
169 | $cname = $name ?: $context->config()->get( 'admin/jsonadm/' . $path . 'name', 'Standard' ); |
||
170 | |||
171 | $classname = '\\Aimeos\\Admin\\JsonAdm\\' . str_replace( '/', '\\', ucwords( $path, '/' ) ) . $cname; |
||
172 | $interface = '\\Aimeos\\Admin\\JsonAdm\\Iface'; |
||
173 | |||
174 | if( class_exists( $classname ) === false ) |
||
175 | { |
||
176 | $cname = $name ?: $context->config()->get( 'admin/jsonadm/name', 'Standard' ); |
||
177 | $classname = '\\Aimeos\\Admin\\JsonAdm\\' . $cname; |
||
178 | |||
179 | if( class_exists( $classname ) === false ) { |
||
180 | throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Class "%1$s" not found', $classname, 404 ) ); |
||
181 | } |
||
182 | } |
||
183 | |||
184 | $client = self::createComponent( $context, $classname, $interface, $path ); |
||
185 | $client = self::addComponentDecorators( $context, $client, $path ); |
||
186 | |||
187 | return $client->setAimeos( $aimeos )->setView( $view ); |
||
188 | } |
||
189 | |||
190 | |||
191 | /** |
||
192 | * Injects a client object |
||
193 | * |
||
194 | * The object is returned via create() if an instance of the class |
||
195 | * with the name name is requested. |
||
196 | * |
||
197 | * @param string $classname Full name of the class for which the object should be returned |
||
198 | * @param \Aimeos\Admin\JsonAdm\Iface|null $client JSON API client object |
||
199 | */ |
||
200 | public static function inject( string $classname, \Aimeos\Admin\JsonAdm\Iface $client = null ) |
||
201 | { |
||
202 | self::$objects['\\' . ltrim( $classname, '\\' )] = $client; |
||
203 | } |
||
204 | |||
205 | |||
206 | /** |
||
207 | * Adds the decorators to the JSON API client object |
||
208 | * |
||
209 | * @param \Aimeos\MShop\ContextIface $context Context instance with necessary objects |
||
210 | * @param \Aimeos\Admin\JsonAdm\Common\Iface $client Client object |
||
211 | * @param string $path Name of the client separated by slashes, e.g "product/property" |
||
212 | * @return \Aimeos\Admin\JsonAdm\Iface Client object |
||
213 | */ |
||
214 | protected static function addComponentDecorators( \Aimeos\MShop\ContextIface $context, |
||
215 | \Aimeos\Admin\JsonAdm\Iface $client, string $path ) : \Aimeos\Admin\JsonAdm\Iface |
||
216 | { |
||
217 | $localClass = str_replace( '/', '\\', ucwords( $path, '/' ) ); |
||
218 | $config = $context->config(); |
||
219 | |||
220 | /** admin/jsonadm/common/decorators/default |
||
221 | * Configures the list of decorators applied to all JSON API clients |
||
222 | * |
||
223 | * Decorators extend the functionality of a class by adding new aspects |
||
224 | * (e.g. log what is currently done), executing the methods of the underlying |
||
225 | * class only in certain conditions (e.g. only for logged in users) or |
||
226 | * modify what is returned to the caller. |
||
227 | * |
||
228 | * This option allows you to configure a list of decorator names that should |
||
229 | * be wrapped around the original instance of all created clients: |
||
230 | * |
||
231 | * admin/jsonadm/common/decorators/default = array( 'decorator1', 'decorator2' ) |
||
232 | * |
||
233 | * This would wrap the decorators named "decorator1" and "decorator2" around |
||
234 | * all client instances in that order. The decorator classes would be |
||
235 | * "\Aimeos\Admin\JsonAdm\Common\Decorator\Decorator1" and |
||
236 | * "\Aimeos\Admin\JsonAdm\Common\Decorator\Decorator2". |
||
237 | * |
||
238 | * @param array List of decorator names |
||
239 | * @since 2015.12 |
||
240 | * @category Developer |
||
241 | */ |
||
242 | $decorators = $config->get( 'admin/jsonadm/common/decorators/default', [] ); |
||
243 | $excludes = $config->get( 'admin/jsonadm/' . $path . 'decorators/excludes', [] ); |
||
244 | |||
245 | foreach( $decorators as $key => $name ) |
||
246 | { |
||
247 | if( in_array( $name, $excludes ) ) { |
||
337 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths