DebugBarExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A debugBarJs() 0 4 1
A __construct() 0 5 1
A debugBarHtml() 0 3 1
A register() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Bone\DebugBar\View\Extension;
6
7
use Bone\DebugBar\DebugBar;
8
use DebugBar\JavascriptRenderer;
9
use League\Plates\Engine;
10
use League\Plates\Extension\ExtensionInterface;
11
use League\Plates\Template\Template;
12
use function getenv;
13
14
class DebugBarExtension implements ExtensionInterface
15
{
16
    public ?Template $template = null;
17
    public JavascriptRenderer $renderer;
18
19
    public function __construct(
20
        private Engine $engine,
21
        private DebugBar $debugBar,
22
    ) {
23
        $this->renderer = $this->debugBar->getJavascriptRenderer('https://' . getenv('DOMAIN_NAME') . '/debug-bar');
24
    }
25
26
    public function register(Engine $engine)
27
    {
28
        $engine->registerFunction('debugBarJs', [$this, 'debugBarJs']);
29
        $engine->registerFunction('debugBarHtml', [$this, 'debugBarHtml']);
30
    }
31
32
    public function debugBarJs() : string
33
    {
34
        $this->debugBar["messages"]->addMessage("hello world!");
0 ignored issues
show
Bug introduced by
The method addMessage() does not exist on DebugBar\DataCollector\DataCollectorInterface. It seems like you code against a sub-type of DebugBar\DataCollector\DataCollectorInterface such as DebugBar\DataCollector\MessagesCollector. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        $this->debugBar["messages"]->/** @scrutinizer ignore-call */ 
35
                                     addMessage("hello world!");
Loading history...
35
        return $this->renderer->renderHead();
36
    }
37
38
    public function debugBarHtml() : string
39
    {
40
        return $this->renderer->render();
41
    }
42
}
43