Completed
Push — master ( a446d4...af70c5 )
by Aimeos
01:43
created
admin/jsonadm/src/Admin/JsonAdm/Base.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	 * @param array $templatePaths List of file system paths where the templates are stored
34 34
 	 * @param string $path Name of the client separated by slashes, e.g "product/property"
35 35
 	 */
36
-	public function __construct( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MW\View\Iface $view, array $templatePaths, $path )
36
+	public function __construct(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MW\View\Iface $view, array $templatePaths, $path)
37 37
 	{
38 38
 		$this->view = $view;
39 39
 		$this->context = $context;
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
 	 * @param array $param List of method parameter
50 50
 	 * @throws \Aimeos\Admin\JsonAdm\Exception If method call failed
51 51
 	 */
52
-	public function __call( $name, array $param )
52
+	public function __call($name, array $param)
53 53
 	{
54
-		throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Unable to call method "%1$s"', $name ) );
54
+		throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('Unable to call method "%1$s"', $name));
55 55
 	}
56 56
 
57 57
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 * @param array $include List of resource types that should be fetched
63 63
 	 * @return array List of items implementing \Aimeos\MShop\Common\Item\Iface
64 64
 	 */
65
-	protected function getChildItems( array $items, array $include )
65
+	protected function getChildItems(array $items, array $include)
66 66
 	{
67 67
 		return [];
68 68
 	}
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
 	 * @param \Aimeos\MW\View\Iface $view View object with "resource" parameter
86 86
 	 * @return array List of domain names
87 87
 	 */
