More cleanups (#12715)

* PHPDoc

* Replace Auth > Illuminate\Support\Facades\Auth

* Return inside when()

* use str_replace correct

* Misc

* dead code

* use int $port

* styleci
This commit is contained in:
Jellyfrog
2021-04-08 15:14:49 +02:00
committed by GitHub
parent c147be4505
commit edb36fd69d
24 changed files with 35 additions and 38 deletions

View File

@@ -37,7 +37,7 @@ class AlertDB
{
/**
* @param string $rule
* @param bool $query_builder
* @param mixed $query_builder
* @return bool|string
*/
public static function genSQL($rule, $query_builder = false)

View File

@@ -2,7 +2,7 @@
namespace LibreNMS\Authentication;
use Auth;
use Illuminate\Support\Facades\Auth;
use LibreNMS\Config;
use LibreNMS\Interfaces\Authentication\Authorizer;

View File

@@ -28,8 +28,8 @@ use App\Models\Bill;
use App\Models\Device;
use App\Models\Port;
use App\Models\User;
use Auth;
use DB;
use Illuminate\Support\Facades\Auth;
use LibreNMS\Config;
class PermissionsCache

View File

@@ -48,7 +48,7 @@ class Component
public function getComponentCount($device_id = null)
{
$counts = \App\Models\Component::query()->when($device_id, function ($query, $device_id) {
$query->where('device_id', $device_id);
return $query->where('device_id', $device_id);
})->selectRaw('type, count(*) as count')->groupBy('type')->pluck('count', 'type');
return $counts->isEmpty() ? false : $counts->all();

View File

@@ -180,7 +180,7 @@ class YamlDiscovery
* Helper function for dynamic discovery to search for data from pre_cached snmp data
*
* @param string $name The name of the field from the discovery data or just an oid
* @param string $index The index of the current sensor
* @param string|int $index The index of the current sensor
* @param array $discovery_data The discovery data for the current sensor
* @param array $pre_cache all pre-cached snmp data
* @param mixed $default The default value to return if data is not found

View File

@@ -114,7 +114,7 @@ class OS implements Module
{
$device = $os->getDevice();
$device->sysContact = snmp_get($os->getDeviceArray(), 'sysContact.0', '-Ovq', 'SNMPv2-MIB');
$device->sysContact = str_replace(['', '"', '\n', 'not set'], null, $device->sysContact);
$device->sysContact = str_replace(['', '"', '\n', 'not set'], '', $device->sysContact);
if (empty($device->sysContact)) {
$device->sysContact = null;
}

View File

@@ -94,9 +94,9 @@ class Timos extends OS implements MplsDiscovery, MplsPolling, WirelessPowerDisco
}
/**
* @param mixed $tmnxEnacpVal
* @param mixed $tmnxEncapVal
* @return string encapsulation
* see TIMETRA-TC-MIB::TmnxEncapVal
* @see TIMETRA-TC-MIB::TmnxEncapVal
*/
private function nokiaEncap($tmnxEncapVal)
{

View File

@@ -46,7 +46,7 @@ class Plugins
/**
* Array of plugin hooks
*
* @var array
* @var array|null
*/
private static $plugins = null;

View File

@@ -26,9 +26,9 @@ namespace LibreNMS\Util;
use App\Models\Device;
use App\Models\Port;
use Auth;
use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use LibreNMS\Config;
use Symfony\Component\HttpFoundation\ParameterBag;
@@ -496,7 +496,7 @@ class Url
// second, prefer the first two words of $feature (i.e. 'Red Hat' becomes 'redhat')
if (strpos($feature, ' ') !== false) {
$distro = Str::replaceFirst(' ', null, strtolower(trim($feature)));
$distro = Str::replaceFirst(' ', '', strtolower(trim($feature)));
$distro = Str::before($distro, ' ');
$possibilities[] = "$distro.svg";
$possibilities[] = "$distro.png";

View File

@@ -76,7 +76,7 @@ class Rrd extends BaseValidation
$validator->fail("$port doesn't appear to exist, rrdcached test failed");
}
} else {
$connection = @fsockopen($host, $port);
$connection = @fsockopen($host, (int) $port);
if (is_resource($connection)) {
fclose($connection);
} else {

View File

@@ -40,7 +40,7 @@ class NetCommand extends Controller
'query' => 'ip_or_hostname',
]);
ini_set('allow_url_fopen', 0);
ini_set('allow_url_fopen', '0');
switch ($request->get('cmd')) {
case 'whois':

View File

@@ -148,7 +148,7 @@ class TwoFactorController extends Controller
/**
* @param User $user
* @param string $token
* @param int $token
* @return true
* @throws AuthenticationException
*/

View File

@@ -200,10 +200,10 @@ class FdbTablesController extends TableController
return Ipv4Mac::where('ipv4_address', 'like', "%$ip%")
->when($device_id, function ($query) use ($device_id) {
$query->where('device_id', $device_id);
return $query->where('device_id', $device_id);
})
->when($port_id, function ($query) use ($port_id) {
$query->where('port_id', $port_id);
return $query->where('port_id', $port_id);
})
->pluck('mac_address');
}
@@ -219,10 +219,10 @@ class FdbTablesController extends TableController
return Vlan::where('vlan_vlan', $vlan)
->when($device_id, function ($query) use ($device_id) {
$query->where('device_id', $device_id);
return $query->where('device_id', $device_id);
})
->when($port_id, function ($query) use ($port_id) {
$query->whereIn('device_id', function ($query) use ($port_id) {
return $query->whereIn('device_id', function ($query) use ($port_id) {
$query->select('device_id')->from('ports')->where('port_id', $port_id);
});
})
@@ -240,10 +240,10 @@ class FdbTablesController extends TableController
return Port::where('ifAlias', 'like', "%$ifAlias%")
->when($device_id, function ($query) use ($device_id) {
$query->where('device_id', $device_id);
return $query->where('device_id', $device_id);
})
->when($port_id, function ($query) use ($port_id) {
$query->where('port_id', $port_id);
return $query->where('port_id', $port_id);
})
->pluck('port_id');
}

View File

@@ -63,7 +63,7 @@ class ComponentStatusController extends WidgetController
->groupBy('status')
->where('disabled', '!=', 0)
->when($data['device_group'], function ($query) use ($data) {
$query->inDeviceGroup($data['device_group']);
return $query->inDeviceGroup($data['device_group']);
})
->get()->pluck('total', 'status')->toArray();

View File

@@ -63,7 +63,7 @@ class GlobeController extends WidgetController
$query = Location::hasAccess($request->user())
->with($eager_load)
->when($data['device_group'], function ($query) use ($data) {
$query->inDeviceGroup($data['device_group']);
return $query->inDeviceGroup($data['device_group']);
});
/** @var Location $location */

View File

@@ -46,7 +46,6 @@ class ServerStatsController extends WidgetController
return $settings['title'];
}
/** @var Device $device */
$device = Device::hasAccess($request->user())->find($settings['device']);
if ($device) {
return $device->displayName() . ' Stats';
@@ -63,7 +62,6 @@ class ServerStatsController extends WidgetController
return $this->getSettingsView($request);
}
/** @var Device $device */
$device = Device::hasAccess($request->user())->find($data['device']);
if ($device) {
$data['cpu'] = $device->processors()->avg('processor_usage');

View File

@@ -137,7 +137,7 @@ class TopDevicesController extends WidgetController
->where('devices.last_polled', '>', Carbon::now()->subMinutes($settings['time_interval']))
->when($settings['device_group'], function ($query) use ($settings) {
/** @var Builder<\App\Models\DeviceRelatedModel> $query */
$query->inDeviceGroup($settings['device_group']);
return $query->inDeviceGroup($settings['device_group']);
});
}
@@ -211,6 +211,7 @@ class TopDevicesController extends WidgetController
$query = $this->deviceQuery()->orderBy('uptime', $sort)->limit($settings['device_count']);
$results = $query->get()->map(function ($device) {
/** @var Device $device */
return $this->standardRow($device, 'device_uptime', ['tab' => 'graphs', 'group' => 'system']);
});
@@ -225,6 +226,7 @@ class TopDevicesController extends WidgetController
$query = $this->deviceQuery()->orderBy('last_ping_timetaken', $sort)->limit($settings['device_count']);
$results = $query->get()->map(function ($device) {
/** @var Device $device */
return $this->standardRow($device, 'device_ping_perf', ['tab' => 'graphs', 'group' => 'poller']);
});
@@ -270,6 +272,7 @@ class TopDevicesController extends WidgetController
$query = $this->deviceQuery()->orderBy('last_polled_timetaken', $sort)->limit($settings['device_count']);
$results = $query->get()->map(function ($device) {
/** @var Device $device */
return $this->standardRow($device, 'device_poller_perf', ['tab' => 'graphs', 'group' => 'poller']);
});

View File

@@ -50,7 +50,7 @@ class Device extends BaseModel
/**
* Returns IP/Hostname where polling will be targeted to
*
* @param string $device hostname which will be triggered
* @param string|array $device hostname which will be triggered
* array $device associative array with device data
* @return string IP/Hostname to which Device polling is targeted
*/

View File

@@ -72,7 +72,7 @@ class TokenUserProvider extends LegacyUserProvider implements UserProvider
// missing user for existing token, create it assuming legacy auth_id
$api_token = ApiToken::where('token_hash', $credentials['api_token'])->first();
/** @var \App\Models\User */
/** @var \App\Models\User|null */
$user = $this->retrieveByLegacyId($api_token->user_id);
// update token user_id

View File

@@ -402,7 +402,7 @@ function delete_device($id)
*
* @param string $host dns name or ip address
* @param string $snmp_version If this is empty, try v2c,v3,v1. Otherwise, use this specific version.
* @param string $port the port to connect to for snmp
* @param int $port the port to connect to for snmp
* @param string $transport udp or tcp
* @param string $poller_group the poller group this device will belong to
* @param bool $force_add add even if the device isn't reachable
@@ -418,7 +418,7 @@ function delete_device($id)
* @throws InvalidPortAssocModeException The given port association mode was invalid
* @throws SnmpVersionUnsupportedException The given snmp version was invalid
*/
function addHost($host, $snmp_version = '', $port = '161', $transport = 'udp', $poller_group = '0', $force_add = false, $port_assoc_mode = 'ifIndex', $additional = [])
function addHost($host, $snmp_version = '', $port = 161, $transport = 'udp', $poller_group = '0', $force_add = false, $port_assoc_mode = 'ifIndex', $additional = [])
{
// Test Database Exists
if (host_exists($host)) {

View File

@@ -20,7 +20,7 @@
* @license GPL
*/
use Auth;
use Illuminate\Support\Facades\Auth;
use LibreNMS\Alert\AlertUtil;
use LibreNMS\Config;

View File

@@ -1168,7 +1168,7 @@ function generate_stacked_graphs($transparency = '88')
/**
* Parse AT time spec, does not handle the entire spec.
* @param string $time
* @param string|int $time
* @return int
*/
function parse_at_time($time)

View File

@@ -97,13 +97,9 @@ class OSModulesTest extends DBTestCase
$expected_data = $helper->getTestData();
$results = $helper->generateTestData($this->getSnmpsim(), true);
} catch (FileNotFoundException $e) {
$this->fail($e->getMessage());
return;
return $this->fail($e->getMessage());
} catch (InvalidModuleException $e) {
$this->fail($e->getMessage());
return;
return $this->fail($e->getMessage());
}
if (is_null($results)) {

View File

@@ -36,7 +36,7 @@ if (! getenv('SNMPSIM')) {
require $install_dir . '/includes/init.php';
chdir($install_dir);
ini_set('display_errors', 1);
ini_set('display_errors', '1');
//error_reporting(E_ALL & ~E_WARNING);
$snmpsim = new Snmpsim('127.1.6.2', 1162, null);