Completed
Push — master ( 6f4209...a56798 )
by Aimeos
03:04
created

Standard   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 63
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C process() 0 39 7
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017
6
 * @package Controller
7
 * @subpackage Common
8
 */
9
10
11
namespace Aimeos\Controller\Common\Order\Export\Csv\Processor\Service;
12
13
14
/**
15
 * Service processor for order CSV exports
16
 *
17
 * @package Controller
18
 * @subpackage Common
19
 */
20
class Standard
21
	extends \Aimeos\Controller\Common\Order\Export\Csv\Processor\Base
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
Coding Style introduced by
Expected 0 spaces between "Base" and comma; 1 found
Loading history...
22
	implements \Aimeos\Controller\Common\Order\Export\Csv\Processor\Iface
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
23
{
24
	/** controller/common/order/export/csv/processor/service/name
25
	 * Name of the service processor implementation
26
	 *
27
	 * Use "Myname" if your class is named "\Aimeos\Controller\Common\Order\Export\Csv\Processor\Service\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 2017.08
32
	 * @category Developer
33
	 */
34
35
36
	/**
37
	 * Returns the order related data
38
	 *
39
	 * @param \Aimeos\MShop\Order\Item\Iface $invoice Invoice item
40
	 * @param \Aimeos\MShop\Order\Item\Base\Iface $order Full order with associated items
41
	 * @return array Two dimensional associative list of order data representing the lines in CSV
42
	 */
43
	public function process( \Aimeos\MShop\Order\Item\Iface $invoice, \Aimeos\MShop\Order\Item\Base\Iface $order )
44
	{
45
		$result = [];
46
		$services = $order->getServices();
47
48
		krsort( $services );
49
50
		foreach( $services as $item )
51
		{
52
			$data = [];
53
			$list = $item->toArray();
54
55
			foreach( $item->getAttributes() as $attrItem )
56
			{
57
				foreach( $attrItem->toArray() as $key => $value )
58
				{
59
					if( isset( $list[$key] ) ) {
60
						$list[$key] .= "\n" . $value;
61
					} else {
62
						$list[$key] = $value;
63
					}
64
				}
65
			}
66
67
			foreach( $this->getMapping() as $pos => $key )
68
			{
69
				if( array_key_exists( $key, $list ) ) {
70
					$data[$pos] = $list[$key];
71
				} else {
72
					$data[$pos] = '';
73
				}
74
			}
75
76
			ksort( $data );
77
			$result[] = $data;
78
		}
79
80
		return $result;
81
	}
82
}
83