Skip to content

Commit 3a83483

Browse files
committed
Fix rector mistake
due to missing types
1 parent b503d14 commit 3a83483

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

LibreNMS/Data/Source/NetSnmpQuery.php

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -45,37 +45,33 @@ class NetSnmpQuery implements SnmpQueryInterface
4545
{
4646
private const DEFAULT_FLAGS = '-OQXUte';
4747

48-
/**
49-
* @var array
50-
*/
51-
private $cleanup = [
52-
'command' => [
53-
[
54-
'/-c\' \'[\S]+\'/',
55-
'/-u\' \'[\S]+\'/',
56-
'/-U\' \'[\S]+\'/',
57-
'/-A\' \'[\S]+\'/',
58-
'/-X\' \'[\S]+\'/',
59-
'/-P\' \'[\S]+\'/',
60-
'/-H\' \'[\S]+\'/',
61-
'/(udp|udp6|tcp|tcp6):([^:]+):([\d]+)/',
62-
], [
63-
'-c\' \'COMMUNITY\'',
64-
'-u\' \'USER\'',
65-
'-U\' \'USER\'',
66-
'-A\' \'PASSWORD\'',
67-
'-X\' \'PASSWORD\'',
68-
'-P\' \'PASSWORD\'',
69-
'-H\' \'HOSTNAME\'',
70-
'\1:HOSTNAME:\3',
71-
],
72-
],
73-
'output' => [
74-
'/(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/',
75-
'*',
76-
],
48+
/** @var string[] */
49+
private array $commandCleanupPatterns = [
50+
'/-c\' \'[\S]+\'/',
51+
'/-u\' \'[\S]+\'/',
52+
'/-U\' \'[\S]+\'/',
53+
'/-A\' \'[\S]+\'/',
54+
'/-X\' \'[\S]+\'/',
55+
'/-P\' \'[\S]+\'/',
56+
'/-H\' \'[\S]+\'/',
57+
'/(udp|udp6|tcp|tcp6):([^:]+):([\d]+)/',
7758
];
7859

60+
/** @var string[] */
61+
private array $commandReplacementPatterns = [
62+
'-c\' \'COMMUNITY\'',
63+
'-u\' \'USER\'',
64+
'-U\' \'USER\'',
65+
'-A\' \'PASSWORD\'',
66+
'-X\' \'PASSWORD\'',
67+
'-P\' \'PASSWORD\'',
68+
'-H\' \'HOSTNAME\'',
69+
'\1:HOSTNAME:\3',
70+
];
71+
72+
private string $output_regex = '/(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/';
73+
private string $output_replacement = '*';
74+
7975
/**
8076
* @var string[]
8177
*/
@@ -526,7 +522,7 @@ private function checkExitCode(int $code, string $error): void
526522
private function logCommand(string $command): void
527523
{
528524
if (Debug::isEnabled() && ! Debug::isVerbose()) {
529-
$debug_command = preg_replace($this->cleanup['command'][0], (string) $this->cleanup['command'][1], $command);
525+
$debug_command = preg_replace($this->commandCleanupPatterns, $this->commandReplacementPatterns, $command);
530526
Log::debug('SNMP[%c' . $debug_command . '%n]', ['color' => true]);
531527
} elseif (Debug::isVerbose()) {
532528
Log::debug('SNMP[%c' . $command . '%n]', ['color' => true]);
@@ -536,7 +532,7 @@ private function logCommand(string $command): void
536532
private function logOutput(string $output, string $error): void
537533
{
538534
if (Debug::isEnabled() && ! Debug::isVerbose()) {
539-
Log::debug(preg_replace($this->cleanup['output'][0], (string) $this->cleanup['output'][1], $output));
535+
Log::debug(preg_replace($this->output_regex, $this->output_replacement, $output));
540536
} elseif (Debug::isVerbose()) {
541537
Log::debug($output);
542538
}

0 commit comments

Comments
 (0)