Fix some lint issues (#14962)

This commit is contained in:
Tony Murray
2023-04-15 09:02:41 -05:00
committed by GitHub
parent a70d10af19
commit 52f5f10231
15 changed files with 38 additions and 42 deletions

View File

@@ -194,7 +194,7 @@ class TwoFactor
((ord($hash[$offset + 2]) & 0xFF) << 8) | ((ord($hash[$offset + 2]) & 0xFF) << 8) |
(ord($hash[$offset + 3]) & 0xFF)) % pow(10, self::OTP_SIZE); (ord($hash[$offset + 3]) & 0xFF)) % pow(10, self::OTP_SIZE);
return str_pad($truncated, self::OTP_SIZE, '0', STR_PAD_LEFT); return str_pad("$truncated", self::OTP_SIZE, '0', STR_PAD_LEFT);
} }
/** /**

View File

@@ -236,7 +236,7 @@ class Processor extends Model implements DiscoveryModule, PollerModule, Discover
private static function processData($data, $precision) private static function processData($data, $precision)
{ {
preg_match('/([0-9]{1,5}(\.[0-9]+)?)/', $data, $matches); preg_match('/([0-9]{1,5}(\.[0-9]+)?)/', $data, $matches);
$value = $matches[1]; $value = (float) $matches[1];
if ($precision < 0) { if ($precision < 0) {
// idle value, subtract from 100 // idle value, subtract from 100

View File

@@ -238,7 +238,7 @@ class YamlDiscovery
return current($pre_cache[$name]); return current($pre_cache[$name]);
} elseif (isset($sub_indexes[$sub_index])) { } elseif (isset($sub_indexes[$sub_index])) {
if ($sub_index_end) { if ($sub_index_end) {
$multi_sub_index = implode('.', array_slice($sub_indexes, $sub_index, $sub_index_end)); $multi_sub_index = implode('.', array_slice($sub_indexes, (int) $sub_index, (int) $sub_index_end));
if (isset($pre_cache[$name][$multi_sub_index][$name])) { if (isset($pre_cache[$name][$multi_sub_index][$name])) {
return $pre_cache[$name][$multi_sub_index][$name]; return $pre_cache[$name][$multi_sub_index][$name];
} }

View File

@@ -56,7 +56,7 @@ class MaximumExecutionTimeExceeded extends \Exception implements UpgradeableExce
public function render(\Illuminate\Http\Request $request) public function render(\Illuminate\Http\Request $request)
{ {
$title = preg_match('/ (\d+) /', $this->message, $matches) $title = preg_match('/ (\d+) /', $this->message, $matches)
? trans_choice('exceptions.maximum_execution_time_exceeded.title', $matches[1], ['seconds' => $matches[1]]) ? trans_choice('exceptions.maximum_execution_time_exceeded.title', (int) $matches[1], ['seconds' => (int) $matches[1]])
: $this->getMessage(); : $this->getMessage();
$message = trans('exceptions.maximum_execution_time_exceeded.message'); $message = trans('exceptions.maximum_execution_time_exceeded.message');

View File

@@ -29,6 +29,7 @@ use App\Http\Controllers\PaginatedAjaxController;
use Illuminate\Contracts\Pagination\Paginator; use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Str; use Illuminate\Support\Str;
abstract class SelectController extends PaginatedAjaxController abstract class SelectController extends PaginatedAjaxController
@@ -64,7 +65,7 @@ abstract class SelectController extends PaginatedAjaxController
} }
/** /**
* @param Paginator $paginator * @param Paginator|Collection $paginator
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */
protected function formatResponse($paginator) protected function formatResponse($paginator)

View File

@@ -61,7 +61,7 @@ class CustomersController extends TableController
} }
/** /**
* @param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator * @param \Illuminate\Contracts\Pagination\LengthAwarePaginator&\Countable $paginator
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */
protected function formatResponse($paginator) protected function formatResponse($paginator)

View File

