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

IndexController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 16
c 1
b 0
f 0
dl 0
loc 43
ccs 0
cts 14
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 4 1
A __construct() 0 4 1
A toolbar() 0 14 1
A panel() 0 4 1
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