LibreNMS/Snmptrap/Handlers/Mgnt2TrapNmsAlarm.php
Method handle
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public function handle(Device $device, Trap $trap)
{
$alarmObj = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogObjectClassIdentifier'));
$sourcePm = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSourcePm'));
$slot = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogBoardNumber'));
Avoid unused parameters such as '$device'. Open
Open
public function handle(Device $device, Trap $trap)
- 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
The method handle uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
Open
} else {
$msg = "Alarm on slot $slot, $sourcePm Issue: $probSpecific Possible Cause: $probCause";
}
- 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
Space before opening parenthesis of function call prohibited Open
Open
$severity = match ($alarmSeverity) {
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
Open
default => Severity::Info,
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
Open
$trap->log($msg, $severity);
- Exclude checks