DbPanel   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 74
ccs 32
cts 32
cp 1
rs 10
c 0
b 0
f 0
wmc 12
lcom 2
cbo 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getLabel() 0 7 1
A save() 0 5 3
A registerAssets() 0 4 1
A calculateTimings() 0 10 3
A getDetail() 0 20 4
1
<?php
2
3
namespace bedezign\yii2\audit\panels;
4
5
use bedezign\yii2\audit\components\panels\DataStoragePanelTrait;
6
use Yii;
7
use yii\debug\models\search\Db;
8
use yii\grid\GridViewAsset;
9
10
/**
11
 * DbPanel
12
 * @package bedezign\yii2\audit\panels
13
 *
14
 * @method bool hasExplain()
15
 * @method int sumDuplicateQueries()
16
 */
17
class DbPanel extends \yii\debug\panels\DbPanel
18
{
19
    use DataStoragePanelTrait;
20
21
    /**
22
     * @var array current database request timings
23
     */
24
    private $_timings;
25
26
    /**
27
     * @inheritdoc
28 3
     */
29
    public function getLabel()
30 3
    {
31 3
        $timings = $this->calculateTimings();
32 3
        $queryCount = count($timings);
33 3
        $queryTime = number_format($this->getTotalQueryTime($timings) * 1000) . ' ms';
34
        return $this->getName() . ' <small>(' . $queryCount . ' / ' . $queryTime . ')</small>';
35
    }
36
37
    /**
38
     * @inheritdoc
39 3
     */
40
    public function getDetail()
41 3
    {
42
        $searchModel = new Db();
43 3
44 3
        if (!$searchModel->load(Yii::$app->request->getQueryParams())) {
45 3
            $searchModel->load($this->defaultFilter, '');
46
        }
47 3
48 3
        $models = $this->getModels();
49
        $dataProvider = $searchModel->search($models);
50 3
        $dataProvider->getSort()->defaultOrder = $this->defaultOrder;
51 3
52 3
        return Yii::$app->view->render('@yii/debug/views/default/panels/db/detail', [
53 3
            'panel' => $this,
54 3
            'dataProvider' => $dataProvider,
55 3
            'searchModel' => $searchModel,
56
            'hasExplain' => method_exists($this, 'hasExplain') ? $this->hasExplain() : null,
57
            'sumDuplicates' => method_exists($this, 'sumDuplicateQueries') ? $this->sumDuplicateQueries($models) : null,
0 ignored issues
show
Unused Code introduced by Steve Guns
The call to DbPanel::sumDuplicateQueries() has too many arguments starting with $models.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
58 60
        ]);
59
    }
60 57
61 60
    public function save()
62
    {
63
        $data = parent::save();
64
        return (isset($data['messages']) && count($data['messages']) > 0) ? $data : null;
65
    }
66
67 3
    /**
68
     * @inheritdoc
69 3
     */
70 3
    public function registerAssets($view)
71
    {
72
        GridViewAsset::register($view);
73
    }
74
75
    /**
76
     * Calculates given request profile timings.
77 3
     *
78
     * @return array timings [token, category, timestamp, traces, nesting level, elapsed time]
79 3
     */
80 3
    public function calculateTimings()
81 3
    {
82 3
        if ($this->_timings === null) {
83 3
            $this->_timings = [];
84 3
            if (isset($this->data['messages'])) {
85 3
                $this->_timings = Yii::getLogger()->calculateTimings($this->data['messages']);
86
            }
87
        }
88
        return $this->_timings;
89
    }
90
}