Passed
Branch master (901174)
by Aimeos
03:14
created

Factory::create()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 124
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 124
rs 9.9666
c 0
b 0
f 0
cc 4
nc 6
nop 2

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018
6
 * @package Controller
7
 * @subpackage Frontend
8
 */
9
10
11
namespace Aimeos\Controller\Frontend\Subscription;
12
13
14
/**
15
 * Subscription frontend controller factory.
16
 *
17
 * @package Controller
18
 * @subpackage Frontend
19
 */
20
class Factory
21
	extends \Aimeos\Controller\Frontend\Common\Factory\Base
22
	implements \Aimeos\Controller\Frontend\Common\Factory\Iface
23
{
24
	/**
25
	 * Creates a new subscription controller object.
26
	 *
27
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context instance with necessary objects
28
	 * @param string|null $name Name of the controller implementaton (default: "Standard")
29
	 * @return \Aimeos\Controller\Frontend\Subscription\Iface Controller object
30
	 */
31
	public static function create( \Aimeos\MShop\Context\Item\Iface $context, $name = null )
32
	{
33
		/** controller/frontend/subscription/name
34
		 * Class name of the used subscription frontend controller implementation
35
		 *
36
		 * Each default frontend controller can be replace by an alternative imlementation.
37
		 * To use this implementation, you have to set the last part of the class
38
		 * name as configuration value so the controller factory knows which class it
39
		 * has to instantiate.
40
		 *
41
		 * For example, if the name of the default class is
42
		 *
43
		 *  \Aimeos\Controller\Frontend\Subscription\Standard
44
		 *
45
		 * and you want to replace it with your own version named
46
		 *
47
		 *  \Aimeos\Controller\Frontend\Subscription\Mysubscription
48
		 *
49
		 * then you have to set the this configuration option:
50
		 *
51
		 *  controller/frontend/subscription/name = Mysubscription
52
		 *
53
		 * The value is the last part of your own class name and it's case sensitive,
54
		 * so take care that the configuration value is exactly named like the last
55
		 * part of the class name.
56
		 *
57
		 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
58
		 * characters are possible! You should always start the last part of the class
59
		 * name with an upper case character and continue only with lower case characters
60
		 * or numbers. Avoid chamel case names like "MySubscription"!
61
		 *
62
		 * @param string Last part of the class name
63
		 * @since 2018.04
64
		 * @category Developer
65
		 */
66
		if( $name === null ) {
67
			$name = $context->getConfig()->get( 'controller/frontend/subscription/name', 'Standard' );
68
		}
69
70
		if( ctype_alnum( $name ) === false ) {
71
			$classname = is_string( $name ) ? '\\Aimeos\\Controller\\Frontend\\Subscription\\' . $name : '<not a string>';
72
			throw new \Aimeos\Controller\Frontend\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) );
73
		}
74
75
		$iface = '\\Aimeos\\Controller\\Frontend\\Subscription\\Iface';
76
		$classname = '\\Aimeos\\Controller\\Frontend\\Subscription\\' . $name;
77
78
		$manager = self::createController( $context, $classname, $iface );
79
80
		/** controller/frontend/subscription/decorators/excludes
81
		 * Excludes decorators added by the "common" option from the subscription frontend controllers
82
		 *
83
		 * Decorators extend the functionality of a class by adding new aspects
84
		 * (e.g. log what is currently done), executing the methods of the underlying
85
		 * class only in certain conditions (e.g. only for logged in users) or
86
		 * modify what is returned to the caller.
87
		 *
88
		 * This option allows you to remove a decorator added via
89
		 * "controller/frontend/common/decorators/default" before they are wrapped
90
		 * around the frontend controller.
91
		 *
92
		 *  controller/frontend/subscription/decorators/excludes = array( 'decorator1' )
93
		 *
94
		 * This would remove the decorator named "decorator1" from the list of
95
		 * common decorators ("\Aimeos\Controller\Frontend\Common\Decorator\*") added via
96
		 * "controller/frontend/common/decorators/default" for the subscription frontend controller.
97
		 *
98
		 * @param array List of decorator names
99
		 * @since 2018.04
100
		 * @category Developer
101
		 * @see controller/frontend/common/decorators/default
102
		 * @see controller/frontend/subscription/decorators/global
103
		 * @see controller/frontend/subscription/decorators/local
104
		 */
105
106
		/** controller/frontend/subscription/decorators/global
107
		 * Adds a list of globally available decorators only to the subscription frontend controllers
108
		 *
109
		 * Decorators extend the functionality of a class by adding new aspects
110
		 * (e.g. log what is currently done), executing the methods of the underlying
111
		 * class only in certain conditions (e.g. only for logged in users) or
112
		 * modify what is returned to the caller.
113
		 *
114
		 * This option allows you to wrap global decorators
115
		 * ("\Aimeos\Controller\Frontend\Common\Decorator\*") around the frontend controller.
116
		 *
117
		 *  controller/frontend/subscription/decorators/global = array( 'decorator1' )
118
		 *
119
		 * This would add the decorator named "decorator1" defined by
120
		 * "\Aimeos\Controller\Frontend\Common\Decorator\Decorator1" only to the frontend controller.
121
		 *
122
		 * @param array List of decorator names
123
		 * @since 2018.04
124
		 * @category Developer
125
		 * @see controller/frontend/common/decorators/default
126
		 * @see controller/frontend/subscription/decorators/excludes
127
		 * @see controller/frontend/subscription/decorators/local
128
		 */
129
130
		/** controller/frontend/subscription/decorators/local
131
		 * Adds a list of local decorators only to the subscription frontend controllers
132
		 *
133
		 * Decorators extend the functionality of a class by adding new aspects
134
		 * (e.g. log what is currently done), executing the methods of the underlying
135
		 * class only in certain conditions (e.g. only for logged in users) or
136
		 * modify what is returned to the caller.
137
		 *
138
		 * This option allows you to wrap local decorators
139
		 * ("\Aimeos\Controller\Frontend\Subscription\Decorator\*") around the frontend controller.
140
		 *
141
		 *  controller/frontend/subscription/decorators/local = array( 'decorator2' )
142
		 *
143
		 * This would add the decorator named "decorator2" defined by
144
		 * "\Aimeos\Controller\Frontend\Catalog\Decorator\Decorator2" only to the frontend
145
		 * controller.
146
		 *
147
		 * @param array List of decorator names
148
		 * @since 2018.04
149
		 * @category Developer
150
		 * @see controller/frontend/common/decorators/default
151
		 * @see controller/frontend/subscription/decorators/excludes
152
		 * @see controller/frontend/subscription/decorators/global
153
		 */
154
		return self::addControllerDecorators( $context, $manager, 'subscription' );
155
	}
156
}
157