Passed
Push — master ( 8c606e...aebd94 )
by Aimeos
04:08
created

Factory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 61
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 49 3
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2021
6
 * @package Admin
7
 * @subpackage JQAdm
8
 */
9
10
11
namespace Aimeos\Admin\JQAdm\Rule;
12
13
14
/**
15
 * Factory for rule JQAdm client
16
 *
17
 * @package Admin
18
 * @subpackage JQAdm
19
 */
20
class Factory
21
	extends \Aimeos\Admin\JQAdm\Common\Factory\Base
22
	implements \Aimeos\Admin\JQAdm\Common\Factory\Iface
23
{
24
	/**
25
	 * Creates a rule client object
26
	 *
27
	 * @param \Aimeos\MShop\Context\Item\Iface $context Shop context instance with necessary objects
28
	 * @param string|null $name Admin name (default: "Standard")
29
	 * @return \Aimeos\Admin\JQAdm\Iface Filter part implementing \Aimeos\Admin\JQAdm\Iface
30
	 * @throws \Aimeos\Admin\JQAdm\Exception If requested client implementation couldn't be found or initialisation fails
31
	 */
32
	public static function create( \Aimeos\MShop\Context\Item\Iface $context, string $name = null ) : \Aimeos\Admin\JQAdm\Iface
33
	{
34
		/** admin/jqadm/rule/name
35
		 * Class name of the used account favorite client implementation
36
		 *
37
		 * Each default admin client 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 client factory knows which class it
40
		 * has to instantiate.
41
		 *
42
		 * For example, if the name of the default class is
43
		 *
44
		 *  \Aimeos\Admin\JQAdm\Rule\Standard
45
		 *
46
		 * and you want to replace it with your own version named
47
		 *
48
		 *  \Aimeos\Admin\JQAdm\Rule\Myfavorite
49
		 *
50
		 * then you have to set the this configuration option:
51
		 *
52
		 *  admin/jqadm/rule/name = Myfavorite
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 "MyFavorite"!
62
		 *
63
		 * @param string Last part of the class name
64
		 * @since 2021.04
65
		 * @category Developer
66
		 */
67
		if( $name === null ) {
68
			$name = $context->getConfig()->get( 'admin/jqadm/rule/name', 'Standard' );
69
		}
70
71
		$iface = '\\Aimeos\\Admin\\JQAdm\\Iface';
72
		$classname = '\\Aimeos\\Admin\\JQAdm\\Rule\\' . $name;
73
74
		if( ctype_alnum( $name ) === false ) {
75
			throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) );
76
		}
77
78
		$client = self::createAdmin( $context, $classname, $iface );
79
80
		return self::addClientDecorators( $context, $client, 'rule' );
81
	}
82
83
}
84