From 4dac706231bf86bf2309fc10d72f431ea9e974a4 Mon Sep 17 00:00:00 2001 From: Shift Date: Mon, 24 Oct 2022 17:25:02 +0000 Subject: [PATCH] Apply code style --- LibreNMS/Alert/AlertDB.php | 2 +- LibreNMS/Alert/AlertRules.php | 2 +- LibreNMS/Alert/RunAlerts.php | 6 +++--- .../Authentication/LdapAuthorizationAuthorizer.php | 2 +- LibreNMS/Authentication/SSOAuthorizer.php | 2 +- LibreNMS/Authentication/TwoFactor.php | 2 +- LibreNMS/Data/Store/Rrd.php | 4 ++-- LibreNMS/IRCBot.php | 8 ++++---- LibreNMS/OS/ArubaInstant.php | 12 ++++++------ LibreNMS/OS/Beagleboard.php | 3 +-- LibreNMS/OS/Stellar.php | 4 ++-- LibreNMS/OS/Vrp.php | 4 ++-- LibreNMS/ObjectCache.php | 2 +- LibreNMS/Validations/System.php | 2 +- app/Console/Commands/SmokepingGenerateCommand.php | 2 +- app/Http/Controllers/LegacyController.php | 2 +- app/Http/Controllers/Table/MempoolsController.php | 2 +- tests/Unit/Util/StringHelperTest.php | 6 ++---- tests/phpstan/ignore-by-php-version.neon.php | 2 +- 19 files changed, 33 insertions(+), 36 deletions(-) diff --git a/LibreNMS/Alert/AlertDB.php b/LibreNMS/Alert/AlertDB.php index 919e9a36a1..363fbe7d22 100644 --- a/LibreNMS/Alert/AlertDB.php +++ b/LibreNMS/Alert/AlertDB.php @@ -83,7 +83,7 @@ class AlertDB //Our first table has no valid glue, append the 'devices' table to it! array_unshift($tables, 'devices'); } - $x = sizeof($tables) - 1; + $x = count($tables) - 1; $i = 0; $join = ''; while ($i < $x) { diff --git a/LibreNMS/Alert/AlertRules.php b/LibreNMS/Alert/AlertRules.php index d60c923880..0043b3d122 100644 --- a/LibreNMS/Alert/AlertRules.php +++ b/LibreNMS/Alert/AlertRules.php @@ -77,7 +77,7 @@ class AlertRules $qry[$i]['ip'] = inet6_ntop($qry[$i]['ip']); } } - $s = sizeof($qry); + $s = count($qry); if ($s == 0 && $inv === false) { $doalert = false; } elseif ($s > 0 && $inv === false) { diff --git a/LibreNMS/Alert/RunAlerts.php b/LibreNMS/Alert/RunAlerts.php index 415bae9059..48de13fd5e 100644 --- a/LibreNMS/Alert/RunAlerts.php +++ b/LibreNMS/Alert/RunAlerts.php @@ -226,7 +226,7 @@ class RunAlerts return 'none'; } - return join(' ', $ret); + return implode(' ', $ret); } public function clearStaleAlerts() @@ -329,8 +329,8 @@ class RunAlerts $chk[$i]['ip'] = inet6_ntop($chk[$i]['ip']); } } - $o = sizeof($alert['details']['rule']); - $n = sizeof($chk); + $o = count($alert['details']['rule']); + $n = count($chk); $ret = 'Alert #' . $alert['id']; $state = AlertState::CLEAR; if ($n > $o) { diff --git a/LibreNMS/Authentication/LdapAuthorizationAuthorizer.php b/LibreNMS/Authentication/LdapAuthorizationAuthorizer.php index cf09f5e426..8c4d0fbd9d 100644 --- a/LibreNMS/Authentication/LdapAuthorizationAuthorizer.php +++ b/LibreNMS/Authentication/LdapAuthorizationAuthorizer.php @@ -123,7 +123,7 @@ class LdapAuthorizationAuthorizer extends AuthorizerBase } // Find all defined groups $username is in - $filter = '(&(|(cn=' . join(')(cn=', array_keys(Config::get('auth_ldap_groups'))) . '))(' . Config::get('auth_ldap_groupmemberattr') . '=' . $this->getMembername($username) . '))'; + $filter = '(&(|(cn=' . implode(')(cn=', array_keys(Config::get('auth_ldap_groups'))) . '))(' . Config::get('auth_ldap_groupmemberattr') . '=' . $this->getMembername($username) . '))'; $search = ldap_search($this->ldap_connection, Config::get('auth_ldap_groupbase'), $filter); $entries = ldap_get_entries($this->ldap_connection, $search); diff --git a/LibreNMS/Authentication/SSOAuthorizer.php b/LibreNMS/Authentication/SSOAuthorizer.php index 8847e9320c..eac3394756 100644 --- a/LibreNMS/Authentication/SSOAuthorizer.php +++ b/LibreNMS/Authentication/SSOAuthorizer.php @@ -211,7 +211,7 @@ class SSOAuthorizer extends MysqlAuthorizer if (isset($config_map[$value])) { $map = $config_map[$value]; - if (is_integer($map) && $level < $map) { + if (is_int($map) && $level < $map) { $level = $map; } } diff --git a/LibreNMS/Authentication/TwoFactor.php b/LibreNMS/Authentication/TwoFactor.php index e08897c0ae..0e028f2c1f 100644 --- a/LibreNMS/Authentication/TwoFactor.php +++ b/LibreNMS/Authentication/TwoFactor.php @@ -115,7 +115,7 @@ class TwoFactor $bin = str_split($bin, 5); $ret = ''; $x = -1; - while (++$x < sizeof($bin)) { + while (++$x < count($bin)) { $ret .= self::$base32_enc[(int) base_convert(str_pad($bin[$x], 5, '0'), 2, 10)]; } diff --git a/LibreNMS/Data/Store/Rrd.php b/LibreNMS/Data/Store/Rrd.php index 5ce88c6d64..be8a6276a3 100644 --- a/LibreNMS/Data/Store/Rrd.php +++ b/LibreNMS/Data/Store/Rrd.php @@ -272,13 +272,13 @@ class Rrd extends BaseDatastore */ public function proxmoxName($pmxcluster, $vmid, $vmport) { - $pmxcdir = join('/', [$this->rrd_dir, 'proxmox', self::safeName($pmxcluster)]); + $pmxcdir = implode('/', [$this->rrd_dir, 'proxmox', self::safeName($pmxcluster)]); // this is not needed for remote rrdcached if (! is_dir($pmxcdir)) { mkdir($pmxcdir, 0775, true); } - return join('/', [$pmxcdir, self::safeName($vmid . '_netif_' . $vmport . '.rrd')]); + return implode('/', [$pmxcdir, self::safeName($vmid . '_netif_' . $vmport . '.rrd')]); } /** diff --git a/LibreNMS/IRCBot.php b/LibreNMS/IRCBot.php index 53c01542a5..ee0065d18e 100644 --- a/LibreNMS/IRCBot.php +++ b/LibreNMS/IRCBot.php @@ -150,7 +150,7 @@ class IRCBot } } - return $this->log('Cached ' . sizeof($this->external) . ' commands.'); + return $this->log('Cached ' . count($this->external) . ' commands.'); } //end load_external() @@ -673,7 +673,7 @@ class IRCBot private function ircRaw($params) { - return fputs($this->socket['irc'], $params . "\r\n"); + return fwrite($this->socket['irc'], $params . "\r\n"); } //end irc_raw() @@ -770,9 +770,9 @@ class IRCBot private function _help($params) { - $msg = join(', ', $this->commands); + $msg = implode(', ', $this->commands); if (count($this->external) > 0) { - $msg .= ', ' . join(', ', array_keys($this->external)); + $msg .= ', ' . implode(', ', array_keys($this->external)); } return $this->respond("Available commands: $msg"); diff --git a/LibreNMS/OS/ArubaInstant.php b/LibreNMS/OS/ArubaInstant.php index 4499612cff..01a8923e40 100644 --- a/LibreNMS/OS/ArubaInstant.php +++ b/LibreNMS/OS/ArubaInstant.php @@ -137,7 +137,7 @@ class ArubaInstant extends OS implements // fetch the MAC addresses of currently connected clients, then count them to get an overall total $client_data = $this->getCacheTable('aiClientMACAddress', $ai_mib); - $total_clients = sizeof($client_data); + $total_clients = count($client_data); $combined_oid = sprintf('%s::%s', $ai_mib, 'aiClientMACAddress'); $oid = snmp_translate($combined_oid, 'ALL', 'arubaos', '-On'); @@ -160,7 +160,7 @@ class ArubaInstant extends OS implements $ai_mib = 'AI-AP-MIB'; $ap_data = $this->getCacheTable('aiAPSerialNum', $ai_mib); - $total_aps = sizeof($ap_data); + $total_aps = count($ap_data); $combined_oid = sprintf('%s::%s', $ai_mib, 'aiAPSerialNum'); $oid = snmp_translate($combined_oid, 'ALL', 'arubaos', '-On'); @@ -307,14 +307,14 @@ class ArubaInstant extends OS implements } } else { // version is lower than 8.4.0.0 - if (! empty($sensors) && sizeof($sensors) == 1) { + if (! empty($sensors) && count($sensors) == 1) { $ai_mib = 'AI-AP-MIB'; $client_data = $this->getCacheTable('aiClientMACAddress', $ai_mib); if (empty($client_data)) { $total_clients = 0; } else { - $total_clients = sizeof($client_data); + $total_clients = count($client_data); } $data[$sensors[0]['sensor_id']] = $total_clients; @@ -335,14 +335,14 @@ class ArubaInstant extends OS implements public function pollWirelessApCount(array $sensors) { $data = []; - if (! empty($sensors) && sizeof($sensors) == 1) { + if (! empty($sensors) && count($sensors) == 1) { $ai_mib = 'AI-AP-MIB'; $ap_data = $this->getCacheTable('aiAPSerialNum', $ai_mib); $total_aps = 0; if (! empty($ap_data)) { - $total_aps = sizeof($ap_data); + $total_aps = count($ap_data); } $data[$sensors[0]['sensor_id']] = $total_aps; diff --git a/LibreNMS/OS/Beagleboard.php b/LibreNMS/OS/Beagleboard.php index 10583dec15..36c95e5a19 100644 --- a/LibreNMS/OS/Beagleboard.php +++ b/LibreNMS/OS/Beagleboard.php @@ -27,8 +27,7 @@ use App\Models\Device; use LibreNMS\Interfaces\Discovery\OSDiscovery; use LibreNMS\OS; -class Beagleboard extends OS implements - OSDiscovery +class Beagleboard extends OS implements OSDiscovery { /** * Retrieve basic information about the OS / device diff --git a/LibreNMS/OS/Stellar.php b/LibreNMS/OS/Stellar.php index 307cfaf385..743425a618 100644 --- a/LibreNMS/OS/Stellar.php +++ b/LibreNMS/OS/Stellar.php @@ -34,7 +34,7 @@ class Stellar extends OS implements if (empty($client_ws_data)) { $total_clients = 0; } else { - $total_clients = sizeof($client_ws_data); + $total_clients = count($client_ws_data); } $combined_oid = sprintf('%s::%s', $device['hardware'], 'apClientWlanService'); @@ -75,7 +75,7 @@ class Stellar extends OS implements if (empty($client_ws_data)) { $total_clients = 0; } else { - $total_clients = sizeof($client_ws_data); + $total_clients = count($client_ws_data); } foreach ($sensors as $sensor) { diff --git a/LibreNMS/OS/Vrp.php b/LibreNMS/OS/Vrp.php index 2866ea448e..abfb6b78f3 100644 --- a/LibreNMS/OS/Vrp.php +++ b/LibreNMS/OS/Vrp.php @@ -226,7 +226,7 @@ class Vrp extends OS implements $foundid = 0; - for ($z = 0; $z < sizeof($ap_db); $z++) { + for ($z = 0; $z < count($ap_db); $z++) { if ($ap_db[$z]['name'] == $name && $ap_db[$z]['radio_number'] == $radionum) { $foundid = $ap_db[$z]['accesspoint_id']; $ap_db[$z]['seen'] = 1; @@ -276,7 +276,7 @@ class Vrp extends OS implements }//end foreach 1 }//end foreach 2 - for ($z = 0; $z < sizeof($ap_db); $z++) { + for ($z = 0; $z < count($ap_db); $z++) { if (! isset($ap_db[$z]['seen']) && $ap_db[$z]['deleted'] == 0) { dbUpdate(['deleted' => 1], 'access_points', '`accesspoint_id` = ?', [$ap_db[$z]['accesspoint_id']]); } diff --git a/LibreNMS/ObjectCache.php b/LibreNMS/ObjectCache.php index 8480dfb773..6d4f5f31eb 100644 --- a/LibreNMS/ObjectCache.php +++ b/LibreNMS/ObjectCache.php @@ -100,7 +100,7 @@ class ObjectCache implements ArrayAccess return $GLOBALS['_ObjCache'][$this->obj][$obj]['value']; } else { $GLOBALS['_ObjCache'][$this->obj][$obj]['value'] = dbFetchRows($this->data[$obj]['query'], isset($this->data[$obj]['params']) ? $this->data[$obj]['params'] : []); - if (sizeof($GLOBALS['_ObjCache'][$this->obj][$obj]['value']) == 1 && sizeof($GLOBALS['_ObjCache'][$this->obj][$obj]['value'][0]) == 1) { + if (count($GLOBALS['_ObjCache'][$this->obj][$obj]['value']) == 1 && count($GLOBALS['_ObjCache'][$this->obj][$obj]['value'][0]) == 1) { $GLOBALS['_ObjCache'][$this->obj][$obj]['value'] = current($GLOBALS['_ObjCache'][$this->obj][$obj]['value'][0]); } diff --git a/LibreNMS/Validations/System.php b/LibreNMS/Validations/System.php index bed5146deb..be23084874 100644 --- a/LibreNMS/Validations/System.php +++ b/LibreNMS/Validations/System.php @@ -34,7 +34,7 @@ class System extends BaseValidation protected static $RUN_BY_DEFAULT = true; /** - * {@inheritdoc} + * @inheritdoc */ public function validate(Validator $validator): void { diff --git a/app/Console/Commands/SmokepingGenerateCommand.php b/app/Console/Commands/SmokepingGenerateCommand.php index f093ed0051..e2385a8031 100644 --- a/app/Console/Commands/SmokepingGenerateCommand.php +++ b/app/Console/Commands/SmokepingGenerateCommand.php @@ -79,7 +79,7 @@ class SmokepingGenerateCommand extends LnmsCommand $devices = Device::isNotDisabled()->orderBy('type')->orderBy('hostname')->get(); - if (sizeof($devices) < 1) { + if (count($devices) < 1) { $this->error(__('commands.smokeping:generate.no-devices')); return 3; diff --git a/app/Http/Controllers/LegacyController.php b/app/Http/Controllers/LegacyController.php index d7b5d5725a..ecf7f787f9 100644 --- a/app/Http/Controllers/LegacyController.php +++ b/app/Http/Controllers/LegacyController.php @@ -72,7 +72,7 @@ class LegacyController extends Controller } // create and set the title - $title = join(' - ', $pagetitle); + $title = implode(' - ', $pagetitle); $html .= ""; } diff --git a/app/Http/Controllers/Table/MempoolsController.php b/app/Http/Controllers/Table/MempoolsController.php index 6205199fc5..dd95bc6a25 100644 --- a/app/Http/Controllers/Table/MempoolsController.php +++ b/app/Http/Controllers/Table/MempoolsController.php @@ -46,7 +46,7 @@ class MempoolsController extends TableController } /** - * {@inheritdoc} + * @inheritdoc */ protected function baseQuery($request) { diff --git a/tests/Unit/Util/StringHelperTest.php b/tests/Unit/Util/StringHelperTest.php index 0c491b83d2..cda5890d2e 100644 --- a/tests/Unit/Util/StringHelperTest.php +++ b/tests/Unit/Util/StringHelperTest.php @@ -61,8 +61,7 @@ class StringHelperTest extends TestCase $this->assertFalse(StringHelpers::isStringable([])); $this->assertFalse(StringHelpers::isStringable((object) [])); - $stringable = new class - { + $stringable = new class { public function __toString() { return ''; @@ -70,8 +69,7 @@ class StringHelperTest extends TestCase }; $this->assertTrue(StringHelpers::isStringable($stringable)); - $nonstringable = new class - { + $nonstringable = new class { }; $this->assertFalse(StringHelpers::isStringable($nonstringable)); } diff --git a/tests/phpstan/ignore-by-php-version.neon.php b/tests/phpstan/ignore-by-php-version.neon.php index 040dd8538c..830c5bf26b 100644 --- a/tests/phpstan/ignore-by-php-version.neon.php +++ b/tests/phpstan/ignore-by-php-version.neon.php @@ -17,7 +17,7 @@ if (PHP_VERSION_ID < 80100) { } // If we loaded any extra config -if (sizeof($config) > 0) { +if (count($config) > 0) { $config['parameters']['reportUnmatchedIgnoredErrors'] = false; }