Passed
Push — master ( b8f18d...700c02 )
by Aimeos
33:19 queued 19:46
created

Base::getProcessors()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 14
nc 4
nop 1
dl 0
loc 27
rs 9.7998
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), 2018-2023
6
 * @package Controller
7
 * @subpackage Common
8
 */
9
10
11
namespace Aimeos\Controller\Jobs\Subscription\Export\Csv;
12
13
14
/**
15
 * Common class for CSV subscription export job controllers and processors.
16
 *
17
 * @package Controller
18
 * @subpackage Common
19
 */
20
class Base
21
	extends \Aimeos\Controller\Jobs\Base
22
{
23
	/**
24
	 * Returns the default mapping for the CSV fields to the domain item keys
25
	 *
26
	 * Example:
27
	 * 'subscription' => array(
28
	 *     2 => 'subscription.interval',
29
	 *     3 => 'subscription.datenext',
30
	 *     4 => 'subscription.dateend',
31
	 * ),
32
	 * 'address' => array(
33
	 *     2 => 'subscription.address.type',
34
	 *     3 => 'subscription.address.firstname',
35
	 *     4 => 'subscription.address.lastname',
36
	 * ),
37
	 * 'product' => array(
38
	 *     2 => 'subscription.product.type',
39
	 *     3 => 'subscription.product.prodcode',
40
	 *     4 => 'subscription.product.quantity',
41
	 * ),
42
	 *
43
	 * @return array Associative list of domains as keys and a list of
44
	 * 	positions and the domain item keys as values.
45
	 */
46
	protected function getDefaultMapping() : array
47
	{
48
		return array(
49
			'subscription' => array(
50
				2 => 'subscription.interval',
51
				3 => 'subscription.datenext',
52
				4 => 'subscription.dateend',
53
				5 => 'subscription.period',
54
				6 => 'subscription.status',
55
				7 => 'subscription.ctime',
56
				8 => 'subscription.ordbaseid',
57
			),
58
			'address' => array(
59
				2 => 'order.address.type',
60
				3 => 'order.address.salutation',
61
				4 => 'order.address.company',
62
				5 => 'order.address.vatid',
63
				6 => 'order.address.title',
64
				7 => 'order.address.firstname',
65
				8 => 'order.address.lastname',
66
				9 => 'order.address.address1',
67
				10 => 'order.address.address2',
68
				11 => 'order.address.address3',
69
				12 => 'order.address.postal',
70
				13 => 'order.address.city',
71
				14 => 'order.address.state',
72
				15 => 'order.address.countryid',
73
				16 => 'order.address.languageid',
74
				17 => 'order.address.telephone',
75
				18 => 'order.address.telefax',
76
				19 => 'order.address.email',
77
				20 => 'order.address.website',
78
				21 => 'order.address.longitude',
79
				22 => 'order.address.latitude',
80
			),
81
			'product' => array(
82
				2 => 'order.product.type',
83
				3 => 'order.product.stocktype',
84
				4 => 'order.product.vendor',
85
				5 => 'order.product.prodcode',
86
				6 => 'order.product.productid',
87
				7 => 'order.product.quantity',
88
				8 => 'order.product.name',
89
				9 => 'order.product.mediaurl',
90
				10 => 'order.product.price',
91
				11 => 'order.product.costs',
92
				12 => 'order.product.rebate',
93
				13 => 'order.product.taxrate',
94
				14 => 'order.product.status',
95
				15 => 'order.product.position',
96
				16 => 'order.product.attribute.type',
97
				17 => 'order.product.attribute.code',
98
				18 => 'order.product.attribute.name',
99
				19 => 'order.product.attribute.value',
100
			),
101
		);
102
	}
103
104
105
	/**
106
	 * Returns the processor object for saving the subscription/order related information
107
	 *
108
	 * @param array $mappings Associative list of processor types as keys and index/data mappings as values
109
	 * @return array Associative list of processor types as keys and processor objects as values
110
	 * @throws \LogicException If class can't be instantiated
111
	 */
112
	protected function getProcessors( array $mappings ) : array
113
	{
114
		$list = [];
115
		$context = $this->context();
116
		$config = $context->config();
117
118
		foreach( $mappings as $type => $mapping )
119
		{
120
			if( ctype_alnum( $type ) === false ) {
121
				throw new \LogicException( sprintf( 'Invalid characters in class name "%1$s"', $type ), 400 );
122
			}
123
124
			$name = $config->get( 'controller/common/subscription/export/csv/processor/' . $type . '/name', 'Standard' );
125
126
			if( ctype_alnum( $name ) === false ) {
127
				throw new \LogicException( sprintf( 'Invalid characters in class name "%1$s"', $name ), 400 );
128
			}
129
130
			$classname = '\\Aimeos\\Controller\\Common\\Subscription\\Export\\Csv\\Processor\\' . ucfirst( $type ) . '\\' . $name;
131
			$interface = \Aimeos\Controller\Common\Subscription\Export\Csv\Processor\Iface::class;
0 ignored issues
show
Bug introduced by
The type Aimeos\Controller\Common...ort\Csv\Processor\Iface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
132
133
			$object = \Aimeos\Utils::create( $classname, [$context, $mapping], $interface );
134
135
			$list[$type] = $object;
136
		}
137
138
		return $list;
139
	}
140
}
141