Conditions | 5 |
Paths | 7 |
Total Lines | 58 |
Code Lines | 20 |
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 |
||
48 | protected static function addClientDecorators( \Aimeos\Admin\JsonAdm\Iface $client, |
||
49 | \Aimeos\MShop\ContextIface $context, string $path ) : \Aimeos\Admin\JsonAdm\Iface |
||
50 | { |
||
51 | $config = $context->config(); |
||
52 | |||
53 | /** admin/jsonadm/common/decorators/default |
||
54 | * Configures the list of decorators applied to all JSON API clients |
||
55 | * |
||
56 | * Decorators extend the functionality of a class by adding new aspects |
||
57 | * (e.g. log what is currently done), executing the methods of the underlying |
||
58 | * class only in certain conditions (e.g. only for logged in users) or |
||
59 | * modify what is returned to the caller. |
||
60 | * |
||
61 | * This option allows you to configure a list of decorator names that should |
||
62 | * be wrapped around the original instance of all created clients: |
||
63 | * |
||
64 | * admin/jsonadm/common/decorators/default = array( 'decorator1', 'decorator2' ) |
||
65 | * |
||
66 | * This would wrap the decorators named "decorator1" and "decorator2" around |
||
67 | * all client instances in that order. The decorator classes would be |
||
68 | * "\Aimeos\Admin\JsonAdm\Common\Decorator\Decorator1" and |
||
69 | * "\Aimeos\Admin\JsonAdm\Common\Decorator\Decorator2". |
||
70 | * |
||
71 | * @param array List of decorator names |
||
72 | * @since 2015.12 |
||
73 | * @category Developer |
||
74 | */ |
||
75 | $decorators = $config->get( 'admin/jsonadm/common/decorators/default', [] ); |
||
76 | |||
77 | if( empty( $path ) ) |
||
78 | { |
||
79 | $classprefix = '\\Aimeos\\Admin\\JsonAdm\\Common\\Decorator\\'; |
||
80 | return self::addDecorators( $client, $decorators, $classprefix, $context, $path ); |
||
81 | } |
||
82 | |||
83 | $dpath = trim( $path, '/' ); |
||
84 | $dpath = ( $dpath !== '' ? $dpath . '/' : $dpath ); |
||
85 | |||
86 | $excludes = $config->get( 'admin/jsonadm/' . $dpath . 'decorators/excludes', [] ); |
||
87 | $localClass = str_replace( '/', '\\', ucwords( $path, '/' ) ); |
||
88 | |||
89 | foreach( $decorators as $key => $name ) |
||
90 | { |
||
91 | if( in_array( $name, $excludes ) ) { |
||
92 | unset( $decorators[$key] ); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | $classprefix = '\\Aimeos\\Admin\\JsonAdm\\Common\\Decorator\\'; |
||
97 | $client = self::addDecorators( $client, $decorators, $classprefix, $context, $path ); |
||
98 | |||
99 | $classprefix = '\\Aimeos\\Admin\\JsonAdm\\Common\\Decorator\\'; |
||
100 | $decorators = $config->get( 'admin/jsonadm/' . $dpath . 'decorators/global', [] ); |
||
101 | $client = self::addDecorators( $client, $decorators, $classprefix, $context, $path ); |
||
102 | |||
103 | $classprefix = '\\Aimeos\\Admin\\JsonAdm\\' . ucfirst( $localClass ) . '\\Decorator\\'; |
||
104 | $decorators = $config->get( 'admin/jsonadm/' . $dpath . 'decorators/local', [] ); |
||
105 | return self::addDecorators( $client, $decorators, $classprefix, $context, $path ); |
||
106 | } |
||
157 |