Completed
Push — master ( 882cda...9e63b7 )
by Thomas
02:18 queued 47s
created

DebugBarTimeDataCollector   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 38
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getWidgets() 0 30 4
1
<?php
2
3
use DebugBar\DataCollector\TimeDataCollector;
4
5
class DebugBarTimeDataCollector extends TimeDataCollector
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
{
7
    /**
8
     * Add in a warning or danger notification if the request time is greater than the configured thresholds
9
     *
10
     * {@inheritDoc}
11
     */
12
    public function getWidgets()
13
    {
14
        $widgets = parent::getWidgets();
15
16
        $upperThreshold = DebugBar::config()->warn_request_time_seconds;
17
        $warningRatio = DebugBar::config()->warn_warning_ratio;
18
19
        // Can be disabled by setting the value to false
20
        if (!is_numeric($upperThreshold)) {
21
            return $widgets;
22
        }
23
24
        $widgets['time']['indicator'] = 'PhpDebugBar.DebugBar.WarnableRequestTimeIndicator';
25
        $widgets['time']['warn'] = 'ok';
26
        // Request duration rather than Request Duration
27
        $widgets['time']['tooltip'] = ucfirst(strtolower($widgets['time']['tooltip']));
28
29
        $warningThreshold = $upperThreshold * $warningRatio;
30
        if ($this->getRequestDuration() > $upperThreshold) {
31
            $widgets['time']['warn'] = 'danger';
32
            $widgets['time']['tooltip'] .= ' > ' . $upperThreshold . ' seconds';
33
        } elseif ($this->getRequestDuration() > $warningThreshold) {
34
            $widgets['time']['warn'] = 'warning';
35
            $widgets['time']['tooltip'] .= ' > ' . $warningThreshold . ' seconds';
36
        } else {
37
            $widgets['time']['tooltip'] .= ' < ' . $warningThreshold . ' seconds';
38
        }
39
40
        return $widgets;
41
    }
42
}
43