Update Larastan (#14031)

* Update Larastan

* fix as many as I can

* update baseline for the remaining

* fix style

* Update Log::event phpdoc
This commit is contained in:
Tony Murray
2022-06-13 01:57:21 -05:00
committed by GitHub
parent 3e547de951
commit 9f749ae778
10 changed files with 78 additions and 170 deletions

View File

@@ -69,12 +69,9 @@ class Canopsis extends Transport
$msg_raw = json_encode($msg_body);
// Build routing key
$msg_rk = '';
if ($msg_body['source_type'] == 'resource') {
$msg_rk = $msg_rk . '.' . $msg_body['resource'];
} else {
$msg_rk = $msg_body['connector'] . '.' . $msg_body['connector_name'] . '.' . $msg_body['event_type'] . '.' . $msg_body['source_type'] . '.' . $msg_body['component'];
}
$msg_rk = '.' . $msg_body['resource'];
// non-resource key example
// $msg_rk = $msg_body['connector'] . '.' . $msg_body['connector_name'] . '.' . $msg_body['event_type'] . '.' . $msg_body['source_type'] . '.' . $msg_body['component'];
// Publish Event
$msg = new AMQPMessage($msg_raw, ['content_type' => 'application/json', 'delivery_mode' => 2]);

View File

@@ -65,7 +65,7 @@ class Googlechat extends Transport
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
Log::debug($code);
Log::debug("$code");
if ($code != 200) {
Log::error('Google Chat Transport Error');

View File

@@ -50,7 +50,7 @@ class Ceraos extends OS implements OSDiscovery, WirelessXpiDiscovery, WirelessFr
$device->version = $data[1]['MWRM-UNIT-MIB::genEquipMngSwIDUVersionsRunningVersion'] ?? null;
// update location lat/lng
if ($device->location && (! empty($multi_get_array[0]['MWRM-UNIT-MIB::genEquipUnitLatitude']) || ! empty($multi_get_array[0]['MWRM-UNIT-MIB::genEquipUnitLongitude']))) {
if ($device->location) {
$device->location->lat = $multi_get_array[0]['MWRM-UNIT-MIB::genEquipUnitLatitude'] ?? $device->location->lat;
$device->location->lng = $multi_get_array[0]['MWRM-UNIT-MIB::genEquipUnitLongitude'] ?? $device->location->lng;
$device->location->save();

View File

@@ -42,8 +42,8 @@ class UpsTrapOnBattery implements SnmptrapHandler
*/
public function handle(Device $device, Trap $trap)
{
$min_remaining = Str::before($trap->getOidData($trap->findOid('UPS-MIB::upsEstimatedMinutesRemaining')), ' ');
$sec_time = Str::before($trap->getOidData($trap->findOid('UPS-MIB::upsSecondsOnBattery')), ' ');
$min_remaining = (int) Str::before($trap->getOidData($trap->findOid('UPS-MIB::upsEstimatedMinutesRemaining')), ' ');
$sec_time = (int) Str::before($trap->getOidData($trap->findOid('UPS-MIB::upsSecondsOnBattery')), ' ');
Log::event("UPS running on battery for $sec_time seconds. Estimated $min_remaining minutes remaining", $device->device_id, 'trap', 5);
$sensor_remaining = $device->sensors()->where('sensor_index', '200')->where('sensor_type', 'rfc1628')->first();
if (! $sensor_remaining) {

View File

@@ -1,75 +0,0 @@
<?php
/**
* UpsTrapsOnBattery.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @link https://www.librenms.org
*
* @author TheGreatDoc
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use Illuminate\Support\Str;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class UpsTrapsOnBattery implements SnmptrapHandler
{
/**
* Handle snmptrap.
* Data is pre-parsed and delivered as a Trap.
*
* @param Device $device
* @param Trap $trap
* @return void
*/
public function handle(Device $device, Trap $trap)
{
$min_remaining = Str::before($trap->getOidData($trap->findOid('UPS-MIB::upsEstimatedMinutesRemaining.0')), ' ');
$sec_time = Str::before($trap->getOidData($trap->findOid('UPS-MIB::upsSecondsOnBattery.0')), ' ');
Log::event("UPS running on battery for $sec_time seconds. Estimated $min_remaining minutes remaining", $device->device_id, 'trap', 5);
$sensor_remaining = $device->sensors()->where('sensor_index', '200')->where('sensor_type', 'rfc1628')->first();
if (! $sensor_remaining) {
Log::warning("Snmptrap UpsTraps: Could not find matching sensor \'Estimated battery time remaining\' for device: " . $device->hostname);
return;
}
$sensor_remaining->sensor_current = $min_remaining / $sensor_remaining->sensor_divisor;
$sensor_remaining->save();
$sensor_time = $device->sensors()->where('sensor_index', '100')->where('sensor_type', 'rfc1628')->first();
if (! $sensor_time) {
Log::warning("Snmptrap UpsTraps: Could not find matching sensor \'Time on battery\' for device: " . $device->hostname);
return;
}
$sensor_time->sensor_current = $sec_time / $sensor_time->sensor_divisor;
$sensor_time->save();
$sensor_output = $device->sensors()->where('sensor_type', 'upsOutputSourceState')->first();
if (! $sensor_output) {
Log::warning("Snmptrap UpsTraps: Could not find matching sensor \'upsOutputSourceState\' for device: " . $device->hostname);
return;
}
$sensor_output->sensor_current = 5;
$sensor_output->save();
}
}

View File

@@ -37,7 +37,7 @@ class LogManager extends \Illuminate\Log\LogManager
* @param \App\Models\Device|int $device device array or device_id
* @param string $type brief category for this event. Examples: sensor, state, stp, system, temperature, interface
* @param int $severity 1: ok, 2: info, 3: notice, 4: warning, 5: critical, 0: unknown
* @param int $reference the id of the referenced entity. Supported types: interface
* @param int|string|null $reference the id of the referenced entity. Supported types: interface, bgpPeer
*/
public function event($text, $device = null, $type = null, $severity = Alert::INFO, $reference = null)
{

View File

@@ -63,8 +63,7 @@
"laravel/dusk": "^6.15",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^5.0",
"nunomaduro/larastan": "1.0.2",
"phpstan/phpstan": "1.4.2",
"nunomaduro/larastan": "^1.0",
"php-parallel-lint/php-parallel-lint": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-mockery": "^1.0",

52
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "aaf35a5b25ee679d27efef41a397db86",
"content-hash": "6ae226d7d02a5cc5c60bb124d43a4f6c",
"packages": [
{
"name": "amenadiel/jpgraph",
@@ -9855,16 +9855,16 @@
},
{
"name": "nunomaduro/larastan",
"version": "1.0.2",
"version": "1.0.3",
"source": {
"type": "git",
"url": "https://github.com/nunomaduro/larastan.git",
"reference": "3e0beabe8cf98373700f4d30cdfb2aa6badb9144"
"reference": "f5ce15319da184a5e461ef12c60489c15a9cf65b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nunomaduro/larastan/zipball/3e0beabe8cf98373700f4d30cdfb2aa6badb9144",
"reference": "3e0beabe8cf98373700f4d30cdfb2aa6badb9144",
"url": "https://api.github.com/repos/nunomaduro/larastan/zipball/f5ce15319da184a5e461ef12c60489c15a9cf65b",
"reference": "f5ce15319da184a5e461ef12c60489c15a9cf65b",
"shasum": ""
},
"require": {
@@ -9929,7 +9929,7 @@
],
"support": {
"issues": "https://github.com/nunomaduro/larastan/issues",
"source": "https://github.com/nunomaduro/larastan/tree/1.0.2"
"source": "https://github.com/nunomaduro/larastan/tree/1.0.3"
},
"funding": [
{
@@ -9949,7 +9949,7 @@
"type": "patreon"
}
],
"time": "2021-11-23T10:50:03+00:00"
"time": "2022-01-20T19:33:48+00:00"
},
{
"name": "phar-io/manifest",
@@ -10468,20 +10468,20 @@
},
{
"name": "phpstan/phpstan",
"version": "1.4.2",
"version": "1.7.12",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "1dd8f3e40bf7aa30031a75c65cece99220a161b8"
"reference": "32f10779d9cd88a9cbd972ec611a4148a3cbbc7e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/1dd8f3e40bf7aa30031a75c65cece99220a161b8",
"reference": "1dd8f3e40bf7aa30031a75c65cece99220a161b8",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/32f10779d9cd88a9cbd972ec611a4148a3cbbc7e",
"reference": "32f10779d9cd88a9cbd972ec611a4148a3cbbc7e",
"shasum": ""
},
"require": {
"php": "^7.1|^8.0"
"php": "^7.2|^8.0"
},
"conflict": {
"phpstan/phpstan-shim": "*"
@@ -10491,11 +10491,6 @@
"phpstan.phar"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"files": [
"bootstrap.php"
@@ -10508,7 +10503,7 @@
"description": "PHPStan - PHP Static Analysis Tool",
"support": {
"issues": "https://github.com/phpstan/phpstan/issues",
"source": "https://github.com/phpstan/phpstan/tree/1.4.2"
"source": "https://github.com/phpstan/phpstan/tree/1.7.12"
},
"funding": [
{
@@ -10528,7 +10523,7 @@
"type": "tidelift"
}
],
"time": "2022-01-18T16:09:11+00:00"
"time": "2022-06-09T12:39:36+00:00"
},
{
"name": "phpstan/phpstan-deprecation-rules",
@@ -10582,21 +10577,21 @@
},
{
"name": "phpstan/phpstan-mockery",
"version": "1.0.0",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-mockery.git",
"reference": "1767581e025d830d9288702761ad3cc7b72ecca4"
"reference": "245b17ccd00f04be3c6b9fc6645f63793b37b2ea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan-mockery/zipball/1767581e025d830d9288702761ad3cc7b72ecca4",
"reference": "1767581e025d830d9288702761ad3cc7b72ecca4",
"url": "https://api.github.com/repos/phpstan/phpstan-mockery/zipball/245b17ccd00f04be3c6b9fc6645f63793b37b2ea",
"reference": "245b17ccd00f04be3c6b9fc6645f63793b37b2ea",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0",
"phpstan/phpstan": "^1.0"
"php": "^7.2 || ^8.0",
"phpstan/phpstan": "^1.5.0"
},
"require-dev": {
"mockery/mockery": "^1.2.4",
@@ -10608,9 +10603,6 @@
},
"type": "phpstan-extension",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
},
"phpstan": {
"includes": [
"extension.neon"
@@ -10629,9 +10621,9 @@
"description": "PHPStan Mockery extension",
"support": {
"issues": "https://github.com/phpstan/phpstan-mockery/issues",
"source": "https://github.com/phpstan/phpstan-mockery/tree/1.0.0"
"source": "https://github.com/phpstan/phpstan-mockery/tree/1.1.0"
},
"time": "2021-09-20T16:03:58+00:00"
"time": "2022-05-09T13:12:35+00:00"
},
{
"name": "phpunit/php-code-coverage",

View File

@@ -127,7 +127,8 @@ return [
'OSPF-TRAP-MIB::ospfIfStateChange' => \LibreNMS\Snmptrap\Handlers\OspfIfStateChange::class,
'OSPF-TRAP-MIB::ospfNbrStateChange' => \LibreNMS\Snmptrap\Handlers\OspfNbrStateChange::class,
'OSPF-TRAP-MIB::ospfTxRetransmit' => \LibreNMS\Snmptrap\Handlers\OspfTxRetransmit::class,
'UPS-MIB::upsTraps.0.1' => \LibreNMS\Snmptrap\Handlers\UpsTrapsOnBattery::class,
'UPS-MIB::upsTrapOnBattery' => \LibreNMS\Snmptrap\Handlers\UpsTrapOnBattery::class,
'UPS-MIB::upsTraps.0.1' => \LibreNMS\Snmptrap\Handlers\UpsTrapOnBattery::class, // apparently bad/old UPS-MIB
'VEEAM-MIB::onBackupJobCompleted' => \LibreNMS\Snmptrap\Handlers\VeeamBackupJobCompleted::class,
'VEEAM-MIB::onVmBackupCompleted' => \LibreNMS\Snmptrap\Handlers\VeeamVmBackupCompleted::class,
'VEEAM-MIB::onLinuxFLRMountStarted' => \LibreNMS\Snmptrap\Handlers\VeeamLinuxFLRMountStarted::class,
@@ -145,6 +146,5 @@ return [
'VEEAM-MIB::onSobrOffloadFinished' => \LibreNMS\Snmptrap\Handlers\VeeamSobrOffloadFinished::class,
'VEEAM-MIB::onCdpRpoReport' => \LibreNMS\Snmptrap\Handlers\VeeamCdpRpoReport::class,
'HP-ICF-FAULT-FINDER-MIB::hpicfFaultFinderTrap' => \LibreNMS\Snmptrap\Handlers\HpFault::class,
'UPS-MIB::upsTrapOnBattery' => \LibreNMS\Snmptrap\Handlers\UpsTrapOnBattery::class,
],
];

View File

@@ -2545,11 +2545,6 @@ parameters:
count: 1
path: LibreNMS/Exceptions/AuthenticationException.php
-
message: "#^Parameter \\#2 \\$code of class LibreNMS\\\\Exceptions\\\\DatabaseConnectException constructor expects int, string given\\.$#"
count: 1
path: LibreNMS/Exceptions/DatabaseConnectException.php
-
message: "#^Method LibreNMS\\\\Exceptions\\\\DatabaseInconsistentException\\:\\:__construct\\(\\) has parameter \\$code with no type specified\\.$#"
count: 1
@@ -3930,11 +3925,6 @@ parameters:
count: 1
path: LibreNMS/OS/Ceraos.php
-
message: "#^Variable \\$multi_get_array in empty\\(\\) is never defined\\.$#"
count: 2
path: LibreNMS/OS/Ceraos.php
-
message: "#^Variable \\$multi_get_array on left side of \\?\\? is never defined\\.$#"
count: 2
@@ -4990,16 +4980,6 @@ parameters:
count: 1
path: LibreNMS/Snmptrap/Handlers/AdvaNetThresholdCrossingAlert.php
-
message: "#^Parameter \\#5 \\$reference of static method App\\\\Facades\\\\LogManager\\:\\:event\\(\\) expects int\\|null, string given\\.$#"
count: 1
path: LibreNMS/Snmptrap/Handlers/BgpBackwardTransition.php
-
message: "#^Parameter \\#5 \\$reference of static method App\\\\Facades\\\\LogManager\\:\\:event\\(\\) expects int\\|null, string given\\.$#"
count: 1
path: LibreNMS/Snmptrap/Handlers/BgpEstablished.php
-
message: "#^Method LibreNMS\\\\Snmptrap\\\\Handlers\\\\EquipStatusTrap\\:\\:getSeverity\\(\\) has no return type specified\\.$#"
count: 1
@@ -5370,36 +5350,6 @@ parameters:
count: 1
path: LibreNMS/Util/DynamicConfigItem.php
-
message: "#^Method LibreNMS\\\\Util\\\\DynamicConfigItem\\:\\:offsetExists\\(\\) has parameter \\$offset with no type specified\\.$#"
count: 1
path: LibreNMS/Util/DynamicConfigItem.php
-
message: "#^Method LibreNMS\\\\Util\\\\DynamicConfigItem\\:\\:offsetGet\\(\\) has no return type specified\\.$#"
count: 1
path: LibreNMS/Util/DynamicConfigItem.php
-
message: "#^Method LibreNMS\\\\Util\\\\DynamicConfigItem\\:\\:offsetGet\\(\\) has parameter \\$offset with no type specified\\.$#"
count: 1
path: LibreNMS/Util/DynamicConfigItem.php
-
message: "#^Method LibreNMS\\\\Util\\\\DynamicConfigItem\\:\\:offsetSet\\(\\) has parameter \\$offset with no type specified\\.$#"
count: 1
path: LibreNMS/Util/DynamicConfigItem.php
-
message: "#^Method LibreNMS\\\\Util\\\\DynamicConfigItem\\:\\:offsetSet\\(\\) has parameter \\$value with no type specified\\.$#"
count: 1
path: LibreNMS/Util/DynamicConfigItem.php
-
message: "#^Method LibreNMS\\\\Util\\\\DynamicConfigItem\\:\\:offsetUnset\\(\\) has parameter \\$offset with no type specified\\.$#"
count: 1
path: LibreNMS/Util/DynamicConfigItem.php
-
message: "#^Method LibreNMS\\\\Util\\\\DynamicConfigItem\\:\\:only\\(\\) has no return type specified\\.$#"
count: 1
@@ -6340,6 +6290,16 @@ parameters:
count: 1
path: LibreNMS/Util/Snmpsim.php
-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: LibreNMS/Util/Snmpsim.php
-
message: "#^Anonymous function should return non\\-empty\\-string but returns string\\.$#"
count: 1
path: LibreNMS/Util/StringHelpers.php
-
message: "#^Method LibreNMS\\\\Util\\\\StringHelpers\\:\\:niceCase\\(\\) has no return type specified\\.$#"
count: 1
@@ -8120,21 +8080,46 @@ parameters:
count: 1
path: app/Jobs/PingCheck.php
-
message: "#^Property App\\\\Jobs\\\\PingCheck\\:\\:\\$deferred is never written, only read\\.$#"
count: 1
path: app/Jobs/PingCheck.php
-
message: "#^Property App\\\\Jobs\\\\PingCheck\\:\\:\\$devices \\(Illuminate\\\\Database\\\\Eloquent\\\\Collection\\) in isset\\(\\) is not nullable\\.$#"
count: 1
path: app/Jobs/PingCheck.php
-
message: "#^Property App\\\\Jobs\\\\PingCheck\\:\\:\\$devices is never written, only read\\.$#"
count: 1
path: app/Jobs/PingCheck.php
-
message: "#^Property App\\\\Jobs\\\\PingCheck\\:\\:\\$groups is never read, only written\\.$#"
count: 1
path: app/Jobs/PingCheck.php
-
message: "#^Property App\\\\Jobs\\\\PingCheck\\:\\:\\$rrd_tags has no type specified\\.$#"
count: 1
path: app/Jobs/PingCheck.php
-
message: "#^Property App\\\\Jobs\\\\PingCheck\\:\\:\\$tiered is never written, only read\\.$#"
count: 1
path: app/Jobs/PingCheck.php
-
message: "#^Property App\\\\Jobs\\\\PingCheck\\:\\:\\$wait has no type specified\\.$#"
count: 1
path: app/Jobs/PingCheck.php
-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: app/Jobs/PingCheck.php
-
message: "#^Ternary operator condition is always true\\.$#"
count: 2
@@ -9360,6 +9345,16 @@ parameters:
count: 1
path: app/Providers/AppServiceProvider.php
-
message: "#^Result of && is always false\\.$#"
count: 1
path: app/Providers/CliServiceProvider.php
-
message: "#^Right side of && is always false\\.$#"
count: 1
path: app/Providers/CliServiceProvider.php
-
message: "#^Method App\\\\Providers\\\\DatastoreServiceProvider\\:\\:registerInflux\\(\\) has no return type specified\\.$#"
count: 1