DrawProfiler   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 103
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getData() 0 9 2
A getTotalTime() 0 4 1
A beginNodeRender() 0 17 1
A beginNodesDraw() 0 4 1
A finishNodesDraw() 0 9 1
A createKey() 0 4 2
1
<?php
2
/**
3
 * Webino (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino/WebinoDraw for the canonical source repository
6
 * @copyright   Copyright (c) 2012-2018 Webino, s. r. o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoDraw\Service;
12
13
use WebinoDebug\Debugger\DebuggerInterface as Debugger;
14
15
/**
16
 * Class DrawProfiler
17
 */
18
class DrawProfiler
19
{
20
    /**
21
     * @var int
22
     */
23
    protected $n = 0;
24
25
    /**
26
     * @var Debugger
27
     */
28
    protected $debugger;
29
30
    /**
31
     * @var array
32
     */
33
    protected $data = [];
34
35
    /**
36
     * @var float
37
     */
38
    protected $totalTime = 0;
39
40
    /**
41
     * @param Debugger $debugger
42
     */
43
    public function __construct(Debugger $debugger)
44
    {
45
        $this->debugger = $debugger;
46
    }
47
48
    /**
49
     * @return array
50
     */
51
    public function getData()
52
    {
53
        $data = [];
54
        foreach ($this->data as $row) {
55
            $data[$row['n']] = $row;
56
        }
57
        ksort($data);
58
        return $data;
59
    }
60
61
    /**
62
     * @return float
63
     */
64
    public function getTotalTime()
65
    {
66
        return $this->totalTime;
67
    }
68
69
    /**
70
     * @param array $spec
71
     * @param $isDisabled
72
     */
73
    public function beginNodeRender(array $spec, $isDisabled)
0 ignored issues
show
Unused Code introduced by
The parameter $isDisabled is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
    {
75
        // TODO disabled indicator
76
77
        $this->n++;
78
79
        $_spec = $spec;
80
        unset($_spec['_key']);
81
82
        $key = $this->createKey($spec);
83
        $this->data[$key] = [
84
            'n'    => $this->n,
85
            'key'  => $key,
86
            'spec' => $_spec,
87
            'time' => 0,
88
        ];
89
    }
90
91
    /**
92
     * @TODO method description
93
     */
94
    public function beginNodesDraw($nodes, $helper, $spec, $vars)
0 ignored issues
show
Unused Code introduced by
The parameter $nodes is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $helper is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $spec is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $vars is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
95
    {
96
        $this->debugger->timer(__CLASS__);
97
    }
98
99
    /**
100
     * @TODO method description
101
     */
102
    public function finishNodesDraw($nodes, $helper, $spec, $vars)
0 ignored issues
show
Unused Code introduced by
The parameter $nodes is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $helper is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $vars is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
103
    {
104
        // TODO show more info (nodes, helper, vars?)
105
106
        $time = $this->debugger->timer(__CLASS__)->getDelta();
107
        $index = $this->createKey($spec);
108
        $this->data[$index]['time'] = $time;
109
        $this->totalTime+= $time;
110
    }
111
112
    /**
113
     * @param array $spec
114
     * @return string
115
     */
116
    protected function createKey(array $spec)
117
    {
118
        return empty($spec['_key']) ? '-' : $spec['_key'];
119
    }
120
}
121