Issues (2963)

LibreNMS/Services.php (1 issue)

1
<?php
2
/*
3
 * Services.php
4
 *
5
 * Nagios services helper
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
 *
20
 * @package    LibreNMS
21
 * @link       https://www.librenms.org
22
 * @copyright  2020 Tony Murray
23
 * @author     Tony Murray <[email protected]>
24
 */
25
26
namespace LibreNMS;
27
28
class Services
29
{
30
    /**
31
     * List all available services from nagios plugins directory
32
     *
33
     * @return array
34
     */
35
    public static function list()
36
    {
37
        $services = [];
38
        if (is_dir(Config::get('nagios_plugins'))) {
0 ignored issues
show
It seems like LibreNMS\Config::get('nagios_plugins') can also be of type null; however, parameter $filename of is_dir() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
        if (is_dir(/** @scrutinizer ignore-type */ Config::get('nagios_plugins'))) {
Loading history...
39
            foreach (scandir(Config::get('nagios_plugins')) as $file) {
40
                if (substr($file, 0, 6) === 'check_') {
41
                    $services[] = substr($file, 6);
42
                }
43
            }
44
        }
45
46
        return $services;
47
    }
48
}
49