Completed
Push — master ( 661260...8915f1 )
by
unknown
03:09
created

Highchart::makeClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace EnergieProduction\Chart\Highcharts;
4
5
use EnergieProduction\Chart\Builder;
6
use EnergieProduction\Chart\Exceptions\UnavailableTypeException;
7
8
abstract Class Highchart
9
{
10
	protected $config = [];
11
12
	public function __construct(array $config)
13
	{
14
		$this->config = $config;
15
	}
16
17
	public function make($type, $callback)
18
	{
19
		$availableTypes = array_keys($this->config['available_types']);
20
21
		if (! in_array($type, $availableTypes)) {
22
			throw new UnavailableTypeException;
23
		}
24
25
		$optionClass = $this->makeClass($type);
26
27
		$builder = new Builder($optionClass);
28
29
		return $builder->make($callback);
30
	}
31
32
	protected function makeClass($type)
33
	{
34
		$className = ucfirst($type);
35
36
		$class = static::path . $className;
37
38
		$config = $this->config['available_types'][$type];
39
40
		return new $class($config);
41
	}
42
}
43