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
|
|
|
* Be able to use Module Configuration for DbPanel |
23
|
|
|
*/ |
24
|
|
|
public function init() |
25
|
|
|
{ |
26
|
|
|
$this->db = $this->module->db; |
27
|
|
|
} |
28
|
3 |
|
|
29
|
|
|
/** |
30
|
3 |
|
* @var array current database request timings |
31
|
3 |
|
*/ |
32
|
3 |
|
private $_timings; |
33
|
3 |
|
|
34
|
|
|
/** |
35
|
|
|
* @inheritdoc |
36
|
|
|
*/ |
37
|
|
|
public function getLabel() |
38
|
|
|
{ |
39
|
3 |
|
$timings = $this->calculateTimings(); |
40
|
|
|
$queryCount = count($timings); |
41
|
3 |
|
$queryTime = number_format($this->getTotalQueryTime($timings) * 1000) . ' ms'; |
42
|
|
|
return $this->getName() . ' <small>(' . $queryCount . ' / ' . $queryTime . ')</small>'; |
43
|
3 |
|
} |
44
|
3 |
|
|
45
|
3 |
|
/** |
46
|
|
|
* @inheritdoc |
47
|
3 |
|
*/ |
48
|
3 |
|
public function getDetail() |
49
|
|
|
{ |
50
|
3 |
|
$searchModel = new Db(); |
51
|
3 |
|
|
52
|
3 |
|
if (!$searchModel->load(Yii::$app->request->getQueryParams())) { |
53
|
3 |
|
$searchModel->load($this->defaultFilter, ''); |
54
|
3 |
|
} |
55
|
3 |
|
|
56
|
|
|
$models = $this->getModels(); |
57
|
|
|
$dataProvider = $searchModel->search($models); |
58
|
60 |
|
$dataProvider->getSort()->defaultOrder = $this->defaultOrder; |
59
|
|
|
|
60
|
57 |
|
return Yii::$app->view->render('@yii/debug/views/default/panels/db/detail', [ |
61
|
60 |
|
'panel' => $this, |
62
|
|
|
'dataProvider' => $dataProvider, |
63
|
|
|
'searchModel' => $searchModel, |
64
|
|
|
'hasExplain' => method_exists($this, 'hasExplain') ? $this->hasExplain() : null, |
65
|
|
|
'sumDuplicates' => method_exists($this, 'sumDuplicateQueries') ? $this->sumDuplicateQueries($models) : null, |
|
|
|
|
66
|
|
|
]); |
67
|
3 |
|
} |
68
|
|
|
|
69
|
3 |
|
public function save() |
70
|
3 |
|
{ |
71
|
|
|
$data = parent::save(); |
72
|
|
|
return (isset($data['messages']) && count($data['messages']) > 0) ? $data : null; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @inheritdoc |
77
|
3 |
|
*/ |
78
|
|
|
public function registerAssets($view) |
79
|
3 |
|
{ |
80
|
3 |
|
GridViewAsset::register($view); |
81
|
3 |
|
} |
82
|
3 |
|
|
83
|
3 |
|
/** |
84
|
3 |
|
* Calculates given request profile timings. |
85
|
3 |
|
* |
86
|
|
|
* @return array timings [token, category, timestamp, traces, nesting level, elapsed time] |
87
|
|
|
*/ |
88
|
|
|
public function calculateTimings() |
89
|
|
|
{ |
90
|
|
|
if ($this->_timings === null) { |
91
|
|
|
$this->_timings = []; |
92
|
|
|
if (isset($this->data['messages'])) { |
93
|
|
|
$this->_timings = Yii::getLogger()->calculateTimings($this->data['messages']); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
return $this->_timings; |
97
|
|
|
} |
98
|
|
|
} |
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.