Director::compose()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 13 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
namespace WFV\Artisan;
3
defined( 'ABSPATH' ) || die();
4
5
use WFV\Contract\ArtisanInterface;
6
7
/**
8
 *
9
 *
10
 * @since 0.10.0
11
 *
12
 */
13
class Director {
14
15
	/**
16
	 *
17
	 *
18
	 * @since 0.10.0
19
	 * @access protected
20
	 * @var array
21
	 */
22
	protected $component = array();
23
24
	/**
25
	 *
26
	 *
27
	 * @since 0.10.0
28
	 *
29
	 * @param ArtisanInterface $builder
30
	 * @return object
31
	 */
32
	public function compose( ArtisanInterface $builder ) {
33
		$this->amalgamate( $this->component, $builder );
34
		return $builder
35
			->create()
36
			->actualize();
37
	}
38
39
	/**
40
	 *
41
	 *
42
	 * @since 0.10.0
43
	 *
44
	 * @param string $name
45
	 * @param string|array|object (optional) $params
46
	 * @return self
47
	 */
48
	public function with( $name, $params = null ) {
49
		$this->component[ $name ] = $params;
50
		return $this;
51
	}
52
53
	/**
54
	 * Amalgamate
55
	 *
56
	 * @since 0.10.0
57
	 * @access private
58
	 *
59
	 * @param array $components
60
	 * @param ArtisanInterface $builder
61
	 */
62
	private function amalgamate( array $components, ArtisanInterface &$builder ) {
63
		foreach( $components as $component => $params ) {
64
			$builder->$component( $params );
65
		}
66
	}
67
}
68