Completed
Push — develop ( bd7c3a...4cf41c )
by Peter
18:23
created

DrawPanel::dump()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 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\Bar;
11
12
use Tracy\Dumper;
13
use WebinoDebug\Debugger\Bar\AbstractPanel;
14
use WebinoDebug\Debugger\Bar\PanelInitInterface;
15
use WebinoDebug\Debugger\Bar\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
     * @var string
49
     */
50
    protected $content = '';
51
52
    /**
53
     * @param ServiceManager $services
54
     */
55
    public function init(ServiceManager $services)
56
    {
57
        $this->setProfiler($services->get(DrawProfiler::class));
0 ignored issues
show
Documentation introduced by
$services->get(\WebinoDr...ce\DrawProfiler::class) is of type object|array, but the function expects a object<WebinoDraw\Service\DrawProfiler>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
    }
59
60
    /**
61
     * @return DrawProfiler
62
     * @throws Exception\LogicException
63
     */
64
    protected function getProfiler()
65
    {
66
        if (null === $this->profiler) {
67
            throw new Exception\LogicException('Expected `profiler`');
68
        }
69
        return $this->profiler;
70
    }
71
72
    /**
73
     * @param object|DrawProfiler $profiler
74
     * @return self
75
     */
76
    public function setProfiler(DrawProfiler $profiler)
77
    {
78
        $this->profiler = $profiler;
79
        return $this;
80
    }
81
82
    public function dump($var)
83
    {
84
        if (!class_exists(Dumper::class)) {
85
            return 'Required: ' . Dumper::class;
86
        }
87
        return Dumper::toHtml($var, [Dumper::DEPTH => 10, Dumper::COLLAPSE => 1]);
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function getTab()
94
    {
95
        $profiler = $this->getProfiler();
96
        if (!$profiler || empty($profiler->getData())) {
97
            return '';
98
        }
99
        return $this->createIcon('draw', 'top: -3px;') . parent::getTab();
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function getPanel()
106
    {
107
        return $this->renderTemplate('draw.panel');
108
    }
109
}
110