Issues (2963)

includes/html/graphs/device/ping_perf.inc.php (1 issue)

1
<?php
2
3
/*
4
 * LibreNMS
5
 *
6
 * Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
7
 *
8
 * This program is free software: you can redistribute it and/or modify it
9
 * under the terms of the GNU General Public License as published by the
10
 * Free Software Foundation, either version 3 of the License, or (at your
11
 * option) any later version.  Please see LICENSE.txt at the top level of
12
 * the source code distribution for details.
13
 */
14
15
use LibreNMS\Config;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Config. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
16
17
$scale_min = '0';
18
19
require 'includes/html/graphs/common.inc.php';
20
21
$rrd_filename = Rrd::name($device['hostname'], 'ping-perf');
22
23
$rrd_options .= ' DEF:ping=' . $rrd_filename . ':ping:AVERAGE';
24
$rrd_options .= " 'COMMENT:Milliseconds      Cur      Min     Max     Avg\\n'";
25
if (Config::get('applied_site_style') == 'dark') {
26
    $rrd_options .= ' LINE1.25:ping#63636d:Ping';
27
} else {
28
    $rrd_options .= ' LINE1.25:ping#36393d:Ping';
29
}
30
$rrd_options .= ' GPRINT:ping:LAST:%14.2lf  GPRINT:ping:AVERAGE:%6.2lf';
31
$rrd_options .= " GPRINT:ping:MAX:%6.2lf  'GPRINT:ping:AVERAGE:%6.2lf\\n'";
32
33
if ($_GET['previous'] == 'yes') {
34
    $rrd_options .= " COMMENT:' \\n'";
35
    $rrd_options .= " DEF:pingX=$rrd_filename:ping:AVERAGE:start=$prev_from:end=$from";
36
    $rrd_options .= " SHIFT:pingX:$period";
37
    $rrd_options .= " LINE1.25:pingX#CCCCCC:'Prev Ping'\t\t";
38
    $rrd_options .= ' GPRINT:pingX:AVERAGE:%6.2lf';
39
    $rrd_options .= " GPRINT:pingX:MAX:%6.2lf  'GPRINT:pingX:AVERAGE:%6.2lf\\n'";
40
}
41