Passed
Push — master ( 159b17...86ca6d )
by Rustam
02:24
created

IndexController::toolbar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 14
ccs 0
cts 7
cp 0
rs 9.9666
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Viewer;
6
7
use Psr\Http\Message\ResponseFactoryInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use Yiisoft\DataResponse\DataResponseFactoryInterface;
10
use Yiisoft\Router\CurrentRoute;
11
use Yiisoft\Yii\Debug\Viewer\Panels\PanelInterface;
12
13
final class IndexController
14
{
15
    private DataResponseFactoryInterface $responseFactory;
16
17
    /**
18
     * IndexController constructor.
19
     */
20
    public function __construct(
21
        DataResponseFactoryInterface $responseFactory
22
    ) {
23
        $this->responseFactory = $responseFactory;
24
    }
25
26
    /**
27
     * @return ResponseInterface
28
     */
29
    public function index(): ResponseInterface
30
    {
31
        return $this->responseFactory->createResponse(
32
            file_get_contents(dirname(__DIR__) . '/resources/views/index.html')
33
        );
34
    }
35
36
    public function panel(CurrentRoute $currentRoute, PanelCollection $panelCollection): ResponseInterface
37
    {
38
        $panel = $panelCollection->getPanel($currentRoute->getArgument('panel'));
0 ignored issues
show
Bug introduced by
It seems like $currentRoute->getArgument('panel') can also be of type null; however, parameter $id of Yiisoft\Yii\Debug\Viewer...lCollection::getPanel() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

38
        $panel = $panelCollection->getPanel(/** @scrutinizer ignore-type */ $currentRoute->getArgument('panel'));
Loading history...
39
        return $this->responseFactory->createResponse($panel->renderDetail());
40
    }
41
42
    public function toolbar(
43
        ResponseFactoryInterface $responseFactory,
44
        PanelCollection $panelCollection
45
    ) {
46
        $html = file_get_contents(dirname(__DIR__) . '/resources/views/toolbar.html');
47
        $panels = array_map(
48
            static fn (PanelInterface $panel) => $panel->renderSummary(),
49
            $panelCollection->getPanels()
50
        );
51
        $html = strtr($html, ['{TOOLBAR_BLOCKS}' => implode("\n", $panels)]);
52
        $response = $responseFactory->createResponse()
53
            ->withHeader('Content-Type', 'text/html');
54
        $response->getBody()->write($html);
55
        return $response;
56
    }
57
}
58