Passed
Push — master ( 8aaa8e...6a4321 )
by Aimeos
02:10
created

Factory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 149
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 15
dl 0
loc 149
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 136 6
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2019
6
 * @package Client
7
 * @subpackage JsonApi
8
 */
9
10
11
namespace Aimeos\Client\JsonApi\Customer\Property;
12
13
14
/**
15
 * Factory for customer/property JSON API client
16
 *
17
 * @package Client
18
 * @subpackage JsonApi
19
 */
20
class Factory
21
	extends \Aimeos\Client\JsonApi\Common\Factory\Base
22
	implements \Aimeos\Client\JsonApi\Common\Factory\Iface
23
{
24
	/**
25
	 * Creates a customer/property client object.
26
	 *
27
	 * @param \Aimeos\MShop\Context\Item\Iface $context Shop context instance with necessary objects
28
	 * @param string $path Name of the client separated by slashes, e.g "property"
29
	 * @param string|null $name Client name (default: "Standard")
30
	 * @return \Aimeos\Client\JsonApi\Iface JSON API client
31
	 * @throws \Aimeos\Client\JsonApi\Exception If requested client implementation couldn't be found or initialisation fails
32
	 */
33
	public static function create( \Aimeos\MShop\Context\Item\Iface $context, $path, $name = null )
34
	{
35
		if( is_string( $path ) === false || preg_match( '#^[a-zA-Z0-9/]+$#', $path ) !== 1 ) {
36
			throw new \Aimeos\Client\JsonApi\Exception( sprintf( 'Invalid client "%1$s"', $path ), 400 );
37
		}
38
39
		/** client/jsonapi/customer/property/name
40
		 * Class name of the used customer/property client implementation
41
		 *
42
		 * Each default JSON API client can be replace by an alternative imlementation.
43
		 * To use this implementation, you have to set the last part of the class
44
		 * name as configuration value so the client factory knows which class it
45
		 * has to instantiate.
46
		 *
47
		 * For example, if the name of the default class is
48
		 *
49
		 *  \Aimeos\Client\JsonApi\Customer\Property\Standard
50
		 *
51
		 * and you want to replace it with your own version named
52
		 *
53
		 *  \Aimeos\Client\JsonApi\Customer\Property\Mycustomer/property
54
		 *
55
		 * then you have to set the this configuration option:
56
		 *
57
		 *  client/jsonapi/customer/property/name = Mycustomer/property
58
		 *
59
		 * The value is the last part of your own class name and it's case sensitive,
60
		 * so take care that the configuration value is exactly named like the last
61
		 * part of the class name.
62
		 *
63
		 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
64
		 * characters are possible! You should always start the last part of the class
65
		 * name with an upper case character and continue only with lower case characters
66
		 * or numbers. Avoid chamel case names like "MyProperty"!
67
		 *
68
		 * @param string Last part of the class name
69
		 * @since 2017.03
70
		 * @category Developer
71
		 */
72
		if( $name === null ) {
73
			$name = $context->getConfig()->get( 'client/jsonapi/customer/property/name', 'Standard' );
74
		}
75
76
		if( ctype_alnum( $name ) === false )
77
		{
78
			$classname = is_string( $name ) ? '\\Aimeos\\Client\\JsonApi\\Customer\\Property\\' . $name : '<not a string>';
79
			throw new \Aimeos\Client\JsonApi\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) );
80
		}
81
82
		$iface = '\\Aimeos\\Client\\JsonApi\\Iface';
83
		$classname = '\\Aimeos\\Client\\JsonApi\\Customer\\Property\\' . $name;
84
85
		$client = self::createClient( $classname, $iface, $context, $path );
