librenms/librenms

View on GitHub
LibreNMS/Alert/RunAlerts.php

Summary

Maintainability
F
6 days
Test Coverage

Function runAlerts has a Cognitive Complexity of 67 (exceeds 5 allowed). Consider refactoring.
Open

    public function runAlerts()
    {
        foreach ($this->loadAlerts('alerts.state != ' . AlertState::ACKNOWLEDGED . ' && alerts.open = 1') as $alert) {
            $noiss = false;
            $noacc = false;
Severity: Minor
Found in LibreNMS/Alert/RunAlerts.php - About 1 day 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

File RunAlerts.php has 444 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/*
 * RunAlerts.php
 *
 * Copyright (C) 2014 Daniel Preussker <f0o@devilcode.org>
Severity: Minor
Found in LibreNMS/Alert/RunAlerts.php - About 6 hrs to fix

    Function describeAlert has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
    Open

        public function describeAlert($alert)
        {
            $obj = [];
            $i = 0;
            $device = dbFetchRow('SELECT hostname, sysName, sysDescr, sysContact, os, type, ip, hardware, version, purpose, notes, uptime, status, status_reason, locations.location FROM devices LEFT JOIN locations ON locations.id = devices.location_id WHERE device_id = ?', [$alert['device_id']]);
    Severity: Minor
    Found in LibreNMS/Alert/RunAlerts.php - About 5 hrs 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

    Function runFollowUp has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

        public function runFollowUp()
        {
            foreach ($this->loadAlerts('alerts.state > ' . AlertState::CLEAR . ' && alerts.open = 0') as $alert) {
                if ($alert['state'] != AlertState::ACKNOWLEDGED || ($alert['info']['until_clear'] === false)) {
                    $rextra = json_decode($alert['extra'], true);
    Severity: Minor
    Found in LibreNMS/Alert/RunAlerts.php - About 4 hrs 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

    Method describeAlert has 101 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function describeAlert($alert)
        {
            $obj = [];
            $i = 0;
            $device = dbFetchRow('SELECT hostname, sysName, sysDescr, sysContact, os, type, ip, hardware, version, purpose, notes, uptime, status, status_reason, locations.location FROM devices LEFT JOIN locations ON locations.id = devices.location_id WHERE device_id = ?', [$alert['device_id']]);
    Severity: Major
    Found in LibreNMS/Alert/RunAlerts.php - About 4 hrs to fix

      The class RunAlerts has an overall complexity of 127 which is very high. The configured complexity threshold is 50.
      Open

      class RunAlerts
      {
          /**
           * Populate variables
           * @param string  $txt  Text with variables
      Severity: Minor
      Found in LibreNMS/Alert/RunAlerts.php by phpmd

      Since: PHPMD 0.2.5

      The Weighted Method Count (WMC) of a class is a good indicator of how much time and effort is required to modify and maintain this class. The WMC metric is defined as the sum of complexities of all methods declared in a class. A large number of methods also means that this class has a greater potential impact on derived classes.

      Example:

      class Foo {
            public function bar() {
                if ($a == $b)  {
                    if ($a1 == $b1) {
                        fiddle();
                    } elseif ($a2 == $b2) {
                        fiddle();
                    } else {
                    }
                }
            }
            public function baz() {
                if ($a == $b) {
                    if ($a1 == $b1) {
                        fiddle();
                    } elseif ($a2 == $b2) {
                        fiddle();
                    } else {
                    }
                }
            }
            // Several other complex methods
        }

      Source: http://phpmd.org/rules/codesize.txt

      The class RunAlerts has 13 public methods. Consider refactoring RunAlerts to keep number of public methods under 10.
      Open

      class RunAlerts
      {
          /**
           * Populate variables
           * @param string  $txt  Text with variables
      Severity: Minor
      Found in LibreNMS/Alert/RunAlerts.php by phpmd

      Since: PHPMD 0.1

      A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects. By default it ignores methods starting with 'get' or 'set'.

      Source: http://phpmd.org/rules/codesize.txt

      Method runAlerts has 80 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function runAlerts()
          {
              foreach ($this->loadAlerts('alerts.state != ' . AlertState::ACKNOWLEDGED . ' && alerts.open = 1') as $alert) {
                  $noiss = false;
                  $noacc = false;
      Severity: Major
      Found in LibreNMS/Alert/RunAlerts.php - About 3 hrs to fix

        Method runFollowUp has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function runFollowUp()
            {
                foreach ($this->loadAlerts('alerts.state > ' . AlertState::CLEAR . ' && alerts.open = 0') as $alert) {
                    if ($alert['state'] != AlertState::ACKNOWLEDGED || ($alert['info']['until_clear'] === false)) {
                        $rextra = json_decode($alert['extra'], true);
        Severity: Minor
        Found in LibreNMS/Alert/RunAlerts.php - About 1 hr to fix

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

              public function extTransports($obj)
              {
                  $type = new Template;
          
                  // If alert transport mapping exists, override the default transports
          Severity: Minor
          Found in LibreNMS/Alert/RunAlerts.php - About 1 hr to fix

            Function populate has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                public function populate($txt, $wrap = true)
                {
                    preg_match_all('/%([\w\.]+)/', $txt, $m);
                    foreach ($m[1] as $tmp) {
                        $orig = $tmp;
            Severity: Minor
            Found in LibreNMS/Alert/RunAlerts.php - About 1 hr 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

            Function extTransports has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                public function extTransports($obj)
                {
                    $type = new Template;
            
                    // If alert transport mapping exists, override the default transports
            Severity: Minor
            Found in LibreNMS/Alert/RunAlerts.php - About 1 hr 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

            Method alertLog has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function alertLog($result, $obj, $transport)
                {
                    $prefix = [
                        AlertState::RECOVERED => 'recovery',
                        AlertState::ACTIVE => $obj['severity'] . ' alert',
            Severity: Minor
            Found in LibreNMS/Alert/RunAlerts.php - About 1 hr to fix

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

                  public function loadAlerts($where)
                  {
                      $alerts = [];
                      foreach (dbFetchRows("SELECT alerts.id, alerts.alerted, alerts.device_id, alerts.rule_id, alerts.state, alerts.note, alerts.info FROM alerts WHERE $where") as $alert_status) {
                          $alert = dbFetchRow(
              Severity: Minor
              Found in LibreNMS/Alert/RunAlerts.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

              Consider simplifying this complex logical expression.
              Open

                                  if (! empty($v) && $k != 'device_id' && (stristr($k, 'id') || stristr($k, 'desc') || stristr($k, 'msg')) && substr_count($k, '_') <= 1) {
                                      $obj['faults'][$i]['string'] .= $k . ' => ' . $v . '; ';
                                  }
              Severity: Major
              Found in LibreNMS/Alert/RunAlerts.php - About 40 mins to fix

                Consider simplifying this complex logical expression.
                Open

                                    if (! empty($v) && $k != 'device_id' && (stristr($k, 'id') || stristr($k, 'desc') || stristr($k, 'msg')) && substr_count($k, '_') <= 1) {
                                        $obj['faults'][$i]['string'] .= $k . ' = ' . $v . '; ';
                                    }
                Severity: Major
                Found in LibreNMS/Alert/RunAlerts.php - About 40 mins to fix

                  Function alertLog has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function alertLog($result, $obj, $transport)
                      {
                          $prefix = [
                              AlertState::RECOVERED => 'recovery',
                              AlertState::ACTIVE => $obj['severity'] . ' alert',
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php - About 35 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

                  The method describeAlert() has 114 lines of code. Current threshold is set to 100. Avoid really long methods.
                  Open

                      public function describeAlert($alert)
                      {
                          $obj = [];
                          $i = 0;
                          $device = dbFetchRow('SELECT hostname, sysName, sysDescr, sysContact, os, type, ip, hardware, version, purpose, notes, uptime, status, status_reason, locations.location FROM devices LEFT JOIN locations ON locations.id = devices.location_id WHERE device_id = ?', [$alert['device_id']]);
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

                  The method runAlerts() has 102 lines of code. Current threshold is set to 100. Avoid really long methods.
                  Open

                      public function runAlerts()
                      {
                          foreach ($this->loadAlerts('alerts.state != ' . AlertState::ACKNOWLEDGED . ' && alerts.open = 1') as $alert) {
                              $noiss = false;
                              $noacc = false;
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

                  The method runAlerts() has an NPath complexity of 306433. The configured NPath complexity threshold is 200.
                  Open

                      public function runAlerts()
                      {
                          foreach ($this->loadAlerts('alerts.state != ' . AlertState::ACKNOWLEDGED . ' && alerts.open = 1') as $alert) {
                              $noiss = false;
                              $noacc = false;
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

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

                  The method describeAlert() has an NPath complexity of 866. The configured NPath complexity threshold is 200.
                  Open

                      public function describeAlert($alert)
                      {
                          $obj = [];
                          $i = 0;
                          $device = dbFetchRow('SELECT hostname, sysName, sysDescr, sysContact, os, type, ip, hardware, version, purpose, notes, uptime, status, status_reason, locations.location FROM devices LEFT JOIN locations ON locations.id = devices.location_id WHERE device_id = ?', [$alert['device_id']]);
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

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

                  The method runAlerts() has a Cyclomatic Complexity of 37. The configured cyclomatic complexity threshold is 10.
                  Open

                      public function runAlerts()
                      {
                          foreach ($this->loadAlerts('alerts.state != ' . AlertState::ACKNOWLEDGED . ' && alerts.open = 1') as $alert) {
                              $noiss = false;
                              $noacc = false;
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

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

                  The method runFollowUp() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
                  Open

                      public function runFollowUp()
                      {
                          foreach ($this->loadAlerts('alerts.state > ' . AlertState::CLEAR . ' && alerts.open = 0') as $alert) {
                              if ($alert['state'] != AlertState::ACKNOWLEDGED || ($alert['info']['until_clear'] === false)) {
                                  $rextra = json_decode($alert['extra'], true);
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

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

                  The method describeAlert() has a Cyclomatic Complexity of 30. The configured cyclomatic complexity threshold is 10.
                  Open

                      public function describeAlert($alert)
                      {
                          $obj = [];
                          $i = 0;
                          $device = dbFetchRow('SELECT hostname, sysName, sysDescr, sysContact, os, type, ip, hardware, version, purpose, notes, uptime, status, status_reason, locations.location FROM devices LEFT JOIN locations ON locations.id = devices.location_id WHERE device_id = ?', [$alert['device_id']]);
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

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

                  The method populate has a boolean flag argument $wrap, which is a certain sign of a Single Responsibility Principle violation.
                  Open

                      public function populate($txt, $wrap = true)
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

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

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

                              } else {
                                  $alert['alert_id'] = $alert_status['id'];
                                  $alert['state'] = $alert_status['state'];
                                  $alert['alerted'] = $alert_status['alerted'];
                                  $alert['note'] = $alert_status['note'];
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

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

                                  } else {
                                      $pre = '$obj';
                                  }
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

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

                                      } else {
                                          $alert['details']['delay'] = time();
                                          $updet = true;
                                      }
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

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

                                      } else {
                                          $alert['details']['interval'] = time();
                                          $updet = true;
                                      }
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

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

                          } else {
                              $severity = Alert::UNKNOWN;
                          }
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

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

                              } else {
                                  // This is the new way
                                  if (! empty($rextra['delay']) && (time() - strtotime($alert['time_logged']) + $tolerence_window) < $rextra['delay'] && $alert['state'] != AlertState::RECOVERED) {
                                      continue;
                                  }
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

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

                          } else {
                              echo "ERROR: $result\r\n";
                              Log::event('Could not issue ' . $prefix[$obj['state']] . " for rule '" . $obj['name'] . "' to transport '" . $transport . "' Error: " . $result, $obj['device_id'], 'error', Alert::ERROR);
                          }
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

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

                              } else {
                                  if (strstr($tmp, '.')) {
                                      $tmp = explode('.', $tmp, 2);
                                      $pre = '$' . $tmp[0];
                                      $tmp = $tmp[1];
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

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

                          } else {
                              return 'Unknown State';
                          }//end if
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

                  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

                  FIXME found
                  Open

                                  //FIXME remove Deprecated transport
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by fixme

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                                  foreach ($incident as $k => $v) {
                                      if (! empty($v) && $k != 'device_id' && (stristr($k, 'id') || stristr($k, 'desc') || stristr($k, 'msg')) && substr_count($k, '_') <= 1) {
                                          $obj['faults'][$i]['string'] .= $k . ' => ' . $v . '; ';
                                      }
                                  }
                  Severity: Major
                  Found in LibreNMS/Alert/RunAlerts.php and 1 other location - About 2 hrs to fix
                  LibreNMS/Alert/RunAlerts.php on lines 141..145

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 114.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                                  foreach ($incident as $k => $v) {
                                      if (! empty($v) && $k != 'device_id' && (stristr($k, 'id') || stristr($k, 'desc') || stristr($k, 'msg')) && substr_count($k, '_') <= 1) {
                                          $obj['faults'][$i]['string'] .= $k . ' = ' . $v . '; ';
                                      }
                                  }
                  Severity: Major
                  Found in LibreNMS/Alert/RunAlerts.php and 1 other location - About 2 hrs to fix
                  LibreNMS/Alert/RunAlerts.php on lines 173..177

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 114.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Avoid variables with short names like $m. Configured minimum length is 3.
                  Open

                          preg_match_all('/%([\w\.]+)/', $txt, $m);
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

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

                  Avoid variables with short names like $id. Configured minimum length is 3.
                  Open

                              $id = dbFetchRow('SELECT alert_log.id,alert_log.time_logged,alert_log.details FROM alert_log WHERE alert_log.state != ? && alert_log.state != ? && alert_log.rule_id = ? && alert_log.device_id = ? && alert_log.id < ? ORDER BY id DESC LIMIT 1', [AlertState::ACKNOWLEDGED, AlertState::RECOVERED, $alert['rule_id'], $alert['device_id'], $alert['id']]);
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

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

                  Avoid variables with short names like $i. Configured minimum length is 3.
                  Open

                          $i = 0;
                  Severity: Minor
                  Found in LibreNMS/Alert/RunAlerts.php by phpmd

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

                  There are no issues that match your filters.

                  Category
                  Status