Completed
Push — master ( 33a95e...daccbb )
by Aimeos
09:31
created

Factory::createController()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 126
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 126
rs 8.1935
cc 4
eloc 10
nc 6
nop 3

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
 * @copyright Metaways Infosystems GmbH, 2014
5
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
6
 * @copyright Aimeos (aimeos.org), 2015
7
 * @package Controller
8
 * @subpackage Customer
9
 */
10
11
12
namespace Aimeos\Controller\Jobs\Customer\Email\Watch;
13
14
15
/**
16
 * Product notification e-mail controller factory.
17
 *
18
 * @package Controller
19
 * @subpackage Customer
20
 */
21
class Factory
22
	extends \Aimeos\Controller\Jobs\Common\Factory\Base
23
	implements \Aimeos\Controller\Jobs\Common\Factory\Iface
24
{
25
	/**
26
	 * Creates a new controller specified by the given name.
27
	 *
28
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object required by controllers
29
	 * @param \Aimeos\Bootstrap $aimeos \Aimeos\Bootstrap object
30
	 * @param string|null $name Name of the controller or "Standard" if null
31
	 * @return \Aimeos\Controller\Jobs\Iface New controller object
32
	 */
33
	public static function createController( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\Bootstrap $aimeos, $name = null )
34
	{
35
		/** controller/jobs/customer/email/watch/name
36
		 * Class name of the used product notification e-mail scheduler controller implementation
37
		 *
38
		 * Each default job 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\Jobs\Customer\Email\Watch\Standard
46
		 *
47
		 * and you want to replace it with your own version named
48
		 *
49
		 *  \Aimeos\Controller\Jobs\Customer\Email\Watch\Mywatch
50
		 *
51
		 * then you have to set the this configuration option:
52
		 *
53
		 *  controller/jobs/customer/email/watch/name = Mywatch
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 "MyWatch"!
63
		 *
64
		 * @param string Last part of the class name
65
		 * @since 2014.03
66
		 * @category Developer
67
		 */
68
		if( $name === null ) {
69
			$name = $context->getConfig()->get( 'controller/jobs/customer/email/watch/name', 'Standard' );
70
		}
71
72
		if( ctype_alnum( $name ) === false )
73
		{
74
			$classname = is_string( $name ) ? '\\Aimeos\\Controller\\Jobs\\Customer\\Email\\Watch\\' . $name : '<not a string>';
75
			throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) );
76
		}
77
78
		$iface = '\\Aimeos\\Controller\\Jobs\\Iface';
79
		$classname = '\\Aimeos\\Controller\\Jobs\\Customer\\Email\\Watch\\' . $name;
80
81
		$controller = self::createControllerBase( $context, $aimeos, $classname, $iface );
82
83
		/** controller/jobs/customer/email/watch/decorators/excludes
84
		 * Excludes decorators added by the "common" option from the customer email watch controllers
85
		 *
86
		 * Decorators extend the functionality of a class by adding new aspects
87
		 * (e.g. log what is currently done), executing the methods of the underlying
88
		 * class only in certain conditions (e.g. only for logged in users) or
89
		 * modify what is returned to the caller.
90
		 *
91
		 * This option allows you to remove a decorator added via
92
		 * "controller/jobs/common/decorators/default" before they are wrapped
93
		 * around the job controller.
94
		 *
95
		 *  controller/jobs/customer/email/watch/decorators/excludes = array( 'decorator1' )
96
		 *
97
		 * This would remove the decorator named "decorator1" from the list of
98
		 * common decorators ("\Aimeos\Controller\Jobs\Common\Decorator\*") added via
99
		 * "controller/jobs/common/decorators/default" to this job controller.
100
		 *
101
		 * @param array List of decorator names
102
		 * @since 2015.09
103
		 * @category Developer
104
		 * @see controller/jobs/common/decorators/default
105
		 * @see controller/jobs/customer/email/watch/decorators/global
106
		 * @see controller/jobs/customer/email/watch/decorators/local
107
		 */
108
109
		/** controller/jobs/customer/email/watch/decorators/global
110
		 * Adds a list of globally available decorators only to the customer email watch controllers
111
		 *
112
		 * Decorators extend the functionality of a class by adding new aspects
113
		 * (e.g. log what is currently done), executing the methods of the underlying
114
		 * class only in certain conditions (e.g. only for logged in users) or
115
		 * modify what is returned to the caller.
116
		 *
117
		 * This option allows you to wrap global decorators
118
		 * ("\Aimeos\Controller\Jobs\Common\Decorator\*") around the job controller.
119
		 *
120
		 *  controller/jobs/customer/email/watch/decorators/global = array( 'decorator1' )
121
		 *
122
		 * This would add the decorator named "decorator1" defined by
123
		 * "\Aimeos\Controller\Jobs\Common\Decorator\Decorator1" only to this job controller.
124
		 *
125
		 * @param array List of decorator names
126
		 * @since 2015.09
127
		 * @category Developer
128
		 * @see controller/jobs/common/decorators/default
129
		 * @see controller/jobs/customer/email/watch/decorators/excludes
130
		 * @see controller/jobs/customer/email/watch/decorators/local
131
		 */
132
133
		/** controller/jobs/customer/email/watch/decorators/local
134
		 * Adds a list of local decorators only to the customer email watch controllers
135
		 *
136
		 * Decorators extend the functionality of a class by adding new aspects
137
		 * (e.g. log what is currently done), executing the methods of the underlying
138
		 * class only in certain conditions (e.g. only for logged in users) or
139
		 * modify what is returned to the caller.
140
		 *
141
		 * This option allows you to wrap local decorators
142
		 * ("\Aimeos\Controller\Jobs\Customer\Email\Watch\Decorator\*") around this job controller.
143
		 *
144
		 *  controller/jobs/customer/email/watch/decorators/local = array( 'decorator2' )
145
		 *
146
		 * This would add the decorator named "decorator2" defined by
147
		 * "\Aimeos\Controller\Jobs\Customer\Email\Watch\Decorator\Decorator2" only to this job
148
		 * controller.
149
		 *
150
		 * @param array List of decorator names
151
		 * @since 2015.09
152
		 * @category Developer
153
		 * @see controller/jobs/common/decorators/default
154
		 * @see controller/jobs/customer/email/watch/decorators/excludes
155
		 * @see controller/jobs/customer/email/watch/decorators/global
156
		 */
157
		return self::addControllerDecorators( $context, $aimeos, $controller, 'customer/email/watch' );
158
	}
159
}