| Conditions | 4 |
| Paths | 6 |
| Total Lines | 51 |
| Code Lines | 9 |
| 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 |
||
| 34 | public static function create( \Aimeos\MShop\ContextIface $context, $name = null ) : Iface |
||
| 35 | { |
||
| 36 | /** controller/common/order/name |
||
| 37 | * Class name of the used order common controller implementation |
||
| 38 | * |
||
| 39 | * Each default common controller can be replace by an alternative imlementation. |
||
| 40 | * To use this implementation, you have to set the last part of the class |
||
| 41 | * name as configuration value so the controller factory knows which class it |
||
| 42 | * has to instantiate. |
||
| 43 | * |
||
| 44 | * For example, if the name of the default class is |
||
| 45 | * |
||
| 46 | * \Aimeos\Controller\Common\Order\Standard |
||
| 47 | * |
||
| 48 | * and you want to replace it with your own version named |
||
| 49 | * |
||
| 50 | * \Aimeos\Controller\Common\Order\Myorder |
||
| 51 | * |
||
| 52 | * then you have to set the this configuration option: |
||
| 53 | * |
||
| 54 | * controller/common/order/name = Myorder |
||
| 55 | * |
||
| 56 | * The value is the last part of your own class name and it's case sensitive, |
||
| 57 | * so take care that the configuration value is exactly named like the last |
||
| 58 | * part of the class name. |
||
| 59 | * |
||
| 60 | * The allowed characters of the class name are A-Z, a-z and 0-9. No other |
||
| 61 | * characters are possible! You should always start the last part of the class |
||
| 62 | * name with an upper case character and continue only with lower case characters |
||
| 63 | * or numbers. Avoid chamel case names like "MyOrder"! |
||
| 64 | * |
||
| 65 | * @param string Last part of the class name |
||
| 66 | * @since 2014.07 |
||
| 67 | * @category Developer |
||
| 68 | */ |
||
| 69 | if( $name === null ) { |
||
| 70 | $name = $context->config()->get( 'controller/common/order/name', 'Standard' ); |
||
| 71 | } |
||
| 72 | |||
| 73 | if( ctype_alnum( $name ) === false ) { |
||
| 74 | throw new \LogicException( sprintf( 'Invalid characters in class name "%1$s"', $name ), 400 ); |
||
| 75 | } |
||
| 76 | |||
| 77 | $classname = 'Aimeos\Controller\Common\Order\\' . $name; |
||
| 78 | $interface = \Aimeos\Controller\Common\Order\Iface::class; |
||
| 79 | |||
| 80 | if( isset( self::$objects[$classname] ) ) { |
||
| 81 | return self::$objects[$classname]; |
||
| 82 | } |
||
| 83 | |||
| 84 | return \Aimeos\Utils::create( $classname, [$context], $interface ); |
||
| 85 | } |
||
| 102 |