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