@@ -82,7 +82,7 @@ |
||
82 | 82 | * @param $id |
83 | 83 | * @param $attribute |
84 | 84 | * @param $version |
85 | - * @return null|integer|float|string |
|
85 | + * @return string|null |
|
86 | 86 | */ |
87 | 87 | public static function findAttribute($class, $id, $attribute, $version) |
88 | 88 | { |
@@ -8,8 +8,8 @@ |
||
8 | 8 | |
9 | 9 | use Yii; |
10 | 10 | use bedezign\yii2\audit\components\panels\DataStoragePanel; |
11 | -use yii\grid\GridViewAsset; |
|
12 | 11 | use yii\data\ArrayDataProvider; |
12 | +use yii\grid\GridViewAsset; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * Class CurlPanel |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function getLabel() |
63 | 63 | { |
64 | - return $this->getName() . ' <small>(' . count($this->data) . ')</small>'; |
|
64 | + return $this->getName().' <small>('.count($this->data).')</small>'; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | } |
138 | 138 | |
139 | 139 | if ($this->content) |
140 | - $this->data[$id]['content']= curl_multi_getcontent($handle); |
|
140 | + $this->data[$id]['content'] = curl_multi_getcontent($handle); |
|
141 | 141 | |
142 | 142 | // Cleanup empty things |
143 | 143 | $this->data[$id] = array_filter($this->data[$id]); |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | if (!is_resource($resource)) |
209 | 209 | return false; |
210 | 210 | |
211 | - $parts = explode('#', (string)$resource); |
|
211 | + $parts = explode('#', (string) $resource); |
|
212 | 212 | return array_pop($parts); |
213 | 213 | } |
214 | 214 |
@@ -96,19 +96,22 @@ discard block |
||
96 | 96 | curl_setopt($handle, CURLOPT_URL, $url); |
97 | 97 | } |
98 | 98 | |
99 | - if ($postData) |
|
100 | - $this->data[$id]['post'] = $postData; |
|
99 | + if ($postData) { |
|
100 | + $this->data[$id]['post'] = $postData; |
|
101 | + } |
|
101 | 102 | |
102 | - if ($this->headers) |
|
103 | - curl_setopt($handle, CURLOPT_HEADERFUNCTION, [$this, 'captureHeader']); |
|
103 | + if ($this->headers) { |
|
104 | + curl_setopt($handle, CURLOPT_HEADERFUNCTION, [$this, 'captureHeader']); |
|
105 | + } |
|
104 | 106 | |
105 | 107 | if ($this->log) { |
106 | 108 | curl_setopt($handle, CURLOPT_VERBOSE, true); |
107 | 109 | curl_setopt($handle, CURLOPT_STDERR, $this->_logHandles[$id] = fopen('php://temp', 'rw+')); |
108 | 110 | } |
109 | 111 | |
110 | - if ($this->content) |
|
111 | - curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1); |
|
112 | + if ($this->content) { |
|
113 | + curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1); |
|
114 | + } |
|
112 | 115 | |
113 | 116 | return true; |
114 | 117 | } |
@@ -136,8 +139,9 @@ discard block |
||
136 | 139 | unset($this->_logHandles[$id]); |
137 | 140 | } |
138 | 141 | |
139 | - if ($this->content) |
|
140 | - $this->data[$id]['content']= curl_multi_getcontent($handle); |
|
142 | + if ($this->content) { |
|
143 | + $this->data[$id]['content']= curl_multi_getcontent($handle); |
|
144 | + } |
|
141 | 145 | |
142 | 146 | // Cleanup empty things |
143 | 147 | $this->data[$id] = array_filter($this->data[$id]); |
@@ -192,8 +196,9 @@ discard block |
||
192 | 196 | public function captureHeader($handle, $header) |
193 | 197 | { |
194 | 198 | $id = $this->id($handle); |
195 | - if (!isset($this->data[$id]['headers'])) |
|
196 | - $this->data[$id]['headers'] = []; |
|
199 | + if (!isset($this->data[$id]['headers'])) { |
|
200 | + $this->data[$id]['headers'] = []; |
|
201 | + } |
|
197 | 202 | |
198 | 203 | $this->data[$id]['headers'][] = $header; |
199 | 204 | return strlen($header); |
@@ -205,8 +210,9 @@ discard block |
||
205 | 210 | */ |
206 | 211 | protected function id($resource) |
207 | 212 | { |
208 | - if (!is_resource($resource)) |
|
209 | - return false; |
|
213 | + if (!is_resource($resource)) { |
|
214 | + return false; |
|
215 | + } |
|
210 | 216 | |
211 | 217 | $parts = explode('#', (string)$resource); |
212 | 218 | return array_pop($parts); |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | namespace bedezign\yii2\audit\panels; |
4 | 4 | |
5 | -use bedezign\yii2\audit\components\panels\DataStoragePanelTrait; |
|
6 | 5 | use Yii; |
6 | +use bedezign\yii2\audit\components\panels\DataStoragePanelTrait; |
|
7 | 7 | use yii\debug\models\search\Db; |
8 | 8 | use yii\grid\GridViewAsset; |
9 | 9 |
@@ -29,8 +29,8 @@ |
||
29 | 29 | { |
30 | 30 | $timings = $this->calculateTimings(); |
31 | 31 | $queryCount = count($timings); |
32 | - $queryTime = number_format($this->getTotalQueryTime($timings) * 1000) . ' ms'; |
|
33 | - return $this->getName() . ' <small>(' . $queryCount . ' / ' . $queryTime . ')</small>'; |
|
32 | + $queryTime = number_format($this->getTotalQueryTime($timings) * 1000).' ms'; |
|
33 | + return $this->getName().' <small>('.$queryCount.' / '.$queryTime.')</small>'; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | namespace bedezign\yii2\audit\panels; |
4 | 4 | |
5 | -use bedezign\yii2\audit\components\panels\DataStoragePanelTrait; |
|
6 | 5 | use Yii; |
6 | +use bedezign\yii2\audit\components\panels\DataStoragePanelTrait; |
|
7 | 7 | use yii\debug\models\search\Log; |
8 | 8 | use yii\grid\GridViewAsset; |
9 | 9 |
@@ -21,7 +21,7 @@ |
||
21 | 21 | public function getLabel() |
22 | 22 | { |
23 | 23 | $messageCount = isset($this->data['messages']) ? count($this->data['messages']) : 0; |
24 | - return $this->getName() . ($messageCount ? ' <small>(' . $messageCount . ')</small>' : ''); |
|
24 | + return $this->getName().($messageCount ? ' <small>('.$messageCount.')</small>' : ''); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -36,7 +36,7 @@ |
||
36 | 36 | |
37 | 37 | /** |
38 | 38 | * @param Event $event |
39 | - * @return null|static |
|
39 | + * @return AuditMail|null |
|
40 | 40 | */ |
41 | 41 | public function record($event) |
42 | 42 | { |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | public function init() |
30 | 30 | { |
31 | 31 | parent::init(); |
32 | - Event::on(BaseMailer::className(), BaseMailer::EVENT_AFTER_SEND, function ($event) { |
|
32 | + Event::on(BaseMailer::className(), BaseMailer::EVENT_AFTER_SEND, function($event) { |
|
33 | 33 | $this->record($event); |
34 | 34 | }); |
35 | 35 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | public function getLabel() |
117 | 117 | { |
118 | - return $this->getName() . ' <small>(' . count($this->_model->mails) . ')</small>'; |
|
118 | + return $this->getName().' <small>('.count($this->_model->mails).')</small>'; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -167,8 +167,9 @@ |
||
167 | 167 | public function cleanup($maxAge = null) |
168 | 168 | { |
169 | 169 | $maxAge = $maxAge !== null ? $maxAge : $this->maxAge; |
170 | - if ($maxAge === null) |
|
171 | - return false; |
|
170 | + if ($maxAge === null) { |
|
171 | + return false; |
|
172 | + } |
|
172 | 173 | return AuditMail::deleteAll([ |
173 | 174 | '<=', 'created', date('Y-m-d 23:59:59', strtotime("-$maxAge days")) |
174 | 175 | ]); |
@@ -2,15 +2,15 @@ |
||
2 | 2 | |
3 | 3 | namespace bedezign\yii2\audit\panels; |
4 | 4 | |
5 | +use Swift_Message; |
|
6 | +use Swift_Mime_Attachment; |
|
7 | +use Swift_Mime_MimePart; |
|
8 | +use Yii; |
|
5 | 9 | use bedezign\yii2\audit\Audit; |
6 | 10 | use bedezign\yii2\audit\components\panels\Panel; |
7 | 11 | use bedezign\yii2\audit\components\panels\RendersSummaryChartTrait; |
8 | 12 | use bedezign\yii2\audit\models\AuditMail; |
9 | 13 | use bedezign\yii2\audit\models\AuditMailSearch; |
10 | -use Swift_Message; |
|
11 | -use Swift_Mime_Attachment; |
|
12 | -use Swift_Mime_MimePart; |
|
13 | -use Yii; |
|
14 | 14 | use yii\base\Event; |
15 | 15 | use yii\grid\GridViewAsset; |
16 | 16 | use yii\mail\BaseMailer; |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | namespace bedezign\yii2\audit\panels; |
4 | 4 | |
5 | -use bedezign\yii2\audit\components\panels\DataStoragePanelTrait; |
|
6 | 5 | use Yii; |
6 | +use bedezign\yii2\audit\components\panels\DataStoragePanelTrait; |
|
7 | 7 | use yii\debug\models\search\Profile; |
8 | 8 | use yii\grid\GridViewAsset; |
9 | 9 |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | public function getLabel() |
22 | 22 | { |
23 | 23 | $memory = isset($this->data['memory']) ? sprintf('%.1f MB', $this->data['memory'] / 1048576) : ''; |
24 | - $time = isset($this->data['time']) ? number_format($this->data['time'] * 1000) . ' ms' : ''; |
|
25 | - return $this->getName() . ' <small>(' . $memory . ' / ' . $time . ')</small>'; |
|
24 | + $time = isset($this->data['time']) ? number_format($this->data['time'] * 1000).' ms' : ''; |
|
25 | + return $this->getName().' <small>('.$memory.' / '.$time.')</small>'; |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | 'dataProvider' => $dataProvider, |
39 | 39 | 'searchModel' => $searchModel, |
40 | 40 | 'memory' => isset($this->data['memory']) ? sprintf('%.1f MB', $this->data['memory'] / 1048576) : '', |
41 | - 'time' => isset($this->data['time']) ? number_format($this->data['time'] * 1000) . ' ms' : '', |
|
41 | + 'time' => isset($this->data['time']) ? number_format($this->data['time'] * 1000).' ms' : '', |
|
42 | 42 | ]); |
43 | 43 | } |
44 | 44 |
@@ -2,7 +2,6 @@ |
||
2 | 2 | namespace bedezign\yii2\audit\panels; |
3 | 3 | |
4 | 4 | use Yii; |
5 | -use bedezign\yii2\audit\models\AuditError; |
|
6 | 5 | use bedezign\yii2\audit\components\panels\DataStoragePanel; |
7 | 6 | use yii\data\ArrayDataProvider; |
8 | 7 |
@@ -35,8 +35,9 @@ |
||
35 | 35 | { |
36 | 36 | $this->module->registerPanel($this); |
37 | 37 | |
38 | - if (!is_array($this->data)) |
|
39 | - $this->data = []; |
|
38 | + if (!is_array($this->data)) { |
|
39 | + $this->data = []; |
|
40 | + } |
|
40 | 41 | |
41 | 42 | if (isset($data['error'])) { |
42 | 43 | $error = $this->module->exception($data['error']); |
@@ -36,7 +36,7 @@ |
||
36 | 36 | */ |
37 | 37 | public function getLabel() |
38 | 38 | { |
39 | - return $this->getName() . ' <small>(' . count($this->data) . ')</small>'; |
|
39 | + return $this->getName().' <small>('.count($this->data).')</small>'; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -135,9 +135,9 @@ |
||
135 | 135 | // 'audit/config', |
136 | 136 | |
137 | 137 | // These provide special functionality and get loaded to activate it |
138 | - 'audit/error', // Links the extra error reporting functions (`exception()` and `errorMessage()`) |
|
139 | - 'audit/extra', // Links the data functions (`data()`) |
|
140 | - 'audit/curl', // Links the curl tracking function (`curlBegin()`, `curlEnd()` and `curlExec()`) |
|
138 | + 'audit/error', // Links the extra error reporting functions (`exception()` and `errorMessage()`) |
|
139 | + 'audit/extra', // Links the data functions (`data()`) |
|
140 | + 'audit/curl', // Links the curl tracking function (`curlBegin()`, `curlEnd()` and `curlExec()`) |
|
141 | 141 | ]; |
142 | 142 | |
143 | 143 | /** |
@@ -239,8 +239,9 @@ discard block |
||
239 | 239 | */ |
240 | 240 | public function registerFunction($name, $callback) |
241 | 241 | { |
242 | - if (isset($this->_panelFunctions[$name])) |
|
243 | - throw new InvalidParamException("The '$name'-function has already been defined."); |
|
242 | + if (isset($this->_panelFunctions[$name])) { |
|
243 | + throw new InvalidParamException("The '$name'-function has already been defined."); |
|
244 | + } |
|
244 | 245 | |
245 | 246 | $this->_panelFunctions[$name] = $callback; |
246 | 247 | } |
@@ -260,8 +261,9 @@ discard block |
||
260 | 261 | */ |
261 | 262 | public function __call($name, $params) |
262 | 263 | { |
263 | - if (!isset($this->_panelFunctions[$name])) |
|
264 | - throw new \yii\base\InvalidCallException("Unknown panel function '$name'"); |
|
264 | + if (!isset($this->_panelFunctions[$name])) { |
|
265 | + throw new \yii\base\InvalidCallException("Unknown panel function '$name'"); |
|
266 | + } |
|
265 | 267 | |
266 | 268 | return call_user_func_array($this->_panelFunctions[$name], $params); |
267 | 269 | } |
@@ -333,13 +335,15 @@ discard block |
||
333 | 335 | public function getPanel($identifier) |
334 | 336 | { |
335 | 337 | $config = null; |
336 | - if (isset($this->panels[$identifier])) |
|
337 | - $config = $this->panels[$identifier]; |
|
338 | - elseif (isset($this->_corePanels[$identifier])) |
|
339 | - $config = $this->_corePanels[$identifier]; |
|
338 | + if (isset($this->panels[$identifier])) { |
|
339 | + $config = $this->panels[$identifier]; |
|
340 | + } elseif (isset($this->_corePanels[$identifier])) { |
|
341 | + $config = $this->_corePanels[$identifier]; |
|
342 | + } |
|
340 | 343 | |
341 | - if (!$config) |
|
342 | - throw new InvalidConfigException("'$identifier' is not a valid panel identifier"); |
|
344 | + if (!$config) { |
|
345 | + throw new InvalidConfigException("'$identifier' is not a valid panel identifier"); |
|
346 | + } |
|
343 | 347 | |
344 | 348 | if (is_array($config)) { |
345 | 349 | $config['module'] = $this; |
@@ -360,11 +364,11 @@ discard block |
||
360 | 364 | foreach ($this->panels as $key => $value) { |
361 | 365 | if (is_numeric($key)) { |
362 | 366 | // The $value contains the identifier of a core panel |
363 | - if (!isset($this->_corePanels[$value])) |
|
364 | - throw new InvalidConfigException("'$value' is not a valid panel identifier"); |
|
367 | + if (!isset($this->_corePanels[$value])) { |
|
368 | + throw new InvalidConfigException("'$value' is not a valid panel identifier"); |
|
369 | + } |
|
365 | 370 | $panels[$value] = $this->_corePanels[$value]; |
366 | - } |
|
367 | - else { |
|
371 | + } else { |
|
368 | 372 | // The key contains the identifier and the value is either a class name or a full array |
369 | 373 | $panels[$key] = is_string($value) ? ['class' => $value] : $value; |
370 | 374 | } |
@@ -374,10 +378,11 @@ discard block |
||
374 | 378 | // We now need one more iteration to add core classes to the panels added via the merge, if needed |
375 | 379 | array_walk($this->panels, function(&$value, $key) { |
376 | 380 | if (!isset($value['class'])) { |
377 | - if (isset($this->_corePanels[$key])) |
|
378 | - $value = ArrayHelper::merge($value, $this->_corePanels[$key]); |
|
379 | - else |
|
380 | - throw new InvalidConfigException("Invalid configuration for '$key'. No 'class' specified."); |
|
381 | + if (isset($this->_corePanels[$key])) { |
|
382 | + $value = ArrayHelper::merge($value, $this->_corePanels[$key]); |
|
383 | + } else { |
|
384 | + throw new InvalidConfigException("Invalid configuration for '$key'. No 'class' specified."); |
|
385 | + } |
|
381 | 386 | } |
382 | 387 | }); |
383 | 388 | } |
@@ -389,18 +394,21 @@ discard block |
||
389 | 394 | { |
390 | 395 | foreach (Yii::$app->modules as $name => $module) { |
391 | 396 | $class = null; |
392 | - if (is_string($module)) |
|
393 | - $class = $module; |
|
394 | - elseif (is_array($module)) { |
|
395 | - if (isset($module['class'])) |
|
396 | - $class = $module['class']; |
|
397 | - } else |
|
398 | - /** @var Module $module */ |
|
397 | + if (is_string($module)) { |
|
398 | + $class = $module; |
|
399 | + } elseif (is_array($module)) { |
|
400 | + if (isset($module['class'])) { |
|
401 | + $class = $module['class']; |
|
402 | + } |
|
403 | + } else { |
|
404 | + /** @var Module $module */ |
|
399 | 405 | $class = $module::className(); |
406 | + } |
|
400 | 407 | |
401 | 408 | $parts = explode('\\', $class); |
402 | - if ($class && strtolower(end($parts)) == 'audit') |
|
403 | - return $name; |
|
409 | + if ($class && strtolower(end($parts)) == 'audit') { |
|
410 | + return $name; |
|
411 | + } |
|
404 | 412 | } |
405 | 413 | return null; |
406 | 414 | } |
@@ -436,18 +444,21 @@ discard block |
||
436 | 444 | $len = strlen($compare); |
437 | 445 | if ($compare[$len - 1] == '*') { |
438 | 446 | $compare = rtrim($compare, '*'); |
439 | - if (substr($route, 0, $len - 1) === $compare) |
|
440 | - return true; |
|
447 | + if (substr($route, 0, $len - 1) === $compare) { |
|
448 | + return true; |
|
449 | + } |
|
441 | 450 | } |
442 | 451 | |
443 | 452 | if ($compare[0] == '*') { |
444 | 453 | $compare = ltrim($compare, '*'); |
445 | - if (substr($route, - ($len - 1)) === $compare) |
|
446 | - return true; |
|
454 | + if (substr($route, - ($len - 1)) === $compare) { |
|
455 | + return true; |
|
456 | + } |
|
447 | 457 | } |
448 | 458 | |
449 | - if ($route === $compare) |
|
450 | - return true; |
|
459 | + if ($route === $compare) { |
|
460 | + return true; |
|
461 | + } |
|
451 | 462 | } |
452 | 463 | return false; |
453 | 464 | } |
@@ -240,6 +240,9 @@ |
||
240 | 240 | $this->panels = $this->loadPanels(array_keys($this->panels)); |
241 | 241 | } |
242 | 242 | |
243 | + /** |
|
244 | + * @param ActionEvent $event |
|
245 | + */ |
|
243 | 246 | public function shouldTrack($event, $isError = false) |
244 | 247 | { |
245 | 248 | $trackActions = $isError ? $this->trackErrorActions : $this->trackActions; |
@@ -10,9 +10,9 @@ |
||
10 | 10 | |
11 | 11 | namespace bedezign\yii2\audit; |
12 | 12 | |
13 | +use Yii; |
|
13 | 14 | use bedezign\yii2\audit\components\panels\Panel; |
14 | 15 | use bedezign\yii2\audit\models\AuditEntry; |
15 | -use Yii; |
|
16 | 16 | use yii\base\ActionEvent; |
17 | 17 | use yii\base\Application; |
18 | 18 | use yii\base\InvalidConfigException; |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | // Things required to keep the module yii2-debug compatible |
177 | 177 | /* @see \yii\debug\Module::$traceLine (since 2.0.7) */ |
178 | 178 | public $traceLine = \yii\debug\Module::DEFAULT_IDE_TRACELINE; |
179 | - /* @see \yii\debug\Module::$tracePathMappings (since 2.1.6) */ |
|
179 | + /* @see \yii\debug\Module::$tracePathMappings (since 2.1.6) */ |
|
180 | 180 | public $tracePathMappings = []; |
181 | 181 | |
182 | 182 | /** |
@@ -350,9 +350,9 @@ discard block |
||
350 | 350 | // This code assumes the audit module is already loaded and can thus look for a derived instance |
351 | 351 | $loadedModules = Yii::$app->loadedModules; |
352 | 352 | foreach ($loadedModules as $module) { |
353 | - if ($module instanceof self) { |
|
354 | - return self::$_me = $module; |
|
355 | - } |
|
353 | + if ($module instanceof self) { |
|
354 | + return self::$_me = $module; |
|
355 | + } |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | // If we're still here, fall back onto the default implementation |
@@ -482,12 +482,12 @@ discard block |
||
482 | 482 | |
483 | 483 | // We now need one more iteration to add core classes to the panels added via the merge, if needed |
484 | 484 | array_walk($this->panels, function(&$value, $key) { |
485 | - if (!isset($value['class'])) { |
|
486 | - if (isset($this->_corePanels[$key])) |
|
487 | - $value = ArrayHelper::merge($value, $this->_corePanels[$key]); |
|
488 | - else |
|
489 | - throw new InvalidConfigException("Invalid configuration for '$key'. No 'class' specified."); |
|
490 | - } |
|
485 | + if (!isset($value['class'])) { |
|
486 | + if (isset($this->_corePanels[$key])) |
|
487 | + $value = ArrayHelper::merge($value, $this->_corePanels[$key]); |
|
488 | + else |
|
489 | + throw new InvalidConfigException("Invalid configuration for '$key'. No 'class' specified."); |
|
490 | + } |
|
491 | 491 | }); |
492 | 492 | } |
493 | 493 |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | { |
92 | 92 | $data = ArrayHelper::toArray($data); |
93 | 93 | if ($simplify) |
94 | - array_walk($data, function (&$value) { |
|
94 | + array_walk($data, function(&$value) { |
|
95 | 95 | if (is_array($value) && count($value) == 1) $value = reset($value); |
96 | 96 | }); |
97 | 97 | |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | if (is_object($value)) { |
168 | 168 | $class = get_class($value); |
169 | 169 | // By default we just mention the object type |
170 | - $args[$name] = 'Object(' . $class . ')'; |
|
170 | + $args[$name] = 'Object('.$class.')'; |
|
171 | 171 | |
172 | 172 | if ($recurseDepth > 0) { |
173 | 173 | // Make sure to limit the toArray to non recursive, it's much to easy to get stuck in an infinite loop |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | $hash = bcadd(sprintf('%u', crc32($data)), 0x100000000); |
199 | 199 | $str = ''; |
200 | 200 | do { |
201 | - $str = $map[bcmod($hash, 62)] . $str; |
|
201 | + $str = $map[bcmod($hash, 62)].$str; |
|
202 | 202 | $hash = bcdiv($hash, 62); |
203 | 203 | } while ($hash >= 1); |
204 | 204 | return $str; |
@@ -23,8 +23,9 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public static function serialize($data, $compact = true) |
25 | 25 | { |
26 | - if ($compact) |
|
27 | - $data = self::compact($data); |
|
26 | + if ($compact) { |
|
27 | + $data = self::compact($data); |
|
28 | + } |
|
28 | 29 | |
29 | 30 | $data = serialize($data); |
30 | 31 | $data = self::compress($data); |
@@ -39,19 +40,22 @@ discard block |
||
39 | 40 | */ |
40 | 41 | public static function unserialize($data) |
41 | 42 | { |
42 | - if (is_resource($data)) |
|
43 | - // For some databases (like Postgres) binary columns return as a resource, fetch the content first |
|
43 | + if (is_resource($data)) { |
|
44 | + // For some databases (like Postgres) binary columns return as a resource, fetch the content first |
|
44 | 45 | $data = stream_get_contents($data, -1, 0); |
46 | + } |
|
45 | 47 | |
46 | 48 | $originalData = $data; |
47 | 49 | $data = self::uncompress($data); |
48 | 50 | |
49 | - if ($data === false) |
|
50 | - $data = $originalData; |
|
51 | + if ($data === false) { |
|
52 | + $data = $originalData; |
|
53 | + } |
|
51 | 54 | |
52 | 55 | $data = @unserialize($data); |
53 | - if ($data === false) |
|
54 | - $data = $originalData; |
|
56 | + if ($data === false) { |
|
57 | + $data = $originalData; |
|
58 | + } |
|
55 | 59 | |
56 | 60 | return $data; |
57 | 61 | } |
@@ -63,8 +67,9 @@ discard block |
||
63 | 67 | */ |
64 | 68 | public static function compress($data) |
65 | 69 | { |
66 | - if (Audit::getInstance()->compressData) |
|
67 | - $data = gzcompress($data); |
|
70 | + if (Audit::getInstance()->compressData) { |
|
71 | + $data = gzcompress($data); |
|
72 | + } |
|
68 | 73 | return $data; |
69 | 74 | } |
70 | 75 | |
@@ -90,15 +95,17 @@ discard block |
||
90 | 95 | public static function compact($data, $simplify = false, $threshold = 512) |
91 | 96 | { |
92 | 97 | $data = ArrayHelper::toArray($data); |
93 | - if ($simplify) |
|
94 | - array_walk($data, function (&$value) { |
|
98 | + if ($simplify) { |
|
99 | + array_walk($data, function (&$value) { |
|
95 | 100 | if (is_array($value) && count($value) == 1) $value = reset($value); |
101 | + } |
|
96 | 102 | }); |
97 | 103 | |
98 | 104 | $tooBig = []; |
99 | - foreach ($data as $index => $value) |
|
100 | - if (strlen(serialize($value)) > $threshold) |
|
105 | + foreach ($data as $index => $value) { |
|
106 | + if (strlen(serialize($value)) > $threshold) |
|
101 | 107 | $tooBig[] = $index; |
108 | + } |
|
102 | 109 | |
103 | 110 | if (count($tooBig)) { |
104 | 111 | $data = array_diff_key($data, array_flip($tooBig)); |
@@ -117,8 +124,9 @@ discard block |
||
117 | 124 | { |
118 | 125 | $trace = debug_backtrace(); |
119 | 126 | array_pop($trace); // remove the last trace since it would be the entry script, not very useful |
120 | - if ($skip > 0) |
|
121 | - $trace = array_slice($trace, $skip); |
|
127 | + if ($skip > 0) { |
|
128 | + $trace = array_slice($trace, $skip); |
|
129 | + } |
|
122 | 130 | return self::cleanupTrace($trace); |
123 | 131 | } |
124 | 132 | |
@@ -130,8 +138,9 @@ discard block |
||
130 | 138 | */ |
131 | 139 | public static function cleanupTrace($trace) |
132 | 140 | { |
133 | - if (!is_array($trace)) |
|
134 | - return []; |
|
141 | + if (!is_array($trace)) { |
|
142 | + return []; |
|
143 | + } |
|
135 | 144 | |
136 | 145 | foreach ($trace as $n => $call) { |
137 | 146 | $call['file'] = isset($call['file']) ? $call['file'] : 'unknown'; |
@@ -140,14 +149,18 @@ discard block |
||
140 | 149 | $call['file'] = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $call['file']); |
141 | 150 | |
142 | 151 | // XDebug |
143 | - if (isset($call['params'])) unset($call['params']); |
|
152 | + if (isset($call['params'])) { |
|
153 | + unset($call['params']); |
|
154 | + } |
|
144 | 155 | |
145 | 156 | // Trace entry contains the class instance, also compact and include this |
146 | - if (isset($call['object'])) |
|
147 | - $call['object'] = current(self::cleanupTraceArguments([$call['object']])); |
|
157 | + if (isset($call['object'])) { |
|
158 | + $call['object'] = current(self::cleanupTraceArguments([$call['object']])); |
|
159 | + } |
|
148 | 160 | |
149 | - if (isset($call['args'])) |
|
150 | - $call['args'] = self::cleanupTraceArguments($call['args']); |
|
161 | + if (isset($call['args'])) { |
|
162 | + $call['args'] = self::cleanupTraceArguments($call['args']); |
|
163 | + } |
|
151 | 164 | |
152 | 165 | $trace[$n] = $call; |
153 | 166 | } |
@@ -176,10 +189,11 @@ discard block |
||
176 | 189 | $args[$name] = $object; |
177 | 190 | } |
178 | 191 | } else if (is_array($value)) { |
179 | - if ($recurseDepth > 0) |
|
180 | - $args[$name] = self::cleanupTraceArguments($value, $recurseDepth - 1); |
|
181 | - else |
|
182 | - $args[$name] = 'Array'; |
|
192 | + if ($recurseDepth > 0) { |
|
193 | + $args[$name] = self::cleanupTraceArguments($value, $recurseDepth - 1); |
|
194 | + } else { |
|
195 | + $args[$name] = 'Array'; |
|
196 | + } |
|
183 | 197 | } |
184 | 198 | } |
185 | 199 | return $args; |
@@ -212,8 +226,9 @@ discard block |
||
212 | 226 | public static function formatAsQuery($data) |
213 | 227 | { |
214 | 228 | $data = rawurldecode($data); |
215 | - if (!preg_match('/^([\w\d\-\[\]]+(=[^&]*)?(&[\w\d\-\[\]]+(=[^&]*)?)*)?$/', $data)) |
|
216 | - return null; |
|
229 | + if (!preg_match('/^([\w\d\-\[\]]+(=[^&]*)?(&[\w\d\-\[\]]+(=[^&]*)?)*)?$/', $data)) { |
|
230 | + return null; |
|
231 | + } |
|
217 | 232 | |
218 | 233 | $result = []; |
219 | 234 | parse_str($data, $result); |
@@ -241,8 +256,9 @@ discard block |
||
241 | 256 | $doc = new \DOMDocument('1.0'); |
242 | 257 | $doc->preserveWhiteSpace = false; |
243 | 258 | $doc->formatOutput = true; |
244 | - if (@$doc->loadXML($data)) |
|
245 | - return htmlentities($doc->saveXML(), ENT_COMPAT, 'UTF-8'); |
|
259 | + if (@$doc->loadXML($data)) { |
|
260 | + return htmlentities($doc->saveXML(), ENT_COMPAT, 'UTF-8'); |
|
261 | + } |
|
246 | 262 | return null; |
247 | 263 | } |
248 | 264 | |
@@ -253,14 +269,16 @@ discard block |
||
253 | 269 | */ |
254 | 270 | public static function formatAsHTML($data) |
255 | 271 | { |
256 | - if ($data == strip_tags($data) || strtolower(substr(ltrim($data), 0, 5)) == '<?xml') |
|
257 | - return null; |
|
272 | + if ($data == strip_tags($data) || strtolower(substr(ltrim($data), 0, 5)) == '<?xml') { |
|
273 | + return null; |
|
274 | + } |
|
258 | 275 | |
259 | 276 | $doc = new \DOMDocument('1.0'); |
260 | 277 | $doc->preserveWhiteSpace = false; |
261 | 278 | $doc->formatOutput = true; |
262 | - if (@$doc->loadHTML($data)) |
|
263 | - return htmlentities($doc->saveHTML(), ENT_COMPAT, 'UTF-8'); |
|
279 | + if (@$doc->loadHTML($data)) { |
|
280 | + return htmlentities($doc->saveHTML(), ENT_COMPAT, 'UTF-8'); |
|
281 | + } |
|
264 | 282 | return null; |
265 | 283 | } |
266 | 284 | } |
267 | 285 | \ No newline at end of file |