Issues (2963)

app/Http/Controllers/Table/EditPortsController.php (1 issue)

1
<?php
2
/*
3
 * EditPortsController.php
4
 *
5
 * -Description-
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 <http://www.gnu.org/licenses/>.
19
 *
20
 * @package    LibreNMS
21
 * @link       http://librenms.org
22
 * @copyright  2021 Tony Murray
23
 * @author     Tony Murray <[email protected]>
24
 */
25
26
namespace App\Http\Controllers\Table;
27
28
class EditPortsController extends TableController
29
{
30
    public function rules()
31
    {
32
        return [
33
            'device_id' => 'required|int',
34
            'device_group' => 'nullable|int',
35
            'eventtype' => 'nullable|string',
36
        ];
37
    }
38
39
    public function searchFields($request)
40
    {
41
        return ['ifName', 'ifAlias', 'ifDescr'];
42
    }
43
44
    protected function sortFields($request)
45
    {
46
        return ['ifIndex', 'ifName', 'ifAdminStatus', 'ifOperStatus', 'ifSpeed', 'ifAlias'];
47
    }
48
49
    protected function baseQuery($request)
50
    {
51
        return \App\Models\Port::where('device_id', $request->get('device_id'))
52
            ->with('groups');
53
    }
54
55
    /**
56
     * @param  \App\Models\Port  $port
57
     * @return array
58
     */
59
    public function formatItem($port)
60
    {
61
        $is_port_bad = $port->ifAdminStatus != 'down' && $port->ifOperStatus != 'up';
62
        $do_we_care = ($port->ignore || $port->disabled) ? false : $is_port_bad;
63
        $out_of_sync = $do_we_care ? "class='red'" : '';
64
        $tune = $port->device->getAttrib('ifName_tune:' . $port->ifName) == 'true' ? 'checked' : '';
0 ignored issues
show
The method getAttrib() does not exist on null. ( Ignorable by Annotation )

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

64
        $tune = $port->device->/** @scrutinizer ignore-call */ getAttrib('ifName_tune:' . $port->ifName) == 'true' ? 'checked' : '';

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
66
        $port_group_options = '';
67
        foreach ($port->groups as $group) {
68
            /** @var \App\Models\PortGroup $group */
69
            $port_group_options .= '<option value="' . $group->id . '" selected>' . $group->name . '</option>';
70
        }
71
72
        return [
73
            'ifIndex'          => $port->ifIndex,
74
            'ifName'           => $port->getLabel(),
75
            'ifAdminStatus'    => $port->ifAdminStatus,
76
            'ifOperStatus'     => '<span id="operstatus_' . $port->port_id . '" ' . $out_of_sync . '>' . $port->ifOperStatus . '</span>',
77
            'disabled'         => '<input type="checkbox" class="disable-check" data-size="small" name="disabled_' . $port->port_id . '"' . ($port->disabled ? 'checked' : '') . '>
78
                               <input type="hidden" name="olddis_' . $port->port_id . '" value="' . ($port->disabled ? 1 : 0) . '"">',
79
            'ignore'           => '<input type="checkbox" class="ignore-check" data-size="small" name="ignore_' . $port->port_id . '"' . ($port->ignore ? 'checked' : '') . '>
80
                               <input type="hidden" name="oldign_' . $port->port_id . '" value="' . ($port->ignore ? 1 : 0) . '"">',
81
            'port_tune'        => '<input type="checkbox" name="override_config" data-attrib="ifName_tune:' . $port->ifName . '" data-device_id="' . $port->device_id . '" data-size="small" ' . $tune . '>',
82
            'ifAlias'          => '<div class="form-group"><input class="form-control input-sm" name="if-alias" data-device_id="' . $port->device_id . '" data-port_id="' . $port->port_id . '" data-ifName="' . $port->ifName . '" value="' . $port->ifAlias . '"><span class="form-control-feedback"><i class="fa" aria-hidden="true"></i></span></div>',
83
            'ifSpeed'          => '<div class="form-group has-feedback"><input type="text" pattern="[0-9]*" inputmode="numeric" class="form-control input-sm" name="if-speed" data-device_id="' . $port->device_id . '" data-port_id="' . $port->port_id . '" data-ifName="' . $port->ifName . '" value="' . $port->ifSpeed . '"><span class="form-control-feedback"><i class="fa" aria-hidden="true"></i></span></div>',
84
            'portGroup'        => '<div class="form-group has-feedback"><select class="input-sm port_group_select" name="port_group_' . $port->port_id . '[]"  data-port_id="' . $port->port_id . '" multiple>' . $port_group_options . '</select></div>',
85
        ];
86
    }
87
}
88