Standard::process()   B
last analyzed

Complexity

Conditions 10
Paths 98

Size

Total Lines 54
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 30
nc 98
nop 2
dl 0
loc 54
rs 7.6666
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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), 2019-2025
6
 * @package Controller
7
 * @subpackage Common
8
 */
9
10
11
namespace Aimeos\Controller\Jobs\Common\Import\Xml\Processor\Lists\Price;
12
13
14
/**
15
 * Price list processor for XML imports
16
 *
17
 * @package Controller
18
 * @subpackage Common
19
 */
20
class Standard
21
	extends \Aimeos\Controller\Jobs\Common\Import\Xml\Processor\Base
22
	implements \Aimeos\Controller\Jobs\Common\Import\Xml\Processor\Iface
23
{
24
	use \Aimeos\Controller\Jobs\Common\Import\Xml\Traits;
25
26
27
	/** controller/jobs/common/import/xml/processor/lists/price/name
28
	 * Name of the lists processor implementation
29
	 *
30
	 * Use "Myname" if your class is named "\Aimeos\Controller\Jobs\Common\Import\Xml\Processor\Lists\Price\Myname".
31
	 * The name is case-sensitive and you should avoid camel case names like "MyName".
32
	 *
33
	 * @param string Last part of the processor class name
34
	 * @since 2019.04
35
	 */
36
37
38
	/**
39
	 * Updates the given item using the data from the DOM node
40
	 *
41
	 * @param \Aimeos\MShop\Common\Item\Iface $item Item which should be updated
42
	 * @param \DOMNode $node XML document node containing a list of nodes to process
43
	 * @return \Aimeos\MShop\Common\Item\Iface Updated item
44
	 */
45
	public function process( \Aimeos\MShop\Common\Item\Iface $item, \DOMNode $node ) : \Aimeos\MShop\Common\Item\Iface
46
	{
47
		\Aimeos\Utils::implements( $item, \Aimeos\MShop\Common\Item\ListsRef\Iface::class );
48
49
		$listItems = $item->getListItems( 'price', null, null, false )->reverse();
50
		$resource = $item->getResourceType();
51
		$context = $this->context();
52
53
		$manager = \Aimeos\MShop::create( $context, $resource );
54
		$priceManager = \Aimeos\MShop::create( $context, 'price' );
55
56
		foreach( $node->childNodes as $refNode )
57
		{
58
			if( $refNode->nodeName !== 'priceitem' ) {
59
				continue;
60
			}
61
62
			if( ( $listItem = $listItems->pop() ) === null ) {
63
				$listItem = $manager->createListItem();
0 ignored issues
show
Bug introduced by
The method createListItem() does not exist on Aimeos\MShop\Common\Manager\Iface. Did you maybe mean create()? ( Ignorable by Annotation )

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

63
				/** @scrutinizer ignore-call */ 
64
    $listItem = $manager->createListItem();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
			}
65
66
			if( ( $refItem = $listItem->getRefItem() ) === null ) {
67
				$refItem = $priceManager->create();
68
			}
69
70
			$list = [];
71
72
			foreach( $refNode->childNodes as $tag )
73
			{
74
				if( in_array( $tag->nodeName, ['lists'] ) ) {
75
					$refItem = $this->getProcessor( $tag->nodeName )->process( $refItem, $tag );
76
				} else {
77
					$list[$tag->nodeName] = \Aimeos\Base\Str::decode( $tag->nodeValue );
78
				}
79
			}
80
81
			$refItem = $refItem->fromArray( $list );
82
83
			foreach( $refNode->attributes as $attrName => $attrNode ) {
84
				$list[$resource . '.' . $attrName] = \Aimeos\Base\Str::decode( $attrNode->nodeValue );
85
			}
86
87
			$name = $resource . '.lists.config';
88
			$list[$name] = ( isset( $list[$name] ) ? (array) json_decode( $list[$name] ) : [] );
89
			$name = $resource . '.lists.type';
90
			$list[$name] = ( isset( $list[$name] ) ? $list[$name] : 'default' );
91
92
			$this->addType( $resource . '/lists/type', 'price', $list[$resource . '.lists.type'] );
93
94
			$listItem = $listItem->fromArray( $list );
95
			$item->addListItem( 'price', $listItem, $refItem );
96
		}
97
98
		return $item->deleteListItems( $listItems->toArray() );
99
	}
100
}
101