Passed
Push — master ( e3443a...9a4066 )
by Aimeos
01:47
created

Standard::process()   B

Complexity

Conditions 7
Paths 18

Size

Total Lines 43
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 22
nc 18
nop 2
dl 0
loc 43
rs 8.6346
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2019
6
 * @package Controller
7
 * @subpackage Common
8
 */
9
10
11
namespace Aimeos\Controller\Common\Common\Import\Xml\Processor\Lists\Media;
12
13
14
/**
15
 * Media list processor for XML imports
16
 *
17
 * @package Controller
18
 * @subpackage Common
19
 */
20
class Standard
21
	extends \Aimeos\Controller\Common\Common\Import\Xml\Processor\Base
22
	implements \Aimeos\Controller\Common\Common\Import\Xml\Processor\Iface
23
{
24
	use \Aimeos\Controller\Common\Common\Import\Xml\Traits;
25
26
27
	/** controller/common/common/import/xml/processor/lists/text/name
28
	 * Name of the lists processor implementation
29
	 *
30
	 * Use "Myname" if your class is named "\Aimeos\Controller\Common\Common\Import\Xml\Processor\Lists\Media\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
	 * @category Developer
36
	 */
37
38
39
	/**
40
	 * Updates the given item using the data from the DOM node
41
	 *
42
	 * @param \Aimeos\MShop\Common\Item\Iface $item Item which should be updated
43
	 * @param \DOMNode $node XML document node containing a list of nodes to process
44
	 * @return \Aimeos\MShop\Common\Item\Iface Updated item
45
	 */
46
	public function process( \Aimeos\MShop\Common\Item\Iface $item, \DOMNode $node )
47
	{
48
		\Aimeos\MW\Common\Base::checkClass( \Aimeos\MShop\Common\Item\ListRef\Iface::class, $item );
49
50
		$listItems = array_reverse( $item->getListItems( 'media', null, null, false ), true );
51
		$resource = $item->getResourceType();
52
		$context = $this->getContext();
53
54
		$listManager = \Aimeos\MShop::create( $context, $resource . '/lists' );
55
		$manager = \Aimeos\MShop::create( $context, 'media' );
56
57
		foreach( $node->childNodes as $refNode )
58
		{
59
			if( $refNode->nodeName !== 'mediaitem' ) {
60
				continue;
61
			}
62
63
			if( ( $listItem = array_pop( $listItems ) ) === null ) {
64
				$listItem = $listManager->createItem();
65
			}
66
67
			if( ( $refItem = $listItem->getRefItem() ) === null ) {
0 ignored issues
show
Bug introduced by
The method getRefItem() does not exist on Aimeos\MShop\Attribute\Item\Iface. Did you maybe mean getRefItems()? ( Ignorable by Annotation )

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

67
			if( ( $refItem = $listItem->/** @scrutinizer ignore-call */ getRefItem() ) === null ) {

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...
68
				$refItem = $manager->createItem();
69
			}
70
71
			$list = [];
72
73
			foreach( $refNode->childNodes as $tagNode ) {
74
				$list[$tagNode->nodeName] = $tagNode->nodeValue;
75
			}
76
77
			$refItem = $refItem->fromArray( $list );
78
79
			foreach( $refNode->attributes as $attrName => $attrNode ) {
80
				$list[$resource . '.' . $attrName] = $attrNode->nodeValue;
81
			}
82
83
			$listItem = $listItem->fromArray( $list );
84
85
			$item->addListItem( 'media', $listItem, $refItem );
86
		}
87
88
		return $item->deleteListItems( $listItems );
89
	}
90
}
91