Issues (2963)

includes/polling/ntp.inc.php (1 issue)

1
<?php
2
/*
3
 * LibreNMS module to capture NTP statistics
4
 *
5
 * Copyright (c) 2016 Aaron Daniels <[email protected]>
6
 *
7
 * This program is free software: you can redistribute it and/or modify it
8
 * under the terms of the GNU General Public License as published by the
9
 * Free Software Foundation, either version 3 of the License, or (at your
10
 * option) any later version.  Please see LICENSE.txt at the top level of
11
 * the source code distribution for details.
12
 *
13
 * This module will display NTP details from various device types.
14
 * To display, modules must create rrd's named: ntp-%PEER%.rrd with the following DS':
15
 *      DS:stratum:GAUGE:'.\LibreNMS\Config::get('rrd.heartbeat').':0:U
16
 *      DS:offset:GAUGE:'.\LibreNMS\Config::get('rrd.heartbeat').':0:U
17
 *      DS:delay:GAUGE:'.\LibreNMS\Config::get('rrd.heartbeat').':0:U
18
 *      DS:dispersion:GAUGE:'.\LibreNMS\Config::get('rrd.heartbeat').':0:U
19
 */
20
21
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...
22
23
if (file_exists(Config::get('install_dir') . "/includes/polling/ntp/{$device['os_group']}.inc.php")) {
24
    include Config::get('install_dir') . "/includes/polling/ntp/{$device['os_group']}.inc.php";
25
}
26
27
if ($device['os'] == 'awplus') {
28
    include 'includes/polling/ntp/awplus.inc.php';
29
}
30
31
unset(
32
    $cntpPeersVarEntry,
33
    $atNtpAssociationEntry
34
);
35