Completed
Push — master ( e2c5a9...852a9e )
by Petrică
02:20
created

CpuAverageGauge   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
c 3
b 0
f 0
lcom 0
cbo 0
dl 0
loc 48
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSamplingPeriod() 0 4 1
A getPath() 0 4 1
A getValue() 0 11 3
A getLoadAverage() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Petrica
5
 * Date: 3/22/2016
6
 * Time: 23:03
7
 */
8
namespace Petrica\StatsdSystem\Gauge;
9
10
class CpuAverageGauge implements GaugeInterface
11
{
12
    /**
13
     * Report every 60 seconds
14
     * Load average is calculated every 1 minute
15
     *
16
     * @return int
17
     */
18
    public function getSamplingPeriod()
19
    {
20
        return 60;
21
    }
22
23
    /**
24
     * CPU average load path reported to statsd
25
     *
26
     * @return string
27
     */
28
    public function getPath()
29
    {
30
        return 'cpu.load.average';
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function getValue()
37
    {
38
        $load = $this->getLoadAverage();
39
40
        $value = null;
41
        if ($load && isset($load[0])) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $load of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
42
            $value = $load[0];
43
        }
44
45
        return $value;
46
    }
47
48
    /**
49
     * Return CPU load average
50
     *
51
     * @return array
52
     */
53
    protected function getLoadAverage()
54
    {
55
        return sys_getloadavg();
56
    }
57
}