TemplatesPanel   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 36
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getTab() 0 13 2
A getPanel() 0 3 1
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of Biurad opensource projects.
5
 *
6
 * @copyright 2019 Biurad Group (https://biurad.com/)
7
 * @license   https://opensource.org/licenses/BSD-3-Clause License
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Flange\Debug\Tracy;
14
15
use Biurad\UI\Template;
16
use Tracy\Helpers;
17
use Tracy\IBarPanel;
18
19
final class TemplatesPanel implements IbarPanel
20
{
21
    /** @var array<int,string> */
22
    private array $templates = [];
23
24
    /**
25
     * Initialize the panel.
26
     */
27
    public function __construct(private Template $render)
28
    {
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function getPanel(): string
35
    {
36
        return Helpers::capture(fn () => require __DIR__.'/templates/TemplatesPanel.panel.phtml');
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getTab(): string
43
    {
44
        ($prop = new \ReflectionProperty($render = $this->render, 'loadedTemplates'))->setAccessible(true);
45
46
        foreach ($prop->getValue($render) as $name => $profile) {
47
            $this->templates[] = [
48
                'name' => $name,
49
                'path' => \str_replace('html:', '', $profile[0] ?? 'unknown'),
50
                'render' => \get_class($render->getRenders()[$profile[1] ?? 0]),
51
            ];
52
        }
53
54
        return Helpers::capture(static fn () => require __DIR__.'/templates/TemplatesPanel.tab.phtml');
55
    }
56
}
57