Completed
Push — develop ( 9ed2dd...34c48b )
by Peter
18:31 queued 06:00
created

DrawPanel   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 86
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A getProfiler() 0 7 2
A setProfiler() 0 5 1
A dump() 0 7 2
A getTab() 0 8 3
A getPanel() 0 4 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-2018 Webino, s. r. o. (http://webino.sk/)
7
 * @license     BSD-3-Clause
8
 */
9
10
namespace WebinoDraw\Debugger;
11
12
use Tracy\Dumper;
13
use WebinoDebug\Debugger\AbstractPanel;
14
use WebinoDebug\Debugger\PanelInitInterface;
15
use WebinoDebug\Debugger\PanelInterface;
16
use WebinoDebug\Exception;
17
use WebinoDraw\Service\DrawProfiler;
18
use Zend\ServiceManager\ServiceManager;
19
20
/**
21
 * Class DrawPanel
22
 */
23
class DrawPanel extends AbstractPanel implements
24
    PanelInterface,
25
    PanelInitInterface
26
{
27
    /**
28
     * Profiler bar panel id
29
     */
30
    const ID = 'WebinoDraw:draw';
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    protected $dir = __DIR__;
36
37
    /**
38
     * @var DrawProfiler
39
     */
40
    private $profiler;
41
42
    /**
43
     * @var string
44
     */
45
    protected $title = 'WebinoDraw profiler';
46
47
    /**
48
     * @param ServiceManager $services
49
     */
50
    public function init(ServiceManager $services)
51
    {
52
        $this->setProfiler($services->get(DrawProfiler::class));
53
    }
54
55
    /**
56
     * @return DrawProfiler
57
     * @throws Exception\LogicException
58
     */
59
    protected function getProfiler()
60
    {
61
        if (null === $this->profiler) {
62
            throw new Exception\LogicException('Expected `profiler`');
63
        }
64
        return $this->profiler;
65
    }
66
67
    /**
68
     * @param object|DrawProfiler $profiler
69
     * @return $this
70
     */
71
    public function setProfiler(DrawProfiler $profiler)
72
    {
73
        $this->profiler = $profiler;
74
        return $this;
75
    }
76
77
    /**
78
     * @param $var mixed
79
     * @return string
80
     */
81
    public function dump($var) : string
82
    {
83
        if (!class_exists(Dumper::class)) {
84
            return 'Required: ' . Dumper::class;
85
        }
86
        return Dumper::toHtml($var, [Dumper::DEPTH => 10, Dumper::COLLAPSE => 1]);
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function getTab()
93
    {
94
        $profiler = $this->getProfiler();
95
        if (!$profiler || empty($profiler->getData())) {
96
            return '';
97
        }
98
        return $this->createIcon('draw', 'top: -3px;') . parent::getTab();
99
    }
100
101
    /**
102
     * {@inheritdoc}
103
     */
104
    public function getPanel()
105
    {
106
        return $this->renderTemplate('draw.panel');
107
    }
108
}
109