Conditions | 9 |
Paths | 72 |
Total Lines | 69 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
54 | */ |
||
55 | public function actionDashboardRadialBar( |
||
56 | string $range = 'day', |
||
57 | string $column = 'pageLoad', |
||
58 | int $siteId = 0 |
||
59 | ): Response { |
||
60 | PermissionHelper::controllerPermissionCheck('webperf:dashboard'); |
||
61 | $data = []; |
||
62 | $days = 1; |
||
63 | switch ($range) { |
||
64 | case 'day': |
||
65 | $days = 1; |
||
66 | break; |
||
67 | case 'week': |
||
68 | $days = 7; |
||
69 | break; |
||
70 | case 'month': |
||
71 | $days = 30; |
||
72 | break; |
||
73 | } |
||
74 | // Different dbs do it different ways |
||
75 | $stats = null; |
||
76 | $db = Craft::$app->getDb(); |
||
77 | if ($db->getIsMysql()) { |
||
78 | // Query the db |
||
79 | $query = (new Query()) |
||
80 | ->from('{{%webperf_data_samples}}') |
||
81 | ->select([ |
||
82 | 'AVG('.$column.') AS avg', |
||
83 | ]) |
||
84 | ->where("dateUpdated >= ( CURDATE() - INTERVAL '{$days}' DAY )"); |
||
85 | if ((int)$siteId !== 0) { |
||
86 | $query->andWhere(['siteId' => $siteId]); |
||
87 | } |
||
88 | $stats = $query->all(); |
||
89 | } |
||
90 | if ($db->getIsPgsql()) { |
||
91 | // Query the db |
||
92 | $query = (new Query()) |
||
93 | ->from('{{%retour_stats}}') |
||
94 | ->select([ |
||
95 | "to_char(\"hitLastTime\", 'yyyy-mm-dd') AS date_formatted", |
||
96 | "COUNT(\"redirectSrcUrl\") AS cnt", |
||
97 | "COUNT(CASE WHEN \"handledByRetour\" = true THEN 1 END) as handled_cnt", |
||
98 | ]) |
||
99 | ->where("\"hitLastTime\" >= ( CURRENT_TIMESTAMP - INTERVAL '{$days} days' )"); |
||
100 | if ((int)$siteId !== 0) { |
||
101 | $query->andWhere(['siteId' => $siteId]); |
||
102 | } |
||
103 | $query |
||
104 | ->orderBy('date_formatted ASC') |
||
105 | ->groupBy('date_formatted'); |
||
106 | $stats = $query->all(); |
||
107 | } |
||
108 | if ($stats) { |
||
109 | $data = ArrayHelper::getColumn($stats, 'avg'); |
||
110 | } |
||
111 | |||
112 | return $this->asJson($data); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * The Dashboard chart |
||
117 | * |
||
118 | * @param int $days |
||
119 | * |
||
120 | * @return Response |
||
121 | */ |
||
122 | public function actionWidget($days = 1): Response |
||
123 | { |
||
166 |