PHP 8 fixes (#12528)

* port related errors

* more fixes

* fix storage count

* add tests for php8

* style

* only need not empty

* aix fixes....

* storage WIP

* fix aix discovering hrstorage
fix db test adding .gitkeep
fix os modules when discovery only

* fix aos processors wrong oid

* fix mempool number casting

* fix aos7 cpu

* use + 0 cast instead of floatval()

* more verbose error on invalid json

* remove invalid data in json

* actually fix the json

* correct json error fix

* cast_number() function
fix aruba-instant and aos6 bugs exposed by new function, probably more...

* fix a-f
fix inadequate sort for component data

* fix global port poll time

* fix mempools precent 0, route count, ntp const

* fix schleifenbauer liberal current usage

* further number casting refinement

* vrp

* fix tests

* fix arbos

* warn cleanups adjust to :: change

* fix ciena-sds

* fix drac

* fix dell-rpdu anddlink

* fix and improve arubaos
better error when getting an array in Processor

* fix atenpdu, add missing arubaos files

* aruba-instant to yaml
apparently I didn't need to do this, the diff just looks really odd
It did add ranged sub-index replacements

* docker app, was completely wrong... fixed

* fix sentry4 divide by 0...

* fixed root issue, remove check

* nicer cidr in ipv6 code

* remove bogus enuxus battery bank skip_values

* Fix InfluxDB tests

* remove extra import

* fix other style issues.

* influx "style" fixes
This commit is contained in:
Tony Murray
2021-03-12 18:10:14 -06:00
committed by GitHub
parent 13c5745ae8
commit 61316ce2cc
81 changed files with 2578 additions and 3353 deletions

View File

@@ -93,9 +93,7 @@ class IPv6 extends IP
*/
public function getNetworkAddress($cidr = null)
{
if (is_null($cidr)) {
$cidr = $this->cidr;
}
$cidr = (int) ($cidr ?? $this->cidr);
$net_bytes = unpack('n*', inet_pton($this->ip));

View File

@@ -249,13 +249,15 @@ class ModuleTestHelper
[$os, $variant] = self::extractVariant($file);
// calculate valid modules
$data_modules = array_keys(json_decode(file_get_contents($file), true));
$decoded = json_decode(file_get_contents($file), true);
if (json_last_error()) {
echo "Invalid json data: $base_name\n";
exit(1);
}
$data_modules = array_keys($decoded);
if (empty($modules)) {
$valid_modules = $data_modules;
} else {
@@ -837,7 +839,9 @@ class ModuleTestHelper
private function collectComponents($device_id)
{
$components = (new Component())->getComponents($device_id)[$device_id] ?? [];
$components = Arr::sort($components, 'label');
$components = Arr::sort($components, function ($item) {
return $item['type'] . $item['label'];
});
return array_values($components);
}

View File

@@ -61,7 +61,7 @@ class Number
$value = $value * -1;
}
return (number_format(round($value, $round), $sf, '.', '') + 0) . " $ext$suffix";
return self::cast(number_format(round($value, $round), $sf, '.', '')) . " $ext$suffix";
}
public static function formatBi($value, $round = 2, $sf = 3, $suffix = 'B')
@@ -81,6 +81,29 @@ class Number
$value = $value * -1;
}
return (number_format(round($value, $round), $sf, '.', '') + 0) . " $ext$suffix";
return self::cast(number_format(round($value, $round), $sf, '.', '')) . " $ext$suffix";
}
/**
* Cast string to int or float.
* Returns 0 if string is not numeric
*
* @param string $number
* @return float|int
*/
public static function cast($number)
{
if (! is_numeric($number)) {
// match pre-PHP8 behavior
if (! preg_match('/^-?\d+(\.\d+)?/', $number, $matches)) {
return 0;
}
$number = $matches[0];
}
$float = (float) $number;
$int = (int) $number;
return $float == $int ? $int : $float;
}
}