librenms/librenms

View on GitHub
LibreNMS/Snmptrap/Handlers/Mgnt2TrapNmsAlarm.php

Summary

Maintainability
A
1 hr
Test Coverage

Method handle has 28 lines of code (exceeds 25 allowed). Consider refactoring.
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'));
Severity: Minor
Found in LibreNMS/Snmptrap/Handlers/Mgnt2TrapNmsAlarm.php - About 1 hr to fix

    Avoid unused parameters such as '$device'.
    Open

        public function handle(Device $device, Trap $trap)

    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

            } else {
                $msg = "Alarm on slot $slot, $sourcePm Issue: $probSpecific Possible Cause: $probCause";
            }

    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

            $severity = match ($alarmSeverity) {

    Line indented incorrectly; expected 8 spaces, found 12
    Open

                default => Severity::Info,

    Line indented incorrectly; expected at least 12 spaces, found 8
    Open

            $trap->log($msg, $severity);

    There are no issues that match your filters.

    Category
    Status