Passed
Push — master ( 96cc40...534161 )
by Aimeos
01:56
created

Standard   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 34 6
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\Property;
12
13
14
/**
15
 * Property 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
	/** controller/common/common/import/xml/processor/property/name
25
	 * Name of the property processor implementation
26
	 *
27
	 * Use "Myname" if your class is named "\Aimeos\Controller\Common\Common\Import\Xml\Processor\Property\Myname".
28
	 * The name is case-sensitive and you should avoid camel case names like "MyName".
29
	 *
30
	 * @param string Last part of the processor class name
31
	 * @since 2019.04
32
	 * @category Developer
33
	 */
34
35
36
	/**
37
	 * Updates the given item using the data from the DOM node
38
	 *
39
	 * @param \Aimeos\MShop\Common\Item\Iface $item Item which should be updated
40
	 * @param \DOMNode $node XML document node containing a list of nodes to process
41
	 * @return \Aimeos\MShop\Common\Item\Iface Updated item
42
	 */
43
	public function process( \Aimeos\MShop\Common\Item\Iface $item, \DOMNode $node )
44
	{
45
		\Aimeos\MW\Common\Base::checkClass( \Aimeos\MShop\Common\Item\PropertyRef\Iface::class, $item );
46
47
		$manager = \Aimeos\MShop::create( $this->getContext(), $item->getResourceType() . '/property' );
48
		$propItems = $item->getPropertyItems( null, false );
49
		$map = [];
50
51
		foreach( $propItems as $propItem ) {
52
			$map[$propItem->getType()][$propItem->getLanguageId()][$propItem->getValue()] = $propItem->getId();
53
		}
54
55
		foreach( $node->childNodes as $propNode )
56
		{
57
			if( $propNode->nodeName !== 'propertyitem' ) {
58
				continue;
59
			}
60
61
			$list = [];
62
63
			foreach( $propNode->childNodes as $tagNode ) {
64
				$list[$tagNode->nodeName] = $tagNode->nodeValue;
65
			}
66
67
			$propItem = $manager->createItem()->fromArray( $list );
68
69
			if( isset( $map[$propItem->getType()][$propItem->getLanguageId()][$propItem->getValue()] ) ) {
70
				unset( $propItems[ $map[$propItem->getType()][$propItem->getLanguageId()][$propItem->getValue()] ] );
71
			} else {
72
				$item->addPropertyItem( $propItem );
73
			}
74
		}
75
76
		return $item->deletePropertyItems( $propItems );
77
	}
78
}
79