librenms/librenms

View on GitHub
LibreNMS/Alert/Transport/Alertmanager.php

Summary

Maintainability
A
1 hr
Test Coverage

Method contactAlertmanager has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function contactAlertmanager($obj, $api)
    {
        if ($obj['state'] == AlertState::RECOVERED) {
            $alertmanager_status = 'endsAt';
        } else {
Severity: Minor
Found in LibreNMS/Alert/Transport/Alertmanager.php - About 1 hr to fix

    Avoid unused parameters such as '$opts'.
    Open

        public function deliverAlert($obj, $opts)

    Since: PHPMD 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: http://phpmd.org/rules/unusedcode.txt

    Avoid unused local variables such as '$ret'.
    Open

            $ret = curl_exec($curl);

    Since: PHPMD 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: http://phpmd.org/rules/unusedcode.txt

    The method contactAlertmanager uses an else expression. Else is never necessary and you can simplify the code to work without else.
    Open

            } else {
                $alertmanager_status = 'startsAt';
            }

    Since: PHPMD 1.4.0

    An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements. To achieve this 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: http://phpmd.org/rules/cleancode.txt

    There are no issues that match your filters.

    Category
    Status