Completed
Push — master ( 7b4297...eec074 )
by Aimeos
03:02
created

Factory::createClient()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 52
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 52
rs 8.9408
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
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016
6
 * @package Admin
7
 * @subpackage JQAdm
8
 */
9
10
11
namespace Aimeos\Admin\JQAdm\Dashboard;
12
13
14
/**
15
 * Factory for dashboard JQAdm client
16
 *
17
 * @package Admin
18
 * @subpackage JQAdm
19
 */
20
class Factory
21
	extends \Aimeos\Admin\JQAdm\Common\Factory\Base
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
Coding Style introduced by
Expected 0 spaces between "Base" and comma; 1 found
Loading history...
22
	implements \Aimeos\Admin\JQAdm\Common\Factory\Iface
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
23
{
24
	/**
25
	 * Creates a dashboard client object
26
	 *
27
	 * @param \Aimeos\MShop\Context\Item\Iface $context Shop context instance with necessary objects
28
	 * @param array $templatePaths List of file system paths where the templates are stored
29
	 * @param string|null $name Admin name (default: "Standard")
30
	 * @return \Aimeos\Admin\JQAdm\Iface Filter part implementing \Aimeos\Admin\JQAdm\Iface
31
	 * @throws \Aimeos\Admin\JQAdm\Exception If requested client implementation couldn't be found or initialisation fails
32
	 */
33
	public static function createClient( \Aimeos\MShop\Context\Item\Iface $context, array $templatePaths, $name = null )
34
	{
35
		/** admin/jqadm/dashboard/name
36
		 * Class name of the used account favorite client implementation
37
		 *
38
		 * Each default admin client 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 client factory knows which class it
41
		 * has to instantiate.
42
		 *
43
		 * For example, if the name of the default class is
44
		 *
45
		 *  \Aimeos\Admin\JQAdm\Dashboard\Standard
46
		 *
47
		 * and you want to replace it with your own version named
48
		 *
49
		 *  \Aimeos\Admin\JQAdm\Dashboard\Myfavorite
50
		 *
51
		 * then you have to set the this configuration option:
52
		 *
53
		 *  admin/jqadm/dashboard/name = Myfavorite
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 "MyFavorite"!
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->getConfig()->get( 'admin/jqadm/dashboard/name', 'Standard' );
70
		}
71
72
		if( ctype_alnum( $name ) === false )
73
		{
74
			$classname = is_string( $name ) ? '\\Aimeos\\Admin\\JQAdm\\Dashboard\\' . $name : '<not a string>';
75
			throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) );
76
		}
77
78
		$iface = '\\Aimeos\\Admin\\JQAdm\\Iface';
79
		$classname = '\\Aimeos\\Admin\\JQAdm\\Dashboard\\' . $name;
80
81
		$client = self::createClientBase( $context, $classname, $iface, $templatePaths );
82
83
		return self::addClientDecorators( $context, $client, $templatePaths, 'dashboard' );
84
	}
85
86
}
87