Completed
Push — milestone/2_0/react-ui ( 5b168c...b737dc )
by
unknown
04:15
created

Factory::make()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Carbon_Fields\Container\Condition;
4
5
use Carbon_Fields\Helper\Helper;
6
use Carbon_Fields\Exception\Incorrect_Syntax_Exception;
7
8
class Factory {
9
10
	/**
11
	 * Container to resolve conditions from
12
	 */
13
	protected $ioc;
14
15
	/**
16
	 * Constructor
17
	 */
18
	public function __construct( $ioc ) {
19
		$this->ioc = $ioc;
20
	}
21
22
	/**
23
	 * Get the type for the specified class
24
	 * 
25
	 * @param  string $class
26
	 * @return string
27
	 */
28
	public function get_type( $class ) {
29
		return Helper::class_to_type( $class, '_Condition' );
30
	}
31
32
	/**
33
	 * Get an instance of the specified type
34
	 * 
35
	 * @param  string $type
36
	 * @return mixed
37
	 */
38
	public function make( $type ) {
39
		$normalized_type = Helper::normalize_type( $type );
40
		
41
		if ( isset( $this->ioc[ $normalized_type ] ) ) {
42
			return $this->ioc[ $normalized_type ];
43
		}
44
45
		Incorrect_Syntax_Exception::raise( 'Unknown condition type "' . $type . '".' );
46
		return null;
47
	}
48
}