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