Passed
Push — master ( add725...ffb802 )
by Aimeos
04:14
created

Standard::process()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 37
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 19
c 1
b 0
f 0
nc 8
nop 2
dl 0
loc 37
rs 9.3222
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2025
6
 * @package Controller
7
 * @subpackage Common
8
 */
9
10
11
namespace Aimeos\Controller\Jobs\Common\Customer\Import\Csv\Processor\Property;
12
13
14
/**
15
 * Customer property processor for CSV imports
16
 *
17
 * @package Controller
18
 * @subpackage Common
19
 */
20
class Standard
21
	extends \Aimeos\Controller\Jobs\Common\Customer\Import\Csv\Processor\Base
22
	implements \Aimeos\Controller\Jobs\Common\Customer\Import\Csv\Processor\Iface
23
{
24
	/** controller/jobs/customer/import/csv/processor/property/name
25
	 * Name of the property processor implementation
26
	 *
27
	 * Use "Myname" if your class is named "\Aimeos\Controller\Jobs\Common\Customer\Import\Csv\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 2025.10
32
	 */
33
34
35
	/**
36
	 * Saves the customer property related data to the storage
37
	 *
38
	 * @param \Aimeos\MShop\Customer\Item\Iface $customer Customer item with associated items
39
	 * @param array $data List of CSV fields with position as key and data as value
40
	 * @return array List of data which hasn't been imported
41
	 */
42
	public function process( \Aimeos\MShop\Customer\Item\Iface $customer, array $data ) : array
43
	{
44
		$manager = \Aimeos\MShop::create( $this->context(), 'customer' );
45
46
		$propMap = [];
47
		$items = $customer->getPropertyItems( null, false );
48
		$map = $this->getMappedChunk( $data, $this->getMapping() );
49
50
		foreach( $items as $item ) {
51
			$propMap[$item->getValue()][$item->getType()] = $item;
52
		}
53
54
		foreach( $map as $list )
55
		{
56
			if( ( $value = $this->val( $list, 'customer.property.value' ) ) === null ) {
57
				continue;
58
			}
59
60
			$type = $this->val( $list, 'customer.property.type' );
61
			$this->addType( 'customer/property/type', 'customer', $type );
62
63
			if( isset( $propMap[$value][$type] ) )
64
			{
65
				$item = $propMap[$value][$type];
66
				$items->remove( $item->getId() );
67
			}
68
			else
69
			{
70
				$item = $manager->createPropertyItem()->setType( $type );
0 ignored issues
show
Bug introduced by
The method createPropertyItem() 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

70
				$item = $manager->/** @scrutinizer ignore-call */ createPropertyItem()->setType( $type );

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...
71
			}
72
73
			$customer->addPropertyItem( $item->fromArray( $list ) );
74
		}
75
76
		$customer->deletePropertyItems( $items );
77
78
		return $this->object()->process( $customer, $data );
79
	}
80
}
81