Skip to content

Commit

Permalink
style fixes and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
murrant committed Jun 12, 2024
1 parent d02725e commit 9a61d05
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 24 deletions.
2 changes: 1 addition & 1 deletion LibreNMS/Util/Rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public static function location($location)

public static function dslLineType(string $lineType): string
{
return match($lineType) {
return match ($lineType) {
'noChannel' => 'No Channel',
'fastOnly' => 'Fastpath',
'interleavedOnly' => 'Interleaved',
Expand Down
25 changes: 12 additions & 13 deletions app/Http/Controllers/Device/Tabs/PortsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function data(Device $device, Request $request): array
{
$tab = $request->segment(4);
$this->detail = empty($tab) || $tab == 'detail';
$data = match($tab) {
$data = match ($tab) {
'links' => $this->linksData($device),
'xdsl' => $this->xdslData($device),
default => $this->portData($device, $request),
Expand All @@ -73,6 +73,7 @@ public function data(Device $device, Request $request): array
$ignore = $request->input('ignore');
$admin = $request->input('admin') == 'any';
$status = $request->input('status') == 'up';

return array_merge([
'tab' => $tab,
'details' => empty($tab) || $tab == 'detail',
Expand Down Expand Up @@ -127,7 +128,7 @@ private function portData(Device $device, Request $request): array
]);
$perPage = $request->input('perPage', 15);
$sort = $request->input('sort', 'port');
$orderBy = match($sort) {
$orderBy = match ($sort) {
'traffic' => \DB::raw('ports.ifInOctets_rate + ports.ifOutOctets_rate'),
'speed' => 'ifSpeed',
'media' => 'ifType',
Expand All @@ -146,10 +147,10 @@ private function portData(Device $device, Request $request): array

$ports = $device->ports()
->isNotDeleted()
->when(! $request->input('disabled'), fn(Builder $q, $disabled) => $q->where('disabled', 0))
->when(! $request->input('ignore'), fn(Builder $q, $disabled) => $q->where('ignore', 0))
->when($request->input('admin') != 'any', fn(Builder $q, $admin) => $q->where('ifAdminStatus', $request->input('admin', 'up')))
->when($request->input('status', 'any') != 'any', fn(Builder $q, $admin) => $q->where('ifOperStatus', $request->input('status')))
->when(! $request->input('disabled'), fn (Builder $q, $disabled) => $q->where('disabled', 0))
->when(! $request->input('ignore'), fn (Builder $q, $disabled) => $q->where('ignore', 0))
->when($request->input('admin') != 'any', fn (Builder $q, $admin) => $q->where('ifAdminStatus', $request->input('admin', 'up')))
->when($request->input('status', 'any') != 'any', fn (Builder $q, $admin) => $q->where('ifOperStatus', $request->input('status')))
->orderBy($orderBy, $order)
->hasAccess(Auth::user())->with($relationships)
->paginate($perPage);
Expand All @@ -166,11 +167,11 @@ private function portData(Device $device, Request $request): array
],
];

$data['neighbors'] = $ports->keyBy('port_id')->map(fn($port) => $this->findPortNeighbors($port));
$data['neighbors'] = $ports->keyBy('port_id')->map(fn ($port) => $this->findPortNeighbors($port));
if ($this->detail) {
$data['neighbor_ports'] = Port::with('device')
->hasAccess(Auth::user())
->whereIn('port_id', $data['neighbors']->map(fn($a) => array_keys($a))->flatten())
->whereIn('port_id', $data['neighbors']->map(fn ($a) => array_keys($a))->flatten())
->get()->keyBy('port_id');
}

Expand Down Expand Up @@ -204,7 +205,7 @@ public function findPortNeighbors(Port $port): array
// IPv4 + IPv6 subnet if detailed
// fa-arrow-right green portlink on devicelink
if ($port->ipv4Networks->isNotEmpty()) {
$ids = $port->ipv4Networks->map(fn($net) => $net->ipv4->pluck('port_id'))->flatten();
$ids = $port->ipv4Networks->map(fn ($net) => $net->ipv4->pluck('port_id'))->flatten();
foreach ($ids as $port_id) {
if ($port_id !== $port->port_id) {
$this->addPortNeighbor($neighbors, 'ipv4_network', $port_id);
Expand All @@ -213,7 +214,7 @@ public function findPortNeighbors(Port $port): array
}

if ($port->ipv6Networks->isNotEmpty()) {
$ids = $port->ipv6Networks->map(fn($net) => $net->ipv6->pluck('port_id'))->flatten();
$ids = $port->ipv6Networks->map(fn ($net) => $net->ipv6->pluck('port_id'))->flatten();
foreach ($ids as $port_id) {
if ($port_id !== $port->port_id) {
$this->addPortNeighbor($neighbors, 'ipv6_network', $port_id);
Expand All @@ -237,7 +238,7 @@ public function findPortNeighbors(Port $port): array
// fa-expand portlink: local is low port
// fa-compress portlink: local is high portPort
$stacks = \DB::table('ports_stack')->where('device_id', $port->device_id)
->where(fn($q) => $q->where('port_id_high', $port->port_id)->orWhere('port_id_low', $port->port_id))->get();
->where(fn ($q) => $q->where('port_id_high', $port->port_id)->orWhere('port_id_low', $port->port_id))->get();
foreach ($stacks as $stack) {
if ($stack->port_id_low) {
$this->addPortNeighbor($neighbors, 'stack_low', $stack->port_id_low);
Expand All @@ -258,7 +259,6 @@ public function findPortNeighbors(Port $port): array
}
}


return $neighbors;
}

Expand Down Expand Up @@ -291,7 +291,6 @@ private function linksData(Device $device): array
return ['links' => $device->links];
}


private function getTabs(Device $device): array
{
$tabs = [
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/DeviceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\Controllers;

use App\Facades\DeviceCache;
use App\Http\Controllers\Device\Tabs\EmptyTab;
use App\Models\Device;
use App\Models\Vminfo;
use Carbon\Carbon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@

require 'includes/html/print-graphrow.inc.php';

// include("includes/html/print-interface-graphs.inc.php");
echo '
</td>
</tr>';
Expand Down
8 changes: 0 additions & 8 deletions phpstan-baseline-deprecated.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4072,14 +4072,6 @@ parameters:
count: 1
path: includes/html/print-graph-alerts.inc.php

-
message: """
#^Call to deprecated function dbFetchRows\\(\\)\\:
Please use Eloquent instead; https\\://laravel\\.com/docs/eloquent$#
"""
count: 2
path: includes/html/print-interface-adsl.inc.php

-
message: """
#^Call to deprecated function dbFetchCell\\(\\)\\:
Expand Down

0 comments on commit 9a61d05

Please sign in to comment.