ampache/ampache

View on GitHub
src/Module/Util/Ui.php

Summary

Maintainability
F
1 wk
Test Coverage

is_grid_view accesses the super-global variable $_COOKIE.
Open

    public static function is_grid_view($type): bool
    {
        $isgv = true;
        $name = 'browse_' . $type . '_grid_view';
        if (isset($_COOKIE[$name])) {
Severity: Minor
Found in src/Module/Util/Ui.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

is_grid_view accesses the super-global variable $_COOKIE.
Open

    public static function is_grid_view($type): bool
    {
        $isgv = true;
        $name = 'browse_' . $type . '_grid_view';
        if (isset($_COOKIE[$name])) {
Severity: Minor
Found in src/Module/Util/Ui.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

Function createPreferenceInput has a Cognitive Complexity of 112 (exceeds 5 allowed). Consider refactoring.
Open

    public function createPreferenceInput(
        string $name,
        $value
    ): void {
        if (!Preference::has_access($name)) {
Severity: Minor
Found in src/Module/Util/Ui.php - About 2 days 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 createPreferenceInput has 505 lines of code (exceeds 200 allowed). Consider refactoring.
Open

    public function createPreferenceInput(
        string $name,
        $value
    ): void {
        if (!Preference::has_access($name)) {
Severity: Major
Found in src/Module/Util/Ui.php - About 1 day to fix

    File Ui.php has 961 lines of code (exceeds 500 allowed). Consider refactoring.
    Open

    <?php
    
    declare(strict_types=0);
    
    /**
    Severity: Major
    Found in src/Module/Util/Ui.php - About 1 day to fix

      Ui has 35 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Ui implements UiInterface
      {
          private static $_ticker;
          private static $_icon_cache;
          private static $_image_cache;
      Severity: Minor
      Found in src/Module/Util/Ui.php - About 4 hrs to fix

        The class Ui has 28 public methods. Consider refactoring Ui to keep number of public methods under 10.
        Open

        class Ui implements UiInterface
        {
            private static $_ticker;
            private static $_icon_cache;
            private static $_image_cache;
        Severity: Minor
        Found in src/Module/Util/Ui.php by phpmd

        TooManyPublicMethods

        Since: 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'.

        Example

        Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

        The class Ui has 30 non-getter- and setter-methods. Consider refactoring Ui to keep number of methods under 25.
        Open

        class Ui implements UiInterface
        {
            private static $_ticker;
            private static $_icon_cache;
            private static $_image_cache;
        Severity: Minor
        Found in src/Module/Util/Ui.php by phpmd

        TooManyMethods

        Since: 0.1

        A class with too many 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'.

        The default was changed from 10 to 25 in PHPMD 2.3.

        Example

        Source https://phpmd.org/rules/codesize.html#toomanymethods

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

        class Ui implements UiInterface
        {
            private static $_ticker;
            private static $_icon_cache;
            private static $_image_cache;
        Severity: Minor
        Found in src/Module/Util/Ui.php by phpmd

        Function get_icon has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function get_icon(string $name, ?string $title = null, ?string $id_attrib = null, ?string $class_attrib = null): string
            {
                $title    = $title ?? T_(ucfirst($name));
                $icon_url = self::_find_icon($name);
                $icontype = pathinfo($icon_url, PATHINFO_EXTENSION);
        Severity: Minor
        Found in src/Module/Util/Ui.php - About 3 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 get_image has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function get_image(string $name, ?string $title = null, ?string $id_attrib = null, ?string $class_attrib = null): string
            {
                $title     = $title ?? ucfirst($name);
                $image_url = self::_find_image($name);
                $imagetype = pathinfo($image_url, PATHINFO_EXTENSION);
        Severity: Minor
        Found in src/Module/Util/Ui.php - About 2 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 format_bytes has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function format_bytes($value, $precision = 2, $pass = 0): string
            {
                if (!$value) {
                    return '';
                }
        Severity: Minor
        Found in src/Module/Util/Ui.php - About 55 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

        Method showConfirmation has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

                $title,
                $text,
                $next_url,
                $cancel = 0,
                $form_name = 'confirmation',
        Severity: Minor
        Found in src/Module/Util/Ui.php - About 45 mins to fix

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

              public static function update_text($field, $value): void
              {
                  if (defined('API')) {
                      return;
                  }
          Severity: Minor
          Found in src/Module/Util/Ui.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

          Function find_template has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function find_template($template, bool $extern = false): string
              {
                  $path      = AmpConfig::get('theme_path') . '/templates/' . $template;
                  $realpath  = __DIR__ . '/../../../public/' . $path;
                  $extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
          Severity: Minor
          Found in src/Module/Util/Ui.php - About 25 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

          Function show_footer has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function show_footer(): void
              {
                  if (!defined("TABLE_RENDERED")) {
                      show_table_render();
                  }
          Severity: Minor
          Found in src/Module/Util/Ui.php - About 25 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 class Ui has 1202 lines of code. Current threshold is 1000. Avoid really long classes.
          Open

          class Ui implements UiInterface
          {
              private static $_ticker;
              private static $_icon_cache;
              private static $_image_cache;
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

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

              public function createPreferenceInput(
                  string $name,
                  $value
              ): void {
                  if (!Preference::has_access($name)) {
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          The method createPreferenceInput() has an NPath complexity of 1332. The configured NPath complexity threshold is 200.
          Open

              public function createPreferenceInput(
                  string $name,
                  $value
              ): void {
                  if (!Preference::has_access($name)) {
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          NPathComplexity

          Since: 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 https://phpmd.org/rules/codesize.html#npathcomplexity

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

              public function createPreferenceInput(
                  string $name,
                  $value
              ): void {
                  if (!Preference::has_access($name)) {
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          CyclomaticComplexity

          Since: 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 https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

          The method createPreferenceInput uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                          } else {
                              $is_sort_default = 'selected="selected"';
                          }
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method find_template uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      if ($extern === true) {
                          return '/templates/' . $template;
                      }
          
          
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method showConfirmation uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      $path = sprintf('%s/%s', $webPath, $next_url);
                  }
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method update_text uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      if (!empty($field)) {
                          echo "<script>updateText('" . $field . "', '" . json_encode($value) . "');</script>\n";
                      } else {
                          echo "<br />" . $value . "<br /><br />\n";
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method createPreferenceInput uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                          } else {
                              echo $value;
                          }
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method createPreferenceInput uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                          } else {
                              $is_false = "selected=\"selected\"";
                          }
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method get_icon uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      // fall back to png
                      $tag = '<img src="' . $icon_url . '" ';
                      $tag .= 'alt="' . $title . '" ';
                      $tag .= 'title="' . $title . '" ';
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method get_image uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                          } else {
                              $svgimage->title = $title;
                          }
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method get_icon uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                          } else {
                              $svgicon->title = $title;
                          }
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method unformat_bytes uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      return (string)$value;
                  }
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method get_icon uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                          } else {
                              $svgicon->desc = $title;
                          }
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method get_image uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                          } else {
                              $svgimage->desc = $title;
                          }
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method update_text uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                      } else {
                          echo "<br />" . $value . "<br /><br />\n";
                      }
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method createPreferenceInput uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                          } else {
                              echo '<input type="text" name="' . $name . '" value="' . strip_tags($value) . '" />';
                          }
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method showContinue uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      $path = sprintf('%s/%s', $webPath, $next_url);
                  }
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method createPreferenceInput uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                      } else {
                          if (preg_match('/_pass$/', $name) || preg_match('/_api_key$/', $name)) {
                              echo "******";
                          } else {
                              echo $value;
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method _find_icon uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      $filename = pathinfo($filesearch[0], PATHINFO_BASENAME);
                  }
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method get_image uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      // fall back to png
                      $tag = '<img src="' . $image_url . '" ';
                      $tag .= 'alt="' . $title . '" ';
                      $tag .= 'title="' . $title . '" ';
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method _find_image uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      $filename = pathinfo($filesearch[0], PATHINFO_BASENAME);
                  }
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          The method printBool uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      $string = '<span class="item_off">' . T_('Off') . '</span>';
                  }
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          Avoid unused parameters such as '$class'.
          Open

              public static function show_box_top($title = '', $class = ''): void
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          Avoid unused parameters such as '$visible'.
          Open

                  $visible = true
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          Avoid unused parameters such as '$fileName'.
          Open

              public function permissionDenied(string $fileName): void
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          Avoid unused parameters such as '$title'.
          Open

              public static function show_box_top($title = '', $class = ''): void
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          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

          syntax error, unexpected 'ConfigContainerInterface' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
          Open

              private ConfigContainerInterface $configContainer;
          Severity: Critical
          Found in src/Module/Util/Ui.php by phan

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

                  if ($imagetype == 'svg') {
                      // load svg file
                      $svgimage = simplexml_load_file($image_url);
                      if ($svgimage !== false) {
                          $svgimage->addAttribute('class', 'image');
          Severity: Major
          Found in src/Module/Util/Ui.php and 1 other location - About 1 hr to fix
          src/Module/Util/Ui.php on lines 280..317

          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 109.

          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

                  if ($icontype == 'svg') {
                      // load svg file
                      $svgicon = simplexml_load_file($icon_url);
                      if ($svgicon !== false) {
                          if (empty($svgicon->title)) {
          Severity: Major
          Found in src/Module/Util/Ui.php and 1 other location - About 1 hr to fix
          src/Module/Util/Ui.php on lines 361..399

          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 109.

          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

          The parameter $next_url is not named in camelCase.
          Open

              public function showContinue(
                  string $title,
                  string $text,
                  string $next_url
              ): void {
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          CamelCaseParameterName

          Since: 0.2

          It is considered best practice to use the camelCase notation to name parameters.

          Example

          class ClassName {
              public function doSomething($user_name) {
              }
          }

          Source

          The parameter $next_url is not named in camelCase.
          Open

              public function showConfirmation(
                  $title,
                  $text,
                  $next_url,
                  $cancel = 0,
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          CamelCaseParameterName

          Since: 0.2

          It is considered best practice to use the camelCase notation to name parameters.

          Example

          class ClassName {
              public function doSomething($user_name) {
              }
          }

          Source

          Avoid classes with short names like Ui. Configured minimum length is 3.
          Open

          class Ui implements UiInterface
          {
              private static $_ticker;
              private static $_icon_cache;
              private static $_image_cache;
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          ShortClassName

          Since: 2.9

          Detects when classes or interfaces have a very short name.

          Example

          class Fo {
          
          }
          
          interface Fo {
          
          }

          Source https://phpmd.org/rules/naming.html#shortclassname

          The parameter $class_attrib is not named in camelCase.
          Open

              public static function get_image(string $name, ?string $title = null, ?string $id_attrib = null, ?string $class_attrib = null): string
              {
                  $title     = $title ?? ucfirst($name);
                  $image_url = self::_find_image($name);
                  $imagetype = pathinfo($image_url, PATHINFO_EXTENSION);
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          CamelCaseParameterName

          Since: 0.2

          It is considered best practice to use the camelCase notation to name parameters.

          Example

          class ClassName {
              public function doSomething($user_name) {
              }
          }

          Source

          The parameter $id_attrib is not named in camelCase.
          Open

              public static function get_icon(string $name, ?string $title = null, ?string $id_attrib = null, ?string $class_attrib = null): string
              {
                  $title    = $title ?? T_(ucfirst($name));
                  $icon_url = self::_find_icon($name);
                  $icontype = pathinfo($icon_url, PATHINFO_EXTENSION);
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          CamelCaseParameterName

          Since: 0.2

          It is considered best practice to use the camelCase notation to name parameters.

          Example

          class ClassName {
              public function doSomething($user_name) {
              }
          }

          Source

          The parameter $id_attrib is not named in camelCase.
          Open

              public static function get_image(string $name, ?string $title = null, ?string $id_attrib = null, ?string $class_attrib = null): string
              {
                  $title     = $title ?? ucfirst($name);
                  $image_url = self::_find_image($name);
                  $imagetype = pathinfo($image_url, PATHINFO_EXTENSION);
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          CamelCaseParameterName

          Since: 0.2

          It is considered best practice to use the camelCase notation to name parameters.

          Example

          class ClassName {
              public function doSomething($user_name) {
              }
          }

          Source

          The parameter $class_attrib is not named in camelCase.
          Open

              public static function get_icon(string $name, ?string $title = null, ?string $id_attrib = null, ?string $class_attrib = null): string
              {
                  $title    = $title ?? T_(ucfirst($name));
                  $icon_url = self::_find_icon($name);
                  $icontype = pathinfo($icon_url, PATHINFO_EXTENSION);
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          CamelCaseParameterName

          Since: 0.2

          It is considered best practice to use the camelCase notation to name parameters.

          Example

          class ClassName {
              public function doSomething($user_name) {
              }
          }

          Source

          The parameter $form_name is not named in camelCase.
          Open

              public function showConfirmation(
                  $title,
                  $text,
                  $next_url,
                  $cancel = 0,
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpmd

          CamelCaseParameterName

          Since: 0.2

          It is considered best practice to use the camelCase notation to name parameters.

          Example

          class ClassName {
              public function doSomething($user_name) {
              }
          }

          Source

          Property name "$_icon_cache" should not be prefixed with an underscore to indicate visibility
          Open

              private static $_icon_cache;
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpcodesniffer

          Method name "_find_image" should not be prefixed with an underscore to indicate visibility
          Open

              private static function _find_image($name): string
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpcodesniffer

          Method name "_find_icon" should not be prefixed with an underscore to indicate visibility
          Open

              private static function _find_icon($name): string
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpcodesniffer

          Property name "$_ticker" should not be prefixed with an underscore to indicate visibility
          Open

              private static $_ticker;
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpcodesniffer

          Property name "$_image_cache" should not be prefixed with an underscore to indicate visibility
          Open

              private static $_image_cache;
          Severity: Minor
          Found in src/Module/Util/Ui.php by phpcodesniffer

          There are no issues that match your filters.

          Category
          Status