librenms/librenms

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

Summary

Maintainability
A
2 hrs
Test Coverage

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

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

    Method contactHue has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function contactHue($obj, $opts)
        {
            // Don't alert on resolve at this time
            if ($obj['state'] == AlertState::RECOVERED) {
                return true;
    Severity: Minor
    Found in LibreNMS/Alert/Transport/Hue.php - About 1 hr to fix

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

              } else {
                  $device = device_by_id_cache($obj['device_id']); // for event logging
                  $hue_user = $opts['user'];
                  $url = $opts['bridge'] . "/api/$hue_user/groups/0/action";
                  $curl = curl_init();
      Severity: Minor
      Found in LibreNMS/Alert/Transport/Hue.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 contactHue uses an else expression. Else is never necessary and you can simplify the code to work without else.
      Open

                  } else {
                      d_echo('Hue bridge connection error: ' . serialize($ret));
      
                      return false;
                  }
      Severity: Minor
      Found in LibreNMS/Alert/Transport/Hue.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

      There are no issues that match your filters.

      Category
      Status