86
87
88
		/** client/jsonapi/customer/property/decorators/excludes
89
		 * Excludes decorators added by the "common" option from the JSON API clients
90
		 *
91
		 * Decorators extend the functionality of a class by adding new aspects
92
		 * (e.g. log what is currently done), executing the methods of the underlying
93
		 * class only in certain conditions (e.g. only for logged in users) or
94
		 * modify what is returned to the caller.
95
		 *
96
		 * This option allows you to remove a decorator added via
97
		 * "client/jsonapi/common/decorators/default" before they are wrapped
98
		 * around the JsonApi client.
99
		 *
100
		 *  client/jsonapi/decorators/excludes = array( 'decorator1' )
101
		 *
102
		 * This would remove the decorator named "decorator1" from the list of
103
		 * common decorators ("\Aimeos\Client\JsonApi\Common\Decorator\*") added via
104
		 * "client/jsonapi/common/decorators/default" for the JSON API client.
105
		 *
106
		 * @param array List of decorator names
107
		 * @since 2017.07
108
		 * @category Developer
109
		 * @see client/jsonapi/common/decorators/default
110
		 * @see client/jsonapi/customer/property/decorators/global
111
		 * @see client/jsonapi/customer/property/decorators/local
112
		 */
113
114
		/** client/jsonapi/customer/property/decorators/global
115
		 * Adds a list of globally available decorators only to the JsonApi client
116
		 *
117
		 * Decorators extend the functionality of a class by adding new aspects
118
		 * (e.g. log what is currently done), executing the methods of the underlying
119
		 * class only in certain conditions (e.g. only for logged in users) or
120
		 * modify what is returned to the caller.
121
		 *
122
		 * This option allows you to wrap global decorators
123
		 * ("\Aimeos\Client\JsonApi\Common\Decorator\*") around the JsonApi
124
		 * client.
125
		 *
126
		 *  client/jsonapi/customer/property/decorators/global = array( 'decorator1' )
127
		 *
128
		 * This would add the decorator named "decorator1" defined by
129
		 * "\Aimeos\Client\JsonApi\Common\Decorator\Decorator1" only to the
130
		 * "customer" JsonApi client.
131
		 *
132
		 * @param array List of decorator names
133
		 * @since 2017.07
134
		 * @category Developer
135
		 * @see client/jsonapi/common/decorators/default
136
		 * @see client/jsonapi/customer/property/decorators/excludes
137
		 * @see client/jsonapi/customer/property/decorators/local
138
		 */
139
140
		/** client/jsonapi/customer/property/decorators/local
141
		 * Adds a list of local decorators only to the JsonApi client
142
		 *
143
		 * Decorators extend the functionality of a class by adding new aspects
144
		 * (e.g. log what is currently done), executing the methods of the underlying
145
		 * class only in certain conditions (e.g. only for logged in users) or
146
		 * modify what is returned to the caller.
147
		 *
148
		 * This option allows you to wrap local decorators
149
		 * ("\Aimeos\Client\JsonApi\Customer\Property\Decorator\*") around the JsonApi
150
		 * client.
151
		 *
152
		 *  client/jsonapi/customer/property/decorators/local = array( 'decorator2' )
153
		 *
154
		 * This would add the decorator named "decorator2" defined by
155
		 * "\Aimeos\Client\JsonApi\Customer\Property\Decorator\Decorator2" only to the
156
		 * "customer property" JsonApi client.
157
		 *
158
		 * @param array List of decorator names
159
		 * @since 2017.07
160
		 * @category Developer
161
		 * @see client/jsonapi/common/decorators/default
162
		 * @see client/jsonapi/customer/property/decorators/excludes
163
		 * @see client/jsonapi/customer/property/decorators/global
164
		 */
165
166
		$client = self::addClientDecorators( $client, $context, $path );
167
168
		return $client->setView( $context->getView() );
0 ignored issues
show
Bug introduced by
The method setView() does not exist on Aimeos\Client\JsonApi\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\Client\JsonApi\Common\Decorator\Iface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

168
		return $client->/** @scrutinizer ignore-call */ setView( $context->getView() );
Loading history...
169
	}
170
}
171