Completed
Pull Request — develop (#184)
by Tony
32:16
created

Device_processor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getRelation() 0 12 2
A getData() 0 4 1
A getHeaders() 0 8 2
A getRRDGraphDefinition() 0 4 1
A getRRDXportDefinition() 0 12 2
1
<?php
2
/**
3
 * BaseGraph.php
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 *
18
 * @package    LibreNMS
19
 * @link       http://librenms.org
20
 * @copyright  2016 Neil Lathwood
21
 * @author     Neil Lathwood <[email protected]>
22
 */
23
24
namespace App\Graphs;
25
26
use App\Data\RRD;
27
use App\Models\Processor;
28
use Illuminate\Database\Query\Builder;
29
30
class Device_processor extends BaseGraph
0 ignored issues
show
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
31
{
32
    protected function getRelation()
33
    {
34
        if ($this->hasIDs()) {
35
            return [
36
                'processors' => function (Builder $query) {
37
                    $query->whereIn('processor_id', $this->getIDs());
38
                },
39
            ];
40
        }
41
42
        return 'processors';
43
    }
44
45
    protected function getData()
46
    {
47
        return $this->device->processors;
48
    }
49
50
    protected function getHeaders()
51
    {
52
        $headers = [];
53
        foreach ($this->getData() as $proc) {
54
            $headers[] = $proc->getFormattedDescription();
55
        }
56
        return $headers;
57
    }
58
59
    protected function getRRDGraphDefinition()
60
    {
61
        // TODO: Implement getRRDGraphDefinition() method.
62
    }
63
64
    protected function getRRDXportDefinition()
65
    {
66
        $defs = '';
67
        foreach ($this->getData() as $proc) {
68
            /** @var Processor $proc */
69
            $id = $proc->hrDeviceIndex;
0 ignored issues
show
Bug introduced by
The property hrDeviceIndex does not seem to exist. Did you mean device?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
70
            $rrd_file = RRD::getFileName($this->device, array('processor', 'hr', $id));
71
            $defs .= "DEF:ds$id=$rrd_file:usage:AVERAGE \
72
                XPORT:ds$id:'".$proc->getFormattedDescription()."' ";
73
        }
74
        return $defs;
75
    }
76
}
77