| Conditions | 4 |
| Paths | 6 |
| Total Lines | 132 |
| 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 |
||
| 151 | protected static function createRoot( \Aimeos\MShop\Context\Item\Iface $context, $path, $name = null ) |
||
| 152 | { |
||
| 153 | /** client/jsonapi/name |
||
| 154 | * Class name of the used JSON API client implementation |
||
| 155 | * |
||
| 156 | * Each default JSON API client can be replace by an alternative imlementation. |
||
| 157 | * To use this implementation, you have to set the last part of the class |
||
| 158 | * name as configuration value so the client factory knows which class it |
||
| 159 | * has to instantiate. |
||
| 160 | * |
||
| 161 | * For example, if the name of the default class is |
||
| 162 | * |
||
| 163 | * \Aimeos\Client\JsonApi\Standard |
||
| 164 | * |
||
| 165 | * and you want to replace it with your own version named |
||
| 166 | * |
||
| 167 | * \Aimeos\Client\JsonApi\Mycntl |
||
| 168 | * |
||
| 169 | * then you have to set the this configuration option: |
||
| 170 | * |
||
| 171 | * client/jsonapi/name = Mycntl |
||
| 172 | * |
||
| 173 | * The value is the last part of your own class name and it's case sensitive, |
||
| 174 | * so take care that the configuration value is exactly named like the last |
||
| 175 | * part of the class name. |
||
| 176 | * |
||
| 177 | * The allowed characters of the class name are A-Z, a-z and 0-9. No other |
||
| 178 | * characters are possible! You should always start the last part of the class |
||
| 179 | * name with an upper case character and continue only with lower case characters |
||
| 180 | * or numbers. Avoid chamel case names like "MyCntl"! |
||
| 181 | * |
||
| 182 | * @param string Last part of the class name |
||
| 183 | * @since 2015.12 |
||
| 184 | * @category Developer |
||
| 185 | */ |
||
| 186 | if( $name === null ) { |
||
| 187 | $name = $context->getConfig()->get( 'client/jsonapi/name', 'Standard' ); |
||
| 188 | } |
||
| 189 | |||
| 190 | if( ctype_alnum( $name ) === false ) |
||
| 191 | { |
||
| 192 | $classname = is_string( $name ) ? '\\Aimeos\\Client\\JsonApi\\' . $name : '<not a string>'; |
||
| 193 | throw new \Aimeos\Client\JsonApi\Exception( sprintf( 'Invalid class name "%1$s"', $classname ) ); |
||
| 194 | } |
||
| 195 | |||
| 196 | $iface = '\\Aimeos\\Client\\JsonApi\\Iface'; |
||
| 197 | $classname = '\\Aimeos\\Client\\JsonApi\\' . $name; |
||
| 198 | |||
| 199 | $client = self::createClientBase( $classname, $iface, $context, $path ); |
||
| 200 | |||
| 201 | /** client/jsonapi/decorators/excludes |
||
| 202 | * Excludes decorators added by the "common" option from the JSON API clients |
||
| 203 | * |
||
| 204 | * Decorators extend the functionality of a class by adding new aspects |
||
| 205 | * (e.g. log what is currently done), executing the methods of the underlying |
||
| 206 | * class only in certain conditions (e.g. only for logged in users) or |
||
| 207 | * modify what is returned to the caller. |
||
| 208 | * |
||
| 209 | * This option allows you to remove a decorator added via |
||
| 210 | * "client/jsonapi/common/decorators/default" before they are wrapped |
||
| 211 | * around the Jsonadm client. |
||
| 212 | * |
||
| 213 | * client/jsonapi/decorators/excludes = array( 'decorator1' ) |
||
| 214 | * |
||
| 215 | * This would remove the decorator named "decorator1" from the list of |
||
| 216 | * common decorators ("\Aimeos\Client\JsonApi\Common\Decorator\*") added via |
||
| 217 | * "client/jsonapi/common/decorators/default" for the JSON API client. |
||
| 218 | * |
||
| 219 | * @param array List of decorator names |
||
| 220 | * @since 2016.01 |
||
| 221 | * @category Developer |
||
| 222 | * @see client/jsonapi/common/decorators/default |
||
| 223 | * @see client/jsonapi/decorators/global |
||
| 224 | * @see client/jsonapi/decorators/local |
||
| 225 | */ |
||
| 226 | |||
| 227 | /** client/jsonapi/decorators/global |
||
| 228 | * Adds a list of globally available decorators only to the Jsonadm client |
||
| 229 | * |
||
| 230 | * Decorators extend the functionality of a class by adding new aspects |
||
| 231 | * (e.g. log what is currently done), executing the methods of the underlying |
||
| 232 | * class only in certain conditions (e.g. only for logged in users) or |
||
| 233 | * modify what is returned to the caller. |
||
| 234 | * |
||
| 235 | * This option allows you to wrap global decorators |
||
| 236 | * ("\Aimeos\Client\Jsonadm\Common\Decorator\*") around the Jsonadm |
||
| 237 | * client. |
||
| 238 | * |
||
| 239 | * client/jsonapi/product/decorators/global = array( 'decorator1' ) |
||
| 240 | * |
||
| 241 | * This would add the decorator named "decorator1" defined by |
||
| 242 | * "\Aimeos\Client\Jsonadm\Common\Decorator\Decorator1" only to the |
||
| 243 | * "product" Jsonadm client. |
||
| 244 | * |
||
| 245 | * @param array List of decorator names |
||
| 246 | * @since 2016.01 |
||
| 247 | * @category Developer |
||
| 248 | * @see client/jsonapi/common/decorators/default |
||
| 249 | * @see client/jsonapi/decorators/excludes |
||
| 250 | * @see client/jsonapi/decorators/local |
||
| 251 | */ |
||
| 252 | |||
| 253 | /** client/jsonapi/decorators/local |
||
| 254 | * Adds a list of local decorators only to the Jsonadm client |
||
| 255 | * |
||
| 256 | * Decorators extend the functionality of a class by adding new aspects |
||
| 257 | * (e.g. log what is currently done), executing the methods of the underlying |
||
| 258 | * class only in certain conditions (e.g. only for logged in users) or |
||
| 259 | * modify what is returned to the caller. |
||
| 260 | * |
||
| 261 | * This option allows you to wrap local decorators |
||
| 262 | * ("\Aimeos\Client\Jsonadm\Product\Decorator\*") around the Jsonadm |
||
| 263 | * client. |
||
| 264 | * |
||
| 265 | * client/jsonapi/product/decorators/local = array( 'decorator2' ) |
||
| 266 | * |
||
| 267 | * This would add the decorator named "decorator2" defined by |
||
| 268 | * "\Aimeos\Client\Jsonadm\Product\Decorator\Decorator2" only to the |
||
| 269 | * "product" Jsonadm client. |
||
| 270 | * |
||
| 271 | * @param array List of decorator names |
||
| 272 | * @since 2016.01 |
||
| 273 | * @category Developer |
||
| 274 | * @see client/jsonapi/common/decorators/default |
||
| 275 | * @see client/jsonapi/decorators/excludes |
||
| 276 | * @see client/jsonapi/decorators/global |
||
| 277 | */ |
||
| 278 | |||
| 279 | $client = self::addClientDecorators( $client, $context, $path ); |
||
| 280 | |||
| 281 | return $client->setView( $context->getView() ); |
||
| 282 | } |
||
| 283 | } |
||
| 284 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.