Conditions | 7 |
Paths | 5 |
Total Lines | 63 |
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\Context\Item\Iface $context, $path ) |
||
50 | { |
||
51 | $config = $context->getConfig(); |
||
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( $path !== null && is_string( $path ) ) |
||
78 | { |
||
79 | $dpath = trim( $path, '/' ); |
||
80 | $dpath = ( $dpath !== '' ? $dpath . '/' : $dpath ); |
||
81 | |||
82 | $excludes = $config->get( 'admin/jsonadm/' . $dpath . 'decorators/excludes', [] ); |
||
83 | $localClass = str_replace( ' ', '\\', ucwords( str_replace( '/', ' ', $path ) ) ); |
||
84 | |||
85 | foreach( $decorators as $key => $name ) |
||
86 | { |
||
87 | if( in_array( $name, $excludes ) ) { |
||
88 | unset( $decorators[$key] ); |
||
89 | } |
||
90 | } |
||
91 | |||
92 | $classprefix = '\\Aimeos\\Admin\\JsonAdm\\Common\\Decorator\\'; |
||
93 | $decorators = $config->get( 'admin/jsonadm/' . $dpath . 'decorators/global', [] ); |
||
94 | $client = self::addDecorators( $client, $decorators, $classprefix, $context, $path ); |
||
95 | |||
96 | if( !empty( $path ) ) |
||
97 | { |
||
98 | $classprefix = '\\Aimeos\\Admin\\JsonAdm\\' . ucfirst( $localClass ) . '\\Decorator\\'; |
||
99 | $decorators = $config->get( 'admin/jsonadm/' . $dpath . 'decorators/local', [] ); |
||
100 | $client = self::addDecorators( $client, $decorators, $classprefix, $context, $path ); |
||
101 | } |
||
102 | } |
||
103 | else |
||
104 | { |
||
105 | $classprefix = '\\Aimeos\\Admin\\JsonAdm\\Common\\Decorator\\'; |
||
106 | $client = self::addDecorators( $client, $decorators, $classprefix, $context, $path ); |
||
107 | } |
||
108 | |||
109 | return $client; |
||
110 | } |
||
111 | |||
175 |