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