@@ -77,7 +77,7 @@ abstract class TableController extends PaginatedAjaxController
} }
/** /**
* @param LengthAwarePaginator $paginator * @param LengthAwarePaginator|\Countable $paginator
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */
protected function formatResponse($paginator) protected function formatResponse($paginator)

View File

@@ -11,7 +11,7 @@ class Kernel extends HttpKernel
* *
* These middleware are run during every request to your application. * These middleware are run during every request to your application.
* *
* @var array * @var array<int, string>
*/ */
protected $middleware = [ protected $middleware = [
// \App\Http\Middleware\TrustHosts::class, // \App\Http\Middleware\TrustHosts::class,
@@ -26,7 +26,7 @@ class Kernel extends HttpKernel
/** /**
* The application's route middleware groups. * The application's route middleware groups.
* *
* @var array * @var array<string, array<int, string>>
*/ */
protected $middlewareGroups = [ protected $middlewareGroups = [
'web' => [ 'web' => [
@@ -65,7 +65,7 @@ class Kernel extends HttpKernel
* *
* These middleware may be assigned to groups or used individually. * These middleware may be assigned to groups or used individually.
* *
* @var array * @var array<string, string>
*/ */
protected $routeMiddleware = [ protected $routeMiddleware = [
'authenticate' => \App\Http\Middleware\Authenticate::class, 'authenticate' => \App\Http\Middleware\Authenticate::class,

View File

@@ -9,7 +9,7 @@ class EncryptCookies extends Middleware
/** /**
* The names of the cookies that should not be encrypted. * The names of the cookies that should not be encrypted.
* *
* @var array * @var array<int, string>
*/ */
protected $except = [ protected $except = [
// //

View File

@@ -9,7 +9,7 @@ class PreventRequestsDuringMaintenance extends Middleware
/** /**
* The URIs that should be reachable while maintenance mode is enabled. * The URIs that should be reachable while maintenance mode is enabled.
* *
* @var array * @var array<int, string>
*/ */
protected $except = [ protected $except = [
// //

View File

@@ -9,7 +9,7 @@ class VerifyCsrfToken extends Middleware
/** /**
* The URIs that should be excluded from CSRF verification. * The URIs that should be excluded from CSRF verification.
* *
* @var array * @var array<int, string>
*/ */
protected $except = [ protected $except = [
'/auth/*/callback', '/auth/*/callback',

View File

@@ -9,7 +9,7 @@ class EventServiceProvider extends ServiceProvider
/** /**
* The event listener mappings for the application. * The event listener mappings for the application.
* *
* @var array * @var array<string, array<int, string>>
*/ */
protected $listen = [ protected $listen = [
\Illuminate\Auth\Events\Login::class => ['App\Listeners\AuthEventListener@login'], \Illuminate\Auth\Events\Login::class => ['App\Listeners\AuthEventListener@login'],

View File

@@ -20,8 +20,8 @@ class MigrateWidgetIds extends Migration
$this->map = DB::table('widgets')->pluck('widget', 'widget_id'); $this->map = DB::table('widgets')->pluck('widget', 'widget_id');
UserWidget::query()->chunk(1000, function (Collection $widgets) { UserWidget::query()->chunk(1000, function (Collection $widgets) {
$widgets->each(function ($widget) { $widgets->each(function (UserWidget $widget) {
$widget->widget = $this->map[$widget->widget_id]; $widget->widget = $this->map[$widget->getAttribute('widget_id')];
$widget->save(); $widget->save();
}); });
}); });

View File

@@ -1405,11 +1405,6 @@ parameters:
count: 1 count: 1
path: LibreNMS/Authentication/SSOAuthorizer.php path: LibreNMS/Authentication/SSOAuthorizer.php
-
message: "#^Parameter \\#1 \\$string of function str_pad expects string, int given\\.$#"
count: 1
path: LibreNMS/Authentication/TwoFactor.php
- -
message: "#^Property LibreNMS\\\\Authentication\\\\TwoFactor\\:\\:\\$base32 has no type specified\\.$#" message: "#^Property LibreNMS\\\\Authentication\\\\TwoFactor\\:\\:\\$base32 has no type specified\\.$#"
count: 1 count: 1

View File

@@ -139,9 +139,9 @@ class AuthSSOTest extends DBTestCase
// Retrieve it and validate // Retrieve it and validate
$dbuser = $a->getUser($a->getUserid($user)); $dbuser = $a->getUser($a->getUserid($user));
$this->assertTrue($a->authSSOGetAttr(Config::get('sso.realname_attr')) === $dbuser['realname']); $this->assertSame($dbuser['realname'], $a->authSSOGetAttr(Config::get('sso.realname_attr')));
$this->assertTrue($dbuser['level'] == -1); $this->assertTrue($dbuser['level'] == -1);
$this->assertTrue($a->authSSOGetAttr(Config::get('sso.email_attr')) === $dbuser['email']); $this->assertSame($dbuser['email'], $a->authSSOGetAttr(Config::get('sso.email_attr')));
// Change a few things and reauth // Change a few things and reauth
$_SERVER['mail'] = 'test@example.net'; $_SERVER['mail'] = 'test@example.net';
@@ -176,9 +176,9 @@ class AuthSSOTest extends DBTestCase
// Retrieve it and validate the update persisted // Retrieve it and validate the update persisted
$dbuser = $a->getUser($a->getUserid($user)); $dbuser = $a->getUser($a->getUserid($user));
$this->assertTrue($a->authSSOGetAttr(Config::get('sso.realname_attr')) === $dbuser['realname']); $this->assertSame($dbuser['realname'], $a->authSSOGetAttr(Config::get('sso.realname_attr')));
$this->assertTrue($dbuser['level'] == 10); $this->assertTrue($dbuser['level'] == 10);
$this->assertTrue($a->authSSOGetAttr(Config::get('sso.email_attr')) === $dbuser['email']); $this->assertSame($dbuser['email'], $a->authSSOGetAttr(Config::get('sso.email_attr')));
} }
// Check some invalid authentication modes // Check some invalid authentication modes
@@ -356,12 +356,12 @@ class AuthSSOTest extends DBTestCase
//Integer //Integer
Config::set('sso.level_attr', 'level'); Config::set('sso.level_attr', 'level');
$_SERVER['level'] = 9; $_SERVER['level'] = 9;
$this->assertTrue($a->authSSOCalculateLevel() === 9); $this->assertSame(9, $a->authSSOCalculateLevel());
//String //String
Config::set('sso.level_attr', 'level'); Config::set('sso.level_attr', 'level');
$_SERVER['level'] = '9'; $_SERVER['level'] = '9';
$this->assertTrue($a->authSSOCalculateLevel() === 9); $this->assertSame(9, $a->authSSOCalculateLevel());
//Invalid String //Invalid String
Config::set('sso.level_attr', 'level'); Config::set('sso.level_attr', 'level');
@@ -404,68 +404,68 @@ class AuthSSOTest extends DBTestCase
$_SERVER['member'] = 'librenms-admins;librenms-readers;librenms-billingcontacts;unrelatedgroup;confluence-admins'; $_SERVER['member'] = 'librenms-admins;librenms-readers;librenms-billingcontacts;unrelatedgroup;confluence-admins';
// Valid options // Valid options
$this->assertTrue($a->authSSOParseGroups() === 10); $this->assertSame(10, $a->authSSOParseGroups());
// No match // No match
$_SERVER['member'] = 'confluence-admins'; $_SERVER['member'] = 'confluence-admins';
$this->assertTrue($a->authSSOParseGroups() === 0); $this->assertSame(0, $a->authSSOParseGroups());
// Delimiter only // Delimiter only
$_SERVER['member'] = ';;;;'; $_SERVER['member'] = ';;;;';
$this->assertTrue($a->authSSOParseGroups() === 0); $this->assertSame(0, $a->authSSOParseGroups());
// Empty // Empty
$_SERVER['member'] = ''; $_SERVER['member'] = '';
$this->assertTrue($a->authSSOParseGroups() === 0); $this->assertSame(0, $a->authSSOParseGroups());
// Empty with default access level // Empty with default access level
Config::set('sso.static_level', 5); Config::set('sso.static_level', 5);
$this->assertTrue($a->authSSOParseGroups() === 5); $this->assertSame(5, $a->authSSOParseGroups());
Config::forget('sso.static_level'); Config::forget('sso.static_level');
// Null // Null
$_SERVER['member'] = null; $_SERVER['member'] = null;
$this->assertTrue($a->authSSOParseGroups() === 0); $this->assertSame(0, $a->authSSOParseGroups());
// Unset // Unset
unset($_SERVER['member']); unset($_SERVER['member']);
$this->assertTrue($a->authSSOParseGroups() === 0); $this->assertSame(0, $a->authSSOParseGroups());
$_SERVER['member'] = 'librenms-admins;librenms-readers;librenms-billingcontacts;unrelatedgroup;confluence-admins'; $_SERVER['member'] = 'librenms-admins;librenms-readers;librenms-billingcontacts;unrelatedgroup;confluence-admins';
// Empty // Empty
Config::set('sso.group_level_map', []); Config::set('sso.group_level_map', []);
$this->assertTrue($a->authSSOParseGroups() === 0); $this->assertSame(0, $a->authSSOParseGroups());
// Not associative // Not associative
Config::set('sso.group_level_map', ['foo', 'bar', 'librenms-admins']); Config::set('sso.group_level_map', ['foo', 'bar', 'librenms-admins']);
$this->assertTrue($a->authSSOParseGroups() === 0); $this->assertSame(0, $a->authSSOParseGroups());
// Null // Null
Config::set('sso.group_level_map', null); Config::set('sso.group_level_map', null);
$this->assertTrue($a->authSSOParseGroups() === 0); $this->assertSame(0, $a->authSSOParseGroups());
// Unset // Unset
Config::forget('sso.group_level_map'); Config::forget('sso.group_level_map');
$this->assertTrue($a->authSSOParseGroups() === 0); $this->assertSame(0, $a->authSSOParseGroups());
// No delimiter // No delimiter
Config::forget('sso.group_delimiter'); Config::forget('sso.group_delimiter');
$this->assertTrue($a->authSSOParseGroups() === 0); $this->assertSame(0, $a->authSSOParseGroups());
// Test group filtering by regex // Test group filtering by regex
Config::set('sso.group_filter', '/confluence-(.*)/i'); Config::set('sso.group_filter', '/confluence-(.*)/i');
Config::set('sso.group_delimiter', ';'); Config::set('sso.group_delimiter', ';');
Config::set('sso.group_level_map', ['librenms-admins' => 10, 'librenms-readers' => 1, 'librenms-billingcontacts' => 5, 'confluence-admins' => 7]); Config::set('sso.group_level_map', ['librenms-admins' => 10, 'librenms-readers' => 1, 'librenms-billingcontacts' => 5, 'confluence-admins' => 7]);
$this->assertTrue($a->authSSOParseGroups() === 7); $this->assertSame(7, $a->authSSOParseGroups());
// Test group filtering by empty regex // Test group filtering by empty regex
Config::set('sso.group_filter', ''); Config::set('sso.group_filter', '');
$this->assertTrue($a->authSSOParseGroups() === 10); $this->assertSame(10, $a->authSSOParseGroups());
// Test group filtering by null regex // Test group filtering by null regex
Config::set('sso.group_filter', null); Config::set('sso.group_filter', null);
$this->assertTrue($a->authSSOParseGroups() === 10); $this->assertSame(10, $a->authSSOParseGroups());
} }
protected function tearDown(): void protected function tearDown(): void