ProfilingInstructionsRenderer   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 68
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getProfiler() 0 7 2
A setProfiler() 0 5 1
A createNodeSpec() 0 6 1
A resolveIsNodeDisabled() 0 6 1
A resolveIsEmptyNodes() 0 5 1
A drawNodes() 0 7 1
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-2017 Webino, s. r. o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoDraw\Instructions;
12
13
use DOMNodeList;
14
use WebinoDraw\Dom\Locator;
15
use WebinoDraw\Exception\LogicException;
16
use WebinoDraw\Service\DrawProfiler;
17
18
/**
19
 * Class ProfilingInstructionsRenderer
20
 */
21
class ProfilingInstructionsRenderer extends InstructionsRenderer
22
{
23
    /**
24
     * @var DrawProfiler
25
     */
26
    protected $profiler;
27
28
    /**
29
     * @return DrawProfiler
30
     */
31
    protected function getProfiler()
32
    {
33
        if (null === $this->profiler) {
34
            throw new LogicException('Expected profiler');
35
        }
36
        return $this->profiler;
37
    }
38
39
    /**
40
     * @param object|DrawProfiler $profiler
41
     * @return self
42
     */
43
    public function setProfiler(DrawProfiler $profiler)
44
    {
45
        $this->profiler = $profiler;
46
        return $this;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    protected function createNodeSpec(array $specs)
53
    {
54
        $spec = parent::createNodeSpec($specs);
55
        $spec['_key'] = key($specs);
56
        return $spec;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    protected function resolveIsNodeDisabled($node, array $spec)
63
    {
64
        $isDisabled = parent::resolveIsNodeDisabled($node, $spec);
65
        $this->getProfiler()->beginNodeRender($spec, $isDisabled);
66
        return $isDisabled;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    protected function resolveIsEmptyNodes(DOMNodeList $nodes = null)
73
    {
74
        // TODO profiler
75
        return parent::resolveIsEmptyNodes($nodes);
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    protected function drawNodes(DOMNodeList $nodes, $helper, array $spec, array $vars)
82
    {
83
        $profiler = $this->getProfiler();
84
        $profiler->beginNodesDraw($nodes, $helper, $spec, $vars);
85
        parent::drawNodes($nodes, $helper, $spec, $vars);
86
        $profiler->finishNodesDraw($nodes, $helper, $spec, $vars);
87
    }
88
}
89