Chart   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 60
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A pushSubset() 0 20 3
A render() 0 10 2
A restoreExpressions() 0 7 1
1
<?php
2
3
namespace EnergieProduction\Chart;
4
5
use closure;
6
use EnergieProduction\Chart\Exceptions\DotNotationNotAvailableException;
7
8
class Chart {
9
10
    protected $options = [];
11
12
    /**
13
     * [pushSubset description]
14
     * @param  string  $subset
15
     * @param  closure $closure
16
     * @throws EnergieProduction\Chart\Exceptions\DotNotationNotAvailableException
17
     * @return void
18
     */
19
    public function pushSubset($subset, closure $closure)
20
    {
21
        $option = new Option();
22
23
        $option->pushSubset($subset, $closure);
24
25
        $render = $option->render();
26
27
        if (starts_with($subset, 'series')) {
28
29
            if (str_contains($subset, '.')) {
30
                throw new Exceptions\DotNotationNotAvailableException();
31
            }
32
33
            $this->options['series'][] = $render['series'];
34
        }
35
        else {
36
            $this->options = array_merge_recursive($this->options, $render);
37
        }
38
    }
39
40
    /**
41
     * [render description]
42
     * @return void
43
     */
44
    public function render()
45
    {
46
        $formatedOption = json_encode($this->options);
47
48
        if (str_contains($formatedOption, '"#!!')) {
49
            $formatedOption = $this->restoreExpressions($formatedOption);
50
        }
51
52
        return $formatedOption;
53
    }
54
55
    /**
56
     * [restoreExpressions description]
57
     * @param  string $formatedOption
58
     * @return string
59
     */
60
    protected function restoreExpressions($formatedOption)
61
    {
62
        $formatedOption = str_replace('"#!!', '', $formatedOption);
63
        $formatedOption = str_replace('!!#"', '', $formatedOption);
64
65
        return $formatedOption;
66
    }  
67
}
68