88
-	protected function getDomains( \Aimeos\MW\View\Iface $view )
88
+	protected function getDomains(\Aimeos\MW\View\Iface $view)
89 89
 	{
90
-		if( ( $domains = $view->param( 'resource' ) ) == '' )
90
+		if (($domains = $view->param('resource')) == '')
91 91
 		{
92 92
 			/** admin/jsonadm/domains
93 93
 			 * A list of domain names whose clients are available for the JSON API
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 				'attribute', 'catalog', 'coupon', 'customer', 'locale', 'media', 'order',
111 111
 				'plugin', 'price', 'product', 'service', 'supplier', 'stock', 'tag', 'text'
112 112
 			);
113
-			$domains = $this->getContext()->getConfig()->get( 'admin/jsonadm/domains', $default );
113
+			$domains = $this->getContext()->getConfig()->get('admin/jsonadm/domains', $default);
114 114
 		}
115 115
 
116 116
 		return (array) $domains;
@@ -123,15 +123,15 @@  discard block
 block discarded – undo
123 123
 	 * @param \stdClass $request Decoded request body
124 124
 	 * @return array List of item IDs
125 125
 	 */
126
-	protected function getIds( $request )
126
+	protected function getIds($request)
127 127
 	{
128 128
 		$ids = [];
129 129
 
130
-		if( isset( $request->data ) )
130
+		if (isset($request->data))
131 131
 		{
132
-			foreach( (array) $request->data as $entry )
132
+			foreach ((array) $request->data as $entry)
133 133
 			{
134
-				if( isset( $entry->id ) ) {
134
+				if (isset($entry->id)) {
135 135
 					$ids[] = $entry->id;
136 136
 				}
137 137
 			}
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	 * @param array $include List of resource types that should be fetched
149 149
 	 * @return array List of items implementing \Aimeos\MShop\Common\Item\Lists\Iface
150 150
 	 */
151
-	protected function getListItems( array $items, array $include )
151
+	protected function getListItems(array $items, array $include)
152 152
 	{
153 153
 		return [];
154 154
 	}
@@ -171,23 +171,23 @@  discard block
 block discarded – undo
171 171
 	 * @param array $listItems List of items implementing \Aimeos\MShop\Common\Item\Lists\Iface
172 172
 	 * @return array List of items implementing \Aimeos\MShop\Common\Item\Iface
173 173
 	 */
174
-	protected function getRefItems( array $listItems )
174
+	protected function getRefItems(array $listItems)
175 175
 	{
176 176
 		$list = $map = [];
177 177
 		$context = $this->getContext();
178 178
 
179
-		foreach( $listItems as $listItem ) {
179
+		foreach ($listItems as $listItem) {
180 180
 			$map[$listItem->getDomain()][] = $listItem->getRefId();
181 181
 		}
182 182
 
183
-		foreach( $map as $domain => $ids )
183
+		foreach ($map as $domain => $ids)
184 184
 		{
185
-			$manager = \Aimeos\MShop\Factory::createManager( $context, $domain );
185
+			$manager = \Aimeos\MShop\Factory::createManager($context, $domain);
186 186
 
187 187
 			$search = $manager->createSearch();
188
-			$search->setConditions( $search->compare( '==', $domain . '.id', $ids ) );
188
+			$search->setConditions($search->compare('==', $domain . '.id', $ids));
189 189
 
190
-			$list = array_merge( $list, $manager->searchItems( $search ) );
190
+			$list = array_merge($list, $manager->searchItems($search));
191 191
 		}
192 192
 
193 193
 		return $list;
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 	 * @param \Aimeos\MW\View\Iface $view View object with "resource" parameter
201 201
 	 * @return array List of domain names
202 202
 	 */
203
-	protected function getResources( \Aimeos\MW\View\Iface $view )
203
+	protected function getResources(\Aimeos\MW\View\Iface $view)
204 204
 	{
205 205
 		/** admin/jsonadm/resources
206 206
 		 * A list of additional resources name whose clients are available for the JSON API
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 		 * @category Developer
219 219
 		 * @see admin/jsonadm/domains
220 220
 		 */
221
-		return (array) $view->config( 'admin/jsonadm/resources', ['coupon/config', 'service/config'] );
221
+		return (array) $view->config('admin/jsonadm/resources', ['coupon/config', 'service/config']);
222 222
 	}
223 223
 
224 224
 
@@ -251,11 +251,11 @@  discard block
 block discarded – undo
251 251
 	 * @param array $params List of criteria data with condition, sorting and paging
252 252
 	 * @return \Aimeos\MW\Criteria\Iface Initialized criteria object
253 253
 	 */
254
-	protected function initCriteria( \Aimeos\MW\Criteria\Iface $criteria, array $params )
254
+	protected function initCriteria(\Aimeos\MW\Criteria\Iface $criteria, array $params)
255 255
 	{
256
-		$this->initCriteriaConditions( $criteria, $params );
257
-		$this->initCriteriaSortations( $criteria, $params );
258
-		$this->initCriteriaSlice( $criteria, $params );
256
+		$this->initCriteriaConditions($criteria, $params);
257
+		$this->initCriteriaSortations($criteria, $params);
258
+		$this->initCriteriaSlice($criteria, $params);
259 259
 
260 260
 		return $criteria;
261 261
 	}
@@ -267,17 +267,17 @@  discard block
 block discarded – undo
267 267
 	 * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object
268 268
 	 * @param array $params List of criteria data with condition, sorting and paging
269 269
 	 */
270
-	protected function initCriteriaConditions( \Aimeos\MW\Criteria\Iface $criteria, array $params )
270
+	protected function initCriteriaConditions(\Aimeos\MW\Criteria\Iface $criteria, array $params)
271 271
 	{
272
-		if( !isset( $params['filter'] ) ) {
272
+		if (!isset($params['filter'])) {
273 273
 			return;
274 274
 		}
275 275
 
276 276
 		$existing = $criteria->getConditions();
277
-		$criteria->setConditions( $criteria->toConditions( (array) $params['filter'] ) );
277
+		$criteria->setConditions($criteria->toConditions((array) $params['filter']));
278 278
 
279
-		$expr = array( $criteria->getConditions(), $existing );
280
-		$criteria->setConditions( $criteria->combine( '&&', $expr ) );
279
+		$expr = array($criteria->getConditions(), $existing);
280
+		$criteria->setConditions($criteria->combine('&&', $expr));
281 281
 	}
282 282
 
283 283
 
@@ -287,12 +287,12 @@  discard block
 block discarded – undo
287 287
 	 * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object
288 288
 	 * @param array $params List of criteria data with condition, sorting and paging
289 289
 	 */
290
-	protected function initCriteriaSlice( \Aimeos\MW\Criteria\Iface $criteria, array $params )
290
+	protected function initCriteriaSlice(\Aimeos\MW\Criteria\Iface $criteria, array $params)
291 291
 	{
292
-		$start = ( isset( $params['page']['offset'] ) ? (int) $params['page']['offset'] : 0 );
293
-		$size = ( isset( $params['page']['limit'] ) ? (int) $params['page']['limit'] : 25 );
292
+		$start = (isset($params['page']['offset']) ? (int) $params['page']['offset'] : 0);
293
+		$size = (isset($params['page']['limit']) ? (int) $params['page']['limit'] : 25);
294 294
 
295
-		$criteria->setSlice( $start, $size );
295
+		$criteria->setSlice($start, $size);
296 296
 	}
297 297
 
298 298
 
@@ -302,24 +302,24 @@  discard block
 block discarded – undo
302 302
 	 * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object
303 303
 	 * @param array $params List of criteria data with condition, sorting and paging
304 304
 	 */
305
-	protected function initCriteriaSortations( \Aimeos\MW\Criteria\Iface $criteria, array $params )
305
+	protected function initCriteriaSortations(\Aimeos\MW\Criteria\Iface $criteria, array $params)
306 306
 	{
307
-		if( !isset( $params['sort'] ) ) {
307
+		if (!isset($params['sort'])) {
308 308
 			return;
309 309
 		}
310 310
 
311 311
 		$sortation = [];
312 312
 
313
-		foreach( explode( ',', $params['sort'] ) as $sort )
313
+		foreach (explode(',', $params['sort']) as $sort)
314 314
 		{
315
-			if( $sort[0] === '-' ) {
316
-				$sortation[] = $criteria->sort( '-', substr( $sort, 1 ) );
315
+			if ($sort[0] === '-') {
316
+				$sortation[] = $criteria->sort('-', substr($sort, 1));
317 317
 			} else {
318
-				$sortation[] = $criteria->sort( '+', $sort );
318
+				$sortation[] = $criteria->sort('+', $sort);
319 319
 			}
320 320
 		}
321 321
 
322
-		$criteria->setSortations( $sortation );
322
+		$criteria->setSortations($sortation);
323 323
 	}
324 324
 
325 325
 
@@ -330,14 +330,14 @@  discard block
 block discarded – undo
330 330
 	 * @param \stdClass $request Object with request body data
331 331
 	 * @return array List of items
332 332
 	 */
333
-	protected function saveData( \Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $request )
333
+	protected function saveData(\Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $request)
334 334
 	{
335 335
 		$data = [];
336 336
 
337
-		if( isset( $request->data ) )
337
+		if (isset($request->data))
338 338
 		{
339
-			foreach( (array) $request->data as $entry ) {
340
-				$data[] = $this->saveEntry( $manager, $entry );
339
+			foreach ((array) $request->data as $entry) {
340
+				$data[] = $this->saveEntry($manager, $entry);
341 341
 			}
342 342
 		}
343 343
 
@@ -352,22 +352,22 @@  discard block
 block discarded – undo
352 352
 	 * @param \stdClass $entry Object including "id" and "attributes" elements
353 353
 	 * @return \Aimeos\MShop\Common\Item\Iface New or updated item
354 354
 	 */
355
-	protected function saveEntry( \Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $entry )
355
+	protected function saveEntry(\Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $entry)
356 356
 	{
357
-		if( isset( $entry->id ) ) {
358
-			$item = $manager->getItem( $entry->id );
357
+		if (isset($entry->id)) {
358
+			$item = $manager->getItem($entry->id);
359 359
 		} else {
360 360
 			$item = $manager->createItem();
361 361
 		}
362 362
 
363
-		$item = $this->addItemData( $manager, $item, $entry, $item->getResourceType() );
364
-		$item = $manager->saveItem( $item );
363
+		$item = $this->addItemData($manager, $item, $entry, $item->getResourceType());
364
+		$item = $manager->saveItem($item);
365 365
 
366
-		if( isset( $entry->relationships ) ) {
367
-			$this->saveRelationships( $manager, $item, $entry->relationships );
366
+		if (isset($entry->relationships)) {
367
+			$this->saveRelationships($manager, $item, $entry->relationships);
368 368
 		}
369 369
 
370
-		return $manager->getItem( $item->getId() );
370
+		return $manager->getItem($item->getId());
371 371
 	}
372 372
 
373 373
 
@@ -378,28 +378,28 @@  discard block
 block discarded – undo
378 378
 	 * @param \Aimeos\MShop\Common\Item\Iface $item Domain item with an unique ID set
379 379
 	 * @param \stdClass $relationships Object including the <domain>/data/attributes structure
380 380
 	 */
381
-	protected function saveRelationships( \Aimeos\MShop\Common\Manager\Iface $manager,
382
-		\Aimeos\MShop\Common\Item\Iface $item, \stdClass $relationships )
381
+	protected function saveRelationships(\Aimeos\MShop\Common\Manager\Iface $manager,
382
+		\Aimeos\MShop\Common\Item\Iface $item, \stdClass $relationships)
383 383
 	{
384 384
 		$id = $item->getId();
385
-		$listManager = $manager->getSubManager( 'lists' );
385
+		$listManager = $manager->getSubManager('lists');
386 386
 
387
-		foreach( (array) $relationships as $domain => $list )
387
+		foreach ((array) $relationships as $domain => $list)
388 388
 		{
389
-			if( isset( $list->data ) )
389
+			if (isset($list->data))
390 390
 			{
391
-				foreach( (array) $list->data as $data )
391
+				foreach ((array) $list->data as $data)
392 392
 				{
393
-					$listItem = $this->addItemData( $listManager, $listManager->createItem(), $data, $domain );
393
+					$listItem = $this->addItemData($listManager, $listManager->createItem(), $data, $domain);
394 394
 
395
-					if( isset( $data->id ) ) {
396
-						$listItem->setRefId( $data->id );
395
+					if (isset($data->id)) {
396
+						$listItem->setRefId($data->id);
397 397
 					}
398 398
 
399
-					$listItem->setParentId( $id );
400
-					$listItem->setDomain( $domain );
399
+					$listItem->setParentId($id);
400
+					$listItem->setDomain($domain);
401 401
 
402
-					$listManager->saveItem( $listItem, false );
402
+					$listManager->saveItem($listItem, false);
403 403
 				}
404 404
 			}
405 405
 		}
@@ -416,20 +416,20 @@  discard block
 block discarded – undo
416 416
 	 * @return \Aimeos\MShop\Common\Item\Iface Item including the data
417 417
 	 */
418 418
 	protected function addItemData(\Aimeos\MShop\Common\Manager\Iface $manager,
419
-		\Aimeos\MShop\Common\Item\Iface $item, \stdClass $data, $domain )
419
+		\Aimeos\MShop\Common\Item\Iface $item, \stdClass $data, $domain)
420 420
 	{
421
-		if( isset( $data->attributes ) )
421
+		if (isset($data->attributes))
422 422
 		{
423 423
 			$attr = (array) $data->attributes;
424
-			$key = str_replace( '/', '.', $item->getResourceType() );
424
+			$key = str_replace('/', '.', $item->getResourceType());
425 425
 
426
-			if( isset( $attr[$key.'.type'] ) )
426
+			if (isset($attr[$key . '.type']))
427 427
 			{
428
-				$typeItem = $manager->getSubManager( 'type' )->findItem( $attr[$key.'.type'], [], $domain );
429
-				$attr[$key.'.typeid'] = $typeItem->getId();
428
+				$typeItem = $manager->getSubManager('type')->findItem($attr[$key . '.type'], [], $domain);
429
+				$attr[$key . '.typeid'] = $typeItem->getId();
430 430
 			}
431 431
 
432
-			$item->fromArray( $attr );
432
+			$item->fromArray($attr);
433 433
 		}
434 434
 
435 435
 		return $item;
Please login to merge, or discard this patch.