Completed
Push — master ( 90127a...6c75b7 )
by Aimeos
19:38
created

Base   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 4
dl 0
loc 51
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C getProcessors() 0 40 8
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018
6
 * @package Controller
7
 * @subpackage Jobs
8
 */
9
10
11
namespace Aimeos\Controller\Jobs\Subscription\Process;
12
13
14
/**
15
 * Base job controller for subscription processing
16
 *
17
 * @package Controller
18
 * @subpackage Jobs
19
 */
20
abstract class Base
21
	extends \Aimeos\Controller\Jobs\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\Jobs\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
	/**
25
	 * Returns the processor object for managing the subscription resources
26
	 *
27
	 * @param array $pnames List of processor names
28
	 * @return \Aimeos\Controller\Common\Subscription\Export\Csv\Processor\Iface Processor object
29
	 */
30
	protected function getProcessors( array $pnames )
31
	{
32
		$list = [];
33
		$context = $this->getContext();
34
		$config = $context->getConfig();
35
		$iface = '\\Aimeos\\Controller\\Common\\Subscription\\Process\\Processor\\Iface';
36
37
		foreach( $pnames as $pname )
38
		{
39
			if( ctype_alnum( $pname ) === false )
40
			{
41
				$classname = is_string($pname) ? '\\Aimeos\\Controller\\Common\\Subscription\\Process\\Processor\\' . $pname : '<not a string>';
42
				throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) );
43
			}
44
45
			$name = $config->get( 'controller/common/subscription/process/processor/' . $pname . '/name', 'Standard' );
46
47
			if( ctype_alnum( $name ) === false )
48
			{
49
				$classname = is_string($name) ? '\\Aimeos\\Controller\\Common\\Subscription\\Process\\Processor\\' . $pname . '\\' . $name : '<not a string>';
50
				throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) );
51
			}
52
53
			$classname = '\\Aimeos\\Controller\\Common\\Subscription\\Process\\Processor\\' . ucfirst( $pname ) . '\\' . $name;
54
55
			if( class_exists( $classname ) === false ) {
56
				throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Class "%1$s" not found', $classname ) );
57
			}
58
59
			$object = new $classname( $context );
60
61
			if( !( $object instanceof $iface ) ) {
62
				throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Class "%1$s" does not implement interface "%2$s"', $classname, $iface ) );
63
			}
64
65
			$list[$pname] = $object;
66
		}
67
68
		return $list;
69
	}
70
}
71