File ModuleTestHelper.php
has 550 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* ModuleTester.php
*
* -Description-
Function convertSnmpToSnmprec
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring. Open
private function convertSnmpToSnmprec(SnmpResponse $snmp_data): array
{
$result = [];
foreach (explode(PHP_EOL, $snmp_data->raw) as $line) {
if (empty($line)) {
- 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 generateTestData
has 99 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function generateTestData(Snmpsim $snmpsim, $no_save = false)
{
global $device;
Config::set('rrd.enable', false); // disable rrd
Config::set('rrdtool_version', '1.7.2'); // don't detect rrdtool version, rrdtool is not install on ci
The class ModuleTestHelper has an overall complexity of 108 which is very high. The configured complexity threshold is 50. Open
class ModuleTestHelper
{
private $quiet = false;
private $modules;
private $variant;
- Exclude checks
Function generateTestData
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
public function generateTestData(Snmpsim $snmpsim, $no_save = false)
{
global $device;
Config::set('rrd.enable', false); // disable rrd
Config::set('rrdtool_version', '1.7.2'); // don't detect rrdtool version, rrdtool is not install on ci
- 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
ModuleTestHelper
has 25 functions (exceeds 20 allowed). Consider refactoring. Open
class ModuleTestHelper
{
private $quiet = false;
private $modules;
private $variant;
Function findOsWithData
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public static function findOsWithData($modules = [], string $os_filter = null)
{
$os_list = [];
foreach (glob(Config::get('install_dir') . '/tests/data/*.json') as $file) {
- 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 collectOids
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function collectOids($device_id)
{
global $device;
$device = device_by_id_cache($device_id);
Function captureFromDevice
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function captureFromDevice(int $device_id, bool $prefer_new = false, bool $full = false): void
{
if ($full) {
$snmp_oids[][] = [
'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
Method convertSnmpToSnmprec
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function convertSnmpToSnmprec(SnmpResponse $snmp_data): array
{
$result = [];
foreach (explode(PHP_EOL, $snmp_data->raw) as $line) {
if (empty($line)) {
Method findOsWithData
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function findOsWithData($modules = [], string $os_filter = null)
{
$os_list = [];
foreach (glob(Config::get('install_dir') . '/tests/data/*.json') as $file) {
Method saveSnmprec
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function saveSnmprec(array $data, ?string $context = null, bool $write = true, bool $prefer_new = false): string
{
$filename = $this->snmprec_file;
if ($context) {
Method captureFromDevice
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function captureFromDevice(int $device_id, bool $prefer_new = false, bool $full = false): void
{
if ($full) {
$snmp_oids[][] = [
'oid' => '.',
Function saveSnmprec
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function saveSnmprec(array $data, ?string $context = null, bool $write = true, bool $prefer_new = false): string
{
$filename = $this->snmprec_file;
if ($context) {
- 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 cleanSnmprecData
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private function cleanSnmprecData(&$data)
{
$private_oid = [
'1.3.6.1.2.1.1.6.0',
'1.3.6.1.2.1.1.4.0',
- 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 method generateTestData() has an NPath complexity of 3072. The configured NPath complexity threshold is 200. Open
public function generateTestData(Snmpsim $snmpsim, $no_save = false)
{
global $device;
Config::set('rrd.enable', false); // disable rrd
Config::set('rrdtool_version', '1.7.2'); // don't detect rrdtool version, rrdtool is not install on ci
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method generateTestData() has 142 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function generateTestData(Snmpsim $snmpsim, $no_save = false)
{
global $device;
Config::set('rrd.enable', false); // disable rrd
Config::set('rrdtool_version', '1.7.2'); // don't detect rrdtool version, rrdtool is not install on ci
- Exclude checks
The method generateTestData() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10. Open
public function generateTestData(Snmpsim $snmpsim, $no_save = false)
{
global $device;
Config::set('rrd.enable', false); // disable rrd
Config::set('rrdtool_version', '1.7.2'); // don't detect rrdtool version, rrdtool is not install on ci
- 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 method convertSnmpToSnmprec() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. Open
private function convertSnmpToSnmprec(SnmpResponse $snmp_data): array
{
$result = [];
foreach (explode(PHP_EOL, $snmp_data->raw) as $line) {
if (empty($line)) {
- 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 class ModuleTestHelper has a coupling between objects value of 20. Consider to reduce the number of dependencies under 13. Open
class ModuleTestHelper
{
private $quiet = false;
private $modules;
private $variant;
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
The method setQuiet has a boolean flag argument $quiet, which is a certain sign of a Single Responsibility Principle violation. Open
public function setQuiet($quiet = true)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method getJsonFilepath has a boolean flag argument $short, which is a certain sign of a Single Responsibility Principle violation. Open
public function getJsonFilepath($short = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method saveSnmprec has a boolean flag argument $prefer_new, which is a certain sign of a Single Responsibility Principle violation. Open
private function saveSnmprec(array $data, ?string $context = null, bool $write = true, bool $prefer_new = false): string
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method captureFromDevice has a boolean flag argument $prefer_new, which is a certain sign of a Single Responsibility Principle violation. Open
public function captureFromDevice(int $device_id, bool $prefer_new = false, bool $full = false): void
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method saveSnmprec has a boolean flag argument $write, which is a certain sign of a Single Responsibility Principle violation. Open
private function saveSnmprec(array $data, ?string $context = null, bool $write = true, bool $prefer_new = false): string
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method generateTestData has a boolean flag argument $no_save, which is a certain sign of a Single Responsibility Principle violation. Open
public function generateTestData(Snmpsim $snmpsim, $no_save = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method captureFromDevice has a boolean flag argument $full, which is a certain sign of a Single Responsibility Principle violation. Open
public function captureFromDevice(int $device_id, bool $prefer_new = false, bool $full = false): void
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method qPrint uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
echo $var;
}
- 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 convertSnmpToSnmprec uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$result[key($result)] = "$oid|4x|" . bin2hex($data . PHP_EOL . $line);
}
- 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 convertSnmpToSnmprec uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
// multi-line data, append to last
$last = end($result);
[$oid, $type, $data] = explode('|', $last, 3);
- 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 saveSnmprec uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$results = array_merge($new_data, $existing_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
Avoid assigning values to variables in if clauses and the like (line '563', column '14'). Open
public function generateTestData(Snmpsim $snmpsim, $no_save = false)
{
global $device;
Config::set('rrd.enable', false); // disable rrd
Config::set('rrdtool_version', '1.7.2'); // don't detect rrdtool version, rrdtool is not install on ci
- 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 getDiscoveryOutput uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return "Module $module not run. Modules: " . implode(',', array_keys($this->poller_module_output));
}
- 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 saveSnmprec uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$existing_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 findOsWithData uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$valid_modules = array_intersect($modules, $data_modules);
}
- 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 getPollerOutput uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return "Module $module not run. Modules: " . implode(',', array_keys($this->poller_module_output));
}
- 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 saveSnmprec uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->qPrint("\nSaved snmprec data $filename\n");
file_put_contents($filename, $output);
}
- 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 convertSnmpToSnmprec uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
[$raw_type, $data] = explode(':', $raw_data, 2);
if (Str::startsWith($raw_type, 'Wrong Type (should be ')) {
// device returned the wrong type, save the wrong type to emulate the device behavior
[$raw_type, $data] = explode(':', ltrim($data), 2);
- 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 generateTestData uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$existing_data[$module] = $module_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 captureFromDevice uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$snmp_oids = $this->collectOids($device_id);
}
- 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 extractVariant uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
[$rvar, $ros] = explode('_', strrev($full_name), 2);
return [strrev($ros), strrev($rvar)];
}
- 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 generateTestData uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
ob_flush();
}
- 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 generateTestData uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
ob_flush();
}
- 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 parameters such as '$app'. Open
app()->bind(\LibreNMS\Util\AutonomousSystem::class, function ($app, $parameters) {
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused private methods such as 'compareOid'. Open
private static function compareOid($a, $b)
{
$a_oid = explode('.', $a);
$b_oid = explode('.', $b);
- Read upRead up
- Exclude checks
UnusedPrivateMethod
Since: 0.2
Unused Private Method detects when a private method is declared but is unused.
Example
class Something
{
private function foo() {} // unused
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatemethod
The method findOsWithData() contains an exit expression. Open
exit(1);
- Read upRead up
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}
Source https://phpmd.org/rules/design.html#exitexpression
Avoid excessively long variable names like $discovery_module_output. Keep variable name length under 20. Open
private $discovery_module_output = [];
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
The property $exclude_from_all is not named in camelCase. Open
class ModuleTestHelper
{
private $quiet = false;
private $modules;
private $variant;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $discovery_module_output is not named in camelCase. Open
class ModuleTestHelper
{
private $quiet = false;
private $modules;
private $variant;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $discovery_output is not named in camelCase. Open
class ModuleTestHelper
{
private $quiet = false;
private $modules;
private $variant;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
Avoid variables with short names like $os. Configured minimum length is 3. Open
[$os, $variant] = self::extractVariant($file);
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The property $snmprec_file is not named in camelCase. Open
class ModuleTestHelper
{
private $quiet = false;
private $modules;
private $variant;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $json_file is not named in camelCase. Open
class ModuleTestHelper
{
private $quiet = false;
private $modules;
private $variant;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
Avoid variables with short names like $a. Configured minimum length is 3. Open
private static function compareOid($a, $b)
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The property $snmprec_dir is not named in camelCase. Open
class ModuleTestHelper
{
private $quiet = false;
private $modules;
private $variant;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $json_dir is not named in camelCase. Open
class ModuleTestHelper
{
private $quiet = false;
private $modules;
private $variant;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $poller_output is not named in camelCase. Open
class ModuleTestHelper
{
private $quiet = false;
private $modules;
private $variant;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
Avoid variables with short names like $os. Configured minimum length is 3. Open
public function __construct($modules, $os, $variant = '')
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $b. Configured minimum length is 3. Open
private static function compareOid($a, $b)
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The property $file_name is not named in camelCase. Open
class ModuleTestHelper
{
private $quiet = false;
private $modules;
private $variant;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $poller_module_output is not named in camelCase. Open
class ModuleTestHelper
{
private $quiet = false;
private $modules;
private $variant;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}