Skip to content

Commit a3ac1f7

Browse files
authored
Rector to PHP 8.0 (librenms#18445)
* Rector PHP8 * Some cleanups and missed ones * Fix bug found by rector (bad field name)
1 parent 40500fe commit a3ac1f7

File tree

132 files changed

+467
-918
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+467
-918
lines changed

LibreNMS/Alert/Template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function bladeTitle($data)
9393
$alert['alert'] = new AlertData($data['alert']);
9494
try {
9595
return Blade::render($data['title'], $alert);
96-
} catch (\Exception $e) {
96+
} catch (\Exception) {
9797
return $data['title'] ?: Blade::render('Template ' . $data['name'], $alert);
9898
}
9999
}

LibreNMS/Alert/Transport/Canopsis.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,12 @@ public function deliverAlert(array $alert_data): bool
2828
$ch->exchange_declare($exchange, AMQPExchangeType::TOPIC, false, true, false);
2929

3030
// Create Canopsis event, see: https://github.com/capensis/canopsis/wiki/Event-specification
31-
switch ($alert_data['severity']) {
32-
case 'ok':
33-
$state = 0;
34-
break;
35-
case 'warning':
36-
$state = 2;
37-
break;
38-
case 'critical':
39-
$state = 3;
40-
break;
41-
default:
42-
$state = 0;
43-
}
31+
$state = match ($alert_data['severity']) {
32+
'ok' => 0,
33+
'warning' => 2,
34+
'critical' => 3,
35+
default => 0,
36+
};
4437
$msg_body = [
4538
'timestamp' => time(),
4639
'connector' => 'librenms',

LibreNMS/Alert/Transport/Gotify.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,11 @@ public function deliverAlert(array $alert_data): bool
4343
* 4-7 + Sound = Warning
4444
* 8-10 + Vibration = Critical
4545
*/
46-
switch ($alert_data['severity']) {
47-
case 'critical':
48-
$priority = 8;
49-
break;
50-
case 'warning':
51-
$priority = 4;
52-
break;
53-
default:
54-
$priority = 0;
55-
}
46+
$priority = match ($alert_data['severity']) {
47+
'critical' => 8,
48+
'warning' => 4,
49+
default => 0,
50+
};
5651

5752
$data = [
5853
'title' => $alert_data['title'],

LibreNMS/Authentication/ActiveDirectoryAuthorizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function getRoles(string $username): array|false
149149
}
150150
}
151151
}
152-
} catch (AuthenticationException $e) {
152+
} catch (AuthenticationException) {
153153
}
154154
}
155155

LibreNMS/Authentication/SSOAuthorizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function authSSOProxyTrusted()
142142

143143
// No match, proxy is untrusted
144144
return false;
145-
} catch (InvalidIpException $e) {
145+
} catch (InvalidIpException) {
146146
// Webserver is talking nonsense (or, IPv10 has been deployed, or maybe something weird like a domain socket is in use?)
147147
return false;
148148
}

LibreNMS/Component.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public function createStatusLogEntry($component_id, $status, $message)
199199
{
200200
try {
201201
return ComponentStatusLog::create(['component_id' => $component_id, 'status' => $status, 'message' => $message])->id;
202-
} catch (\Exception $e) {
202+
} catch (\Exception) {
203203
Log::debug('Failed to create component status log');
204204
}
205205

LibreNMS/DB/Eloquent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static function isConnected(?string $name = null): bool
5858

5959
return true;
6060
}
61-
} catch (PDOException $e) {
61+
} catch (PDOException) {
6262
return false;
6363
}
6464

LibreNMS/Data/Graphing/GraphImage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
use LibreNMS\Enum\ImageFormat;
3030

31-
class GraphImage
31+
class GraphImage implements \Stringable
3232
{
3333
public function __construct(public readonly ImageFormat $format, public readonly string $title, public readonly string $data)
3434
{
@@ -54,7 +54,7 @@ public function contentType(): string
5454
return $this->format->contentType();
5555
}
5656

57-
public function __toString()
57+
public function __toString(): string
5858
{
5959
return $this->data;
6060
}

LibreNMS/Data/Graphing/GraphParameters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
use LibreNMS\Util\Clean;
3434
use LibreNMS\Util\Time;
3535

36-
class GraphParameters
36+
class GraphParameters implements \Stringable
3737
{
3838
public readonly array $visibleElements;
3939

LibreNMS/Data/Source/FpingResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
use LibreNMS\Exceptions\FpingUnparsableLine;
3434
use LibreNMS\RRD\RrdDefinition;
3535

36-
class FpingResponse
36+
class FpingResponse implements \Stringable
3737
{
3838
const SUCESS = 0;
3939
const UNREACHABLE = 1;
@@ -128,7 +128,7 @@ public function success(): bool
128128
return $this->exit_code == 0 && $this->loss < 100;
129129
}
130130

131-
public function __toString()
131+
public function __toString(): string
132132
{
133133
$str = "$this->host : xmt/rcv/%loss = $this->transmitted/$this->received/$this->loss%";
134134

0 commit comments

Comments
 (0)