librenms/librenms

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

Summary

Maintainability
A
3 hrs
Test Coverage

Method contactCiscospark has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function contactCiscospark($obj, $room_id, $token)
    {
        $text = null;
        $data = [
            'roomId' => $room_id,
Severity: Minor
Found in LibreNMS/Alert/Transport/Ciscospark.php - About 1 hr to fix

    Method configTemplate has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function configTemplate()
        {
            return [
                'config' => [
                    [
    Severity: Minor
    Found in LibreNMS/Alert/Transport/Ciscospark.php - About 1 hr to fix

      Function contactCiscospark has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          public function contactCiscospark($obj, $room_id, $token)
          {
              $text = null;
              $data = [
                  'roomId' => $room_id,
      Severity: Minor
      Found in LibreNMS/Alert/Transport/Ciscospark.php - About 45 mins to fix

      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

      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 contactCiscospark uses an else expression. Else is never necessary and you can simplify the code to work without else.
      Open

              } else {
                  $text = strip_tags($obj['msg']);
              }

      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

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

              } else {
                  $room_id = $this->config['room-id'];
                  $token = $this->config['api-token'];
              }

      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