Completed
Pull Request — master (#35)
by Robbie
02:08 queued 45s
created

DebugBarTimeDataCollector   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B getWidgets() 0 29 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
        $widgets['time']['warn'] = false;
16
        // Request duration rather than Request Duration
17
        $widgets['time']['tooltip'] = ucfirst(strtolower($widgets['time']['tooltip']));
18
19
        $upperThreshold = DebugBar::config()->warn_request_time_seconds;
20
        $warningRatio = DebugBar::config()->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
        $warningThreshold = $upperThreshold * $warningRatio;
28
        if ($this->getRequestDuration() > $warningThreshold) {
29
            $widgets['time']['indicator'] = 'PhpDebugBar.DebugBar.WarnableRequestTimeIndicator';
30
            $widgets['time']['warn'] = 'warning';
31
            $widgets['time']['warn_threshold_seconds'] = $warningThreshold;
32
        }
33
34
        if ($this->getRequestDuration() > $upperThreshold) {
35
            $widgets['time']['warn'] = 'danger';
36
            $widgets['time']['warn_threshold_seconds'] = $upperThreshold;
37
        }
38
39
        return $widgets;
40
    }
41
}
42