TimeDataCollector   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A getWidgets() 0 29 4
1
<?php
2
3
namespace LeKoala\DebugBar\Collector;
4
5
use DebugBar\DataCollector\TimeDataCollector as BaseTimeDataCollector;
6
use LeKoala\DebugBar\DebugBar;
7
8
class TimeDataCollector extends BaseTimeDataCollector
9
{
10
    /**
11
     * Add in a warning or danger notification if the request time is greater than the configured thresholds
12
     *
13
     * {@inheritDoc}
14
     */
15
    public function getWidgets()
16
    {
17
        $widgets = parent::getWidgets();
18
19
        $upperThreshold = DebugBar::config()->get('warn_request_time_seconds');
20
        $warningRatio = DebugBar::config()->get('warn_warning_ratio');
21
22
        // Can be disabled by setting the value to false
23
        if (!is_numeric($upperThreshold)) {
24
            return $widgets;
25
        }
26
27
        $widgets['time']['indicator'] = 'PhpDebugBar.DebugBar.WarnableRequestTimeIndicator';
28
        $widgets['time']['warn'] = 'ok';
29
        // Request duration rather than Request Duration
30
        $widgets['time']['tooltip'] = ucfirst(strtolower($widgets['time']['tooltip']));
31
32
        $warningThreshold = $upperThreshold * $warningRatio;
33
        if ($this->getRequestDuration() > $upperThreshold) {
34
            $widgets['time']['warn'] = 'danger';
35
            $widgets['time']['tooltip'] .= ' > ' . $upperThreshold . ' seconds';
36
        } elseif ($this->getRequestDuration() > $warningThreshold) {
37
            $widgets['time']['warn'] = 'warning';
38
            $widgets['time']['tooltip'] .= ' > ' . $warningThreshold . ' seconds';
39
        } else {
40
            $widgets['time']['tooltip'] .= ' < ' . $warningThreshold . ' seconds';
41
        }
42
43
        return $widgets;
44
    }
45
}
46