The function snmp_walk() calls the typical debug function print_r() which is mostly only used during development. Open
d_echo('Invalid snmp_walk() data = ' . print_r($data, true));
- Read upRead up
- Exclude checks
DevelopmentCodeFragment
Since: 2.3.0
Functions like vardump(), printr() etc. are normally only used during development and therefore such calls in production code are a good indicator that they were just forgotten.
Example
class SuspectCode {
public function doSomething(array $items)
{
foreach ($items as $i => $item) {
// …
if ('qafoo' == $item) var_dump($i);
// …
}
}
}
Source https://phpmd.org/rules/design.html#developmentcodefragment
File snmp.inc.php
has 500 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/*
* LibreNMS - SNMP Functions
*
* Original Observium code by: Adam Armstrong, Tom Laermans
Function snmpwalk_cache_multi_oid
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
function snmpwalk_cache_multi_oid($device, $oid, $array = [], $mib = null, $mibdir = null, $snmpflags = '-OQUs')
{
global $cache;
if (! (is_array($cache['snmp'][$device['device_id']] ?? null) && array_key_exists($oid, $cache['snmp'][$device['device_id']]))) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function snmp_get_multi
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
function snmp_get_multi($device, $oids, $options = '-OQUs', $mib = null, $mibdir = null, $array = [])
{
$measure = Measurement::start('snmpget');
if (! is_array($oids)) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function snmp_get_multi_oid
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
function snmp_get_multi_oid($device, $oids, $options = '-OUQn', $mib = null, $mibdir = null)
{
$measure = Measurement::start('snmpget');
$oid_limit = get_device_oid_limit($device);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function get_mib_dir
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
function get_mib_dir($device)
{
$dirs = [];
if (isset($device['os']) && file_exists(Config::get('mib_dir') . '/' . $device['os'])) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method snmp_get_multi_oid
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
function snmp_get_multi_oid($device, $oids, $options = '-OUQn', $mib = null, $mibdir = null)
{
$measure = Measurement::start('snmpget');
$oid_limit = get_device_oid_limit($device);
Function snmpwalk_cache_oid
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
function snmpwalk_cache_oid($device, $oid, $array = [], $mib = null, $mibdir = null, $snmpflags = '-OQUs')
{
$data = snmp_walk($device, $oid, $snmpflags, $mib, $mibdir);
if (empty($data)) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function snmpwalk_cache_twopart_oid
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
function snmpwalk_cache_twopart_oid($device, $oid, $array = [], $mib = 0, $mibdir = null, $snmpflags = '-OQUs')
{
$cmd = gen_snmpwalk_cmd($device, $oid, $snmpflags, $mib, $mibdir);
$data = trim(external_exec($cmd));
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function snmpwalk_group
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
function snmpwalk_group($device, $oid, $mib = '', $depth = 1, $array = [], $mibdir = null, $snmpFlags = '-OQUsetX')
{
$cmd = gen_snmpwalk_cmd($device, $oid, $snmpFlags, $mib, $mibdir);
$data = rtrim(external_exec($cmd));
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method snmp_get_multi
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
function snmp_get_multi($device, $oids, $options = '-OQUs', $mib = null, $mibdir = null, $array = [])
{
$measure = Measurement::start('snmpget');
if (! is_array($oids)) {
Method snmpwalk_cache_multi_oid
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
function snmpwalk_cache_multi_oid($device, $oid, $array = [], $mib = null, $mibdir = null, $snmpflags = '-OQUs')
{
global $cache;
if (! (is_array($cache['snmp'][$device['device_id']] ?? null) && array_key_exists($oid, $cache['snmp'][$device['device_id']]))) {
Method snmpwalk_group
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
function snmpwalk_group($device, $oid, $mib = '', $depth = 1, $array = [], $mibdir = null, $snmpFlags = '-OQUsetX')
{
$cmd = gen_snmpwalk_cmd($device, $oid, $snmpFlags, $mib, $mibdir);
$data = rtrim(external_exec($cmd));
Method snmpwalk_array_num
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
function snmpwalk_array_num($device, $oid, $indexes = 1)
{
$array = [];
$string = snmp_walk($device, $oid, '-Osqn');
Function snmp_getnext_multi
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
function snmp_getnext_multi($device, $oids, $options = '-OQUs', $mib = null, $mibdir = null, $array = [])
{
$measure = Measurement::start('snmpgetnext');
if (! is_array($oids)) {
$oids = explode(' ', $oids);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function snmp_gen_auth
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
function snmp_gen_auth(&$device, $cmd = [])
{
if ($device['snmpver'] === 'v3') {
array_push($cmd, '-v3', '-l', $device['authlevel']);
array_push($cmd, '-n', isset($device['context_name']) ? $device['context_name'] : '');
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function snmpwalk_array_num
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
function snmpwalk_array_num($device, $oid, $indexes = 1)
{
$array = [];
$string = snmp_walk($device, $oid, '-Osqn');
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method snmpwalk_group
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
function snmpwalk_group($device, $oid, $mib = '', $depth = 1, $array = [], $mibdir = null, $snmpFlags = '-OQUsetX')
Method snmpwalk_cache_long_oid
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
function snmpwalk_cache_long_oid($device, $oid, $noid, $array = [], $mib = null, $mibdir = null, $snmpflags = '-OQnU')
Method snmpwalk_cache_numerical_oid
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function snmpwalk_cache_numerical_oid($device, $oid, $array = [], $mib = null, $mibdir = null, $snmpflags = '-OQUsn')
Method snmpwalk_cache_multi_oid
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function snmpwalk_cache_multi_oid($device, $oid, $array = [], $mib = null, $mibdir = null, $snmpflags = '-OQUs')
Method snmp_getnext_multi
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function snmp_getnext_multi($device, $oids, $options = '-OQUs', $mib = null, $mibdir = null, $array = [])
Function gen_snmpwalk_cmd
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
function gen_snmpwalk_cmd($device, $oids, $options = null, $mib = null, $mibdir = null)
{
$oids = Arr::wrap($oids);
if ($device['snmpver'] == 'v1'
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method snmpwalk_cache_oid
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function snmpwalk_cache_oid($device, $oid, $array = [], $mib = null, $mibdir = null, $snmpflags = '-OQUs')
Method gen_snmp_cmd
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function gen_snmp_cmd($cmd, $device, $oids, $options = null, $mib = null, $mibdir = null)
Method snmp_get_multi
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function snmp_get_multi($device, $oids, $options = '-OQUs', $mib = null, $mibdir = null, $array = [])
Function snmpwalk_cache_long_oid
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
function snmpwalk_cache_long_oid($device, $oid, $noid, $array = [], $mib = null, $mibdir = null, $snmpflags = '-OQnU')
{
$data = snmp_walk($device, $oid, $snmpflags, $mib, $mibdir);
if (empty($data)) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method snmpwalk_cache_twopart_oid
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function snmpwalk_cache_twopart_oid($device, $oid, $array = [], $mib = 0, $mibdir = null, $snmpflags = '-OQUs')
Method snmp_translate
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function snmp_translate($oid, $mib = 'ALL', $mibdir = null, $options = null, $device = null)
Method snmp_get_multi_oid
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function snmp_get_multi_oid($device, $oids, $options = '-OUQn', $mib = null, $mibdir = null)
Method snmpwalk_cache_index
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function snmpwalk_cache_index($device, $oid, $array = [], $mib = null, $mibdir = null)
Method snmp_get
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function snmp_get($device, $oid, $options = null, $mib = null, $mibdir = null)
Method snmp_walk
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function snmp_walk($device, $oid, $options = null, $mib = null, $mibdir = null)
Method gen_snmpwalk_cmd
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function gen_snmpwalk_cmd($device, $oids, $options = null, $mib = null, $mibdir = null)
Method gen_snmpget_cmd
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function gen_snmpget_cmd($device, $oids, $options = null, $mib = null, $mibdir = null)
Method snmp_getnext
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function snmp_getnext($device, $oid, $options = null, $mib = null, $mibdir = null)
Method snmpwalk_cache_oid_num
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function snmpwalk_cache_oid_num($device, $oid, $array = [], $mib = null, $mibdir = null)
Function snmp_translate
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
function snmp_translate($oid, $mib = 'ALL', $mibdir = null, $options = null, $device = null)
{
if (empty($oid)) {
return '';
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function snmp_walk
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
function snmp_walk($device, $oid, $options = null, $mib = null, $mibdir = null)
{
$measure = Measurement::start('snmpwalk');
$cmd = gen_snmpwalk_cmd($device, $oid, $options, $mib, $mibdir);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function snmp_get
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
function snmp_get($device, $oid, $options = null, $mib = null, $mibdir = null)
{
$measure = Measurement::start('snmpget');
if (strstr($oid, ' ')) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
The function get_mib_dir() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
function get_mib_dir($device)
{
$dirs = [];
if (isset($device['os']) && file_exists(Config::get('mib_dir') . '/' . $device['os'])) {
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The function snmpwalk_cache_multi_oid() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
function snmpwalk_cache_multi_oid($device, $oid, $array = [], $mib = null, $mibdir = null, $snmpflags = '-OQUs')
{
global $cache;
if (! (is_array($cache['snmp'][$device['device_id']] ?? null) && array_key_exists($oid, $cache['snmp'][$device['device_id']]))) {
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Missing class import via use statement (line '286', column '19'). Open
throw new Exception("snmp_get called for multiple OIDs: $oid");
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Avoid assigning values to variables in if clauses and the like (line '50', column '13'). Open
function get_mib_dir($device)
{
$dirs = [];
if (isset($device['os']) && file_exists(Config::get('mib_dir') . '/' . $device['os'])) {
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
The method snmp_get_multi_oid uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$array[$oid] = $entry;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method snmp_translate uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if ($mib != 'ALL' && ! Str::contains($oid, '::')) {
$oid = "$mib::$oid";
}
$default_options = ['-On', '-Pu'];
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method snmp_get uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return false;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method snmp_getnext_multi uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$array[$oid] = $value;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method snmp_walk uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if (Str::endsWith($data, '(It is past the end of the MIB tree)')) {
$no_more_pattern = '/.*No more variables left in this MIB View \(It is past the end of the MIB tree\)[\n]?/';
$data = preg_replace($no_more_pattern, '', $data);
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method snmp_get_multi_oid uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if (isset($array[$oid])) {
// if appending, add a line return
$array[$oid] .= PHP_EOL . $entry;
} else {
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method snmp_gen_auth uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
d_echo('DEBUG: ' . $device['snmpver'] . " : Unsupported SNMP Version (shouldn't be possible to get here)\n");
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid assigning values to variables in if clauses and the like (line '59', column '34'). Open
function get_mib_dir($device)
{
$dirs = [];
if (isset($device['os']) && file_exists(Config::get('mib_dir') . '/' . $device['os'])) {
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
The method gen_snmpwalk_cmd uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$snmpcmd = [Config::get('snmpbulkwalk')];
$max_repeaters = get_device_max_repeaters($device);
if ($max_repeaters > 0) {
$snmpcmd[] = "-Cr$max_repeaters";
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method snmp_gen_auth uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
d_echo('DEBUG: ' . $device['snmpver'] . " : Unsupported SNMPv3 AuthLevel (wtf have you done ?)\n");
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method snmp_get_multi uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$array[$index][$oid] = $value;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid unused local variables such as '$snmpflags'. Open
return snmpwalk_cache_oid($device, $oid, $array, $mib, $mibdir, $snmpflags = '-OQUn');
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid unused local variables such as '$k'. Open
foreach ($group_mibdir as $k => $dir) {
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}