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

Standard   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 59
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkEntry() 0 3 1
A process() 0 25 3
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\Address;
12
13
14
/**
15
 * Address 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/address/name
25
	 * Name of the address processor implementation
26
	 *
27
	 * Use "Myname" if your class is named "\Aimeos\Controller\Jobs\Common\Customer\Import\Csv\Processor\Address\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 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
		$context = $this->context();
45
		$manager = \Aimeos\MShop::create( $context, 'customer' );
46
47
		$pos = 0;
48
		$map = $this->getMappedChunk( $data, $this->getMapping() );
49
		$addresses = $customer->getAddressItems();
50
51
		foreach( $map as $entry )
52
		{
53
			if( $this->checkEntry( $entry ) === false ) {
54
				continue;
55
			}
56
57
			$key = $addresses->firstKey();
58
			$address = $addresses->pull( $key ) ?? $manager->createAddressItem();
0 ignored issues
show
Bug introduced by
The method createAddressItem() 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

58
			$address = $addresses->pull( $key ) ?? $manager->/** @scrutinizer ignore-call */ createAddressItem();

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...
59
			$address->setPosition( $pos++ )->fromArray( $entry );
60
61
			$customer->addAddressItem( $address, $key );
62
		}
63
64
		$customer->deleteAddressItems( $addresses, true );
0 ignored issues
show
Unused Code introduced by
The call to Aimeos\MShop\Common\Item...e::deleteAddressItems() has too many arguments starting with true. ( Ignorable by Annotation )

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

64
		$customer->/** @scrutinizer ignore-call */ 
65
             deleteAddressItems( $addresses, true );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
65
66
		return $this->object()->process( $customer, $data );
67
	}
68
69
70
	/**
71
	 * Checks if an entry can be used for updating a address item
72
	 *
73
	 * @param array $entry Associative list of key/value pairs from the mapping
74
	 * @return bool True if valid, false if not
75
	 */
76
	protected function checkEntry( array $entry ) : bool
77
	{
78
		return true;
79
	}
80
}
81