DebugAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 21 2
1
<?php
2
/**
3
 * ActiveRecord for API
4
 *
5
 * @link      https://github.com/hiqdev/yii2-hiart
6
 * @package   yii2-hiart
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\hiart\debug;
12
13
use Yii;
14
use yii\helpers\ArrayHelper;
15
use yii\web\HttpException;
16
use yii\web\Response;
17
18
/**
19
 * Debug Action is used by [[DebugPanel]] to perform HiArt queries using ajax.
20
 */
21
class DebugAction extends \yii\base\Action
22
{
23
    /**
24
     * @var DebugPanel
25
     */
26
    public $panel;
27
28
    /**
29
     * @var \yii\debug\controllers\DefaultController
0 ignored issues
show
Bug introduced by
The type yii\debug\controllers\DefaultController was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
     */
31
    public $controller;
32
33
    public function run($logId, $tag)
34
    {
35
        $this->controller->loadData($tag);
36
37
        $timings = $this->panel->getTimings();
38
        ArrayHelper::multisort($timings, 3, SORT_DESC);
39
40
        if (!isset($timings[$logId])) {
41
            throw new HttpException(404, 'Log message not found.');
42
        }
43
44
        $request  = unserialize($timings[$logId][1]);
45
        $time     = microtime(true);
46
        $response = $request->send();
47
        $time     = microtime(true) - $time;
48
49
        Yii::$app->response->format = Response::FORMAT_JSON;
50
51
        return [
52
            'time'   => sprintf('%.1f ms', $time * 1000),
53
            'result' => $response->getData(),
54
        ];
55
    }
56
}
57