Conditions | 5 |
Paths | 4 |
Total Lines | 54 |
Code Lines | 18 |
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 |
||
83 | protected static function addControllerDecorators( \Aimeos\MShop\Context\Item\Iface $context, |
||
84 | \Aimeos\Controller\Frontend\Iface $controller, $domain ) |
||
85 | { |
||
86 | if( !is_string( $domain ) || $domain === '' ) { |
||
|
|||
87 | throw new \Aimeos\Controller\Frontend\Exception( sprintf( 'Invalid domain "%1$s"', $domain ) ); |
||
88 | } |
||
89 | |||
90 | $localClass = str_replace( ' ', '\\', ucwords( str_replace( '/', ' ', $domain ) ) ); |
||
91 | $config = $context->getConfig(); |
||
92 | |||
93 | /** controller/frontend/common/decorators/default |
||
94 | * Configures the list of decorators applied to all frontend controllers |
||
95 | * |
||
96 | * Decorators extend the functionality of a class by adding new aspects |
||
97 | * (e.g. log what is currently done), executing the methods of the underlying |
||
98 | * class only in certain conditions (e.g. only for logged in users) or |
||
99 | * modify what is returned to the caller. |
||
100 | * |
||
101 | * This option allows you to configure a list of decorator names that should |
||
102 | * be wrapped around the original instance of all created controllers: |
||
103 | * |
||
104 | * controller/frontend/common/decorators/default = array( 'decorator1', 'decorator2' ) |
||
105 | * |
||
106 | * This would wrap the decorators named "decorator1" and "decorator2" around |
||
107 | * all controller instances in that order. The decorator classes would be |
||
108 | * "\Aimeos\Controller\Frontend\Common\Decorator\Decorator1" and |
||
109 | * "\Aimeos\Controller\Frontend\Common\Decorator\Decorator2". |
||
110 | * |
||
111 | * @param array List of decorator names |
||
112 | * @since 2014.03 |
||
113 | * @category Developer |
||
114 | */ |
||
115 | $decorators = $config->get( 'controller/frontend/common/decorators/default', [] ); |
||
116 | $excludes = $config->get( 'controller/frontend/' . $domain . '/decorators/excludes', [] ); |
||
117 | |||
118 | foreach( $decorators as $key => $name ) |
||
119 | { |
||
120 | if( in_array( $name, $excludes ) ) { |
||
121 | unset( $decorators[$key] ); |
||
122 | } |
||
123 | } |
||
124 | |||
125 | $classprefix = '\\Aimeos\\Controller\\Frontend\\Common\\Decorator\\'; |
||
126 | $controller = self::addDecorators( $context, $controller, $decorators, $classprefix ); |
||
127 | |||
128 | $classprefix = '\\Aimeos\\Controller\\Frontend\\Common\\Decorator\\'; |
||
129 | $decorators = $config->get( 'controller/frontend/' . $domain . '/decorators/global', [] ); |
||
130 | $controller = self::addDecorators( $context, $controller, $decorators, $classprefix ); |
||
131 | |||
132 | $classprefix = '\\Aimeos\\Controller\\Frontend\\' . ucfirst( $localClass ) . '\\Decorator\\'; |
||
133 | $decorators = $config->get( 'controller/frontend/' . $domain . '/decorators/local', [] ); |
||
134 | $controller = self::addDecorators( $context, $controller, $decorators, $classprefix ); |
||
135 | |||
136 | return $controller; |
||
137 | } |
||
166 |