Completed
Pull Request — master (#12)
by
unknown
02:44
created

Factory::createController()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 126

Duplication

Lines 0
Ratio 0 %

Importance

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