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 + 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)
{
preg_match('/([0-9]{1,5}(\.[0-9]+)?)/', $data, $matches);
$value = $matches[1];
$value = (float) $matches[1];
if ($precision < 0) {
// idle value, subtract from 100

View File

@@ -238,7 +238,7 @@ class YamlDiscovery
return current($pre_cache[$name]);
} elseif (isset($sub_indexes[$sub_index])) {
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])) {
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)
{
$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();
$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\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
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
*/
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
*/
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
*/
protected function formatResponse($paginator)

View File

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

View File

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

View File

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

View File

@@ -9,7 +9,7 @@ class EventServiceProvider extends ServiceProvider
/**
* The event listener mappings for the application.
*
* @var array
* @var array<string, array<int, string>>
*/
protected $listen = [
\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');
UserWidget::query()->chunk(1000, function (Collection $widgets) {
$widgets->each(function ($widget) {
$widget->widget = $this->map[$widget->widget_id];
$widgets->each(function (UserWidget $widget) {
$widget->widget = $this->map[$widget->getAttribute('widget_id')];
$widget->save();
});
});

View File

@@ -1405,11 +1405,6 @@ parameters:
count: 1
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\\.$#"
count: 1

View File

@@ -139,9 +139,9 @@ class AuthSSOTest extends DBTestCase
// Retrieve it and validate
$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($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
$_SERVER['mail'] = 'test@example.net';
@@ -176,9 +176,9 @@ class AuthSSOTest extends DBTestCase
// Retrieve it and validate the update persisted
$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($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
@@ -356,12 +356,12 @@ class AuthSSOTest extends DBTestCase
//Integer
Config::set('sso.level_attr', 'level');
$_SERVER['level'] = 9;
$this->assertTrue($a->authSSOCalculateLevel() === 9);
$this->assertSame(9, $a->authSSOCalculateLevel());
//String
Config::set('sso.level_attr', 'level');
$_SERVER['level'] = '9';
$this->assertTrue($a->authSSOCalculateLevel() === 9);
$this->assertSame(9, $a->authSSOCalculateLevel());
//Invalid String
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';
// Valid options
$this->assertTrue($a->authSSOParseGroups() === 10);
$this->assertSame(10, $a->authSSOParseGroups());
// No match
$_SERVER['member'] = 'confluence-admins';
$this->assertTrue($a->authSSOParseGroups() === 0);
$this->assertSame(0, $a->authSSOParseGroups());
// Delimiter only
$_SERVER['member'] = ';;;;';
$this->assertTrue($a->authSSOParseGroups() === 0);
$this->assertSame(0, $a->authSSOParseGroups());
// Empty
$_SERVER['member'] = '';
$this->assertTrue($a->authSSOParseGroups() === 0);
$this->assertSame(0, $a->authSSOParseGroups());
// Empty with default access level
Config::set('sso.static_level', 5);
$this->assertTrue($a->authSSOParseGroups() === 5);
$this->assertSame(5, $a->authSSOParseGroups());
Config::forget('sso.static_level');
// Null
$_SERVER['member'] = null;
$this->assertTrue($a->authSSOParseGroups() === 0);
$this->assertSame(0, $a->authSSOParseGroups());
// Unset
unset($_SERVER['member']);
$this->assertTrue($a->authSSOParseGroups() === 0);
$this->assertSame(0, $a->authSSOParseGroups());
$_SERVER['member'] = 'librenms-admins;librenms-readers;librenms-billingcontacts;unrelatedgroup;confluence-admins';
// Empty
Config::set('sso.group_level_map', []);
$this->assertTrue($a->authSSOParseGroups() === 0);
$this->assertSame(0, $a->authSSOParseGroups());
// Not associative
Config::set('sso.group_level_map', ['foo', 'bar', 'librenms-admins']);
$this->assertTrue($a->authSSOParseGroups() === 0);
$this->assertSame(0, $a->authSSOParseGroups());
// Null
Config::set('sso.group_level_map', null);
$this->assertTrue($a->authSSOParseGroups() === 0);
$this->assertSame(0, $a->authSSOParseGroups());
// Unset
Config::forget('sso.group_level_map');
$this->assertTrue($a->authSSOParseGroups() === 0);
$this->assertSame(0, $a->authSSOParseGroups());
// No delimiter
Config::forget('sso.group_delimiter');
$this->assertTrue($a->authSSOParseGroups() === 0);
$this->assertSame(0, $a->authSSOParseGroups());
// Test group filtering by regex
Config::set('sso.group_filter', '/confluence-(.*)/i');
Config::set('sso.group_delimiter', ';');
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
Config::set('sso.group_filter', '');
$this->assertTrue($a->authSSOParseGroups() === 10);
$this->assertSame(10, $a->authSSOParseGroups());
// Test group filtering by null regex
Config::set('sso.group_filter', null);
$this->assertTrue($a->authSSOParseGroups() === 10);
$this->assertSame(10, $a->authSSOParseGroups());
}
protected function tearDown(): void