Completed
Push — master ( 3f77a7...938ad9 )
by Andrii
03:48
created

DebugAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 2
c 2
b 1
f 0
lcom 1
cbo 5
dl 0
loc 36
ccs 0
cts 18
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 23 2
1
<?php
2
/**
3
 * Tools to use API as ActiveRecord for Yii2
4
 *
5
 * @link      https://github.com/hiqdev/yii2-hiart
6
 * @package   yii2-hiart
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, 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
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