XoopsModules25x/about

View on GitHub
class/Tree.php

Summary

Maintainability
C
7 hrs
Test Coverage

Function getAllChildArray has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

        public function getAllChildArray($key, &$ret, $tags = [], $depth = 0)
        {
            if (0 == --$depth) {
                return;
            }
Severity: Minor
Found in class/Tree.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 makeTreeItems has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

        public function makeTreeItems($key, &$ret, $prefix_orig, $prefix_curr = '', $tags = null)
        {
            if ($key > 0) {
                if ($tags && \is_array($tags)) {
                    foreach ($tags as $tag) {
Severity: Minor
Found in class/Tree.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

Method makeSelBox has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

            $name,
            $fieldName,
            $prefix = '-',
            $selected = '',
            $addEmptyOption = false,
Severity: Major
Found in class/Tree.php - About 50 mins to fix

    Method makeTreeItems has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

            public function makeTreeItems($key, &$ret, $prefix_orig, $prefix_curr = '', $tags = null)
    Severity: Minor
    Found in class/Tree.php - About 35 mins to fix

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

                  $addEmptyOption = false,
      Severity: Minor
      Found in class/Tree.php by phpmd

      BooleanArgumentFlag

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

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

                      } else {
                          $ret[$key]['page_title'] = $this->tree[$key]['obj']->getVar('page_title');
                      }
      Severity: Minor
      Found in class/Tree.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 getAllChildArray uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                              } else {
                                  $ret['child'][$childkey]['page_title'] = $this->tree[$childkey]['obj']->getVar('page_title');
                              }
      Severity: Minor
      Found in class/Tree.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 '$fieldName'.
      Open

                  $fieldName,
      Severity: Minor
      Found in class/Tree.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 '$extra'.
      Open

                  $extra = ''
      Severity: Minor
      Found in class/Tree.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

      The parameter $prefix_curr is not named in camelCase.
      Open

              public function makeTreeItems($key, &$ret, $prefix_orig, $prefix_curr = '', $tags = null)
              {
                  if ($key > 0) {
                      if ($tags && \is_array($tags)) {
                          foreach ($tags as $tag) {
      Severity: Minor
      Found in class/Tree.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 $prefix_orig is not named in camelCase.
      Open

              public function makeTreeItems($key, &$ret, $prefix_orig, $prefix_curr = '', $tags = null)
              {
                  if ($key > 0) {
                      if ($tags && \is_array($tags)) {
                          foreach ($tags as $tag) {
      Severity: Minor
      Found in class/Tree.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

      A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 13 and the first side effect is on line 7.
      Open

      <?php
      Severity: Minor
      Found in class/Tree.php by phpcodesniffer

      There must be one blank line after the namespace declaration
      Open

      namespace XoopsModules\About;
      Severity: Minor
      Found in class/Tree.php by phpcodesniffer

      Line exceeds 120 characters; contains 121 characters
      Open

                                  $ret['child'][$childkey]['page_title'] = $this->tree[$childkey]['obj']->getVar('page_title');
      Severity: Minor
      Found in class/Tree.php by phpcodesniffer

      Expected 1 space after closing parenthesis; found 0
      Open

                          if (isset($this->tree[$childkey]['obj'])):
      Severity: Minor
      Found in class/Tree.php by phpcodesniffer

      The variable $prefix_curr is not named in camelCase.
      Open

              public function makeTreeItems($key, &$ret, $prefix_orig, $prefix_curr = '', $tags = null)
              {
                  if ($key > 0) {
                      if ($tags && \is_array($tags)) {
                          foreach ($tags as $tag) {
      Severity: Minor
      Found in class/Tree.php by phpmd

      CamelCaseVariableName

      Since: 0.2

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

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      The variable $prefix_curr is not named in camelCase.
      Open

              public function makeTreeItems($key, &$ret, $prefix_orig, $prefix_curr = '', $tags = null)
              {
                  if ($key > 0) {
                      if ($tags && \is_array($tags)) {
                          foreach ($tags as $tag) {
      Severity: Minor
      Found in class/Tree.php by phpmd

      CamelCaseVariableName

      Since: 0.2

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

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      The variable $prefix_curr is not named in camelCase.
      Open

              public function makeTreeItems($key, &$ret, $prefix_orig, $prefix_curr = '', $tags = null)
              {
                  if ($key > 0) {
                      if ($tags && \is_array($tags)) {
                          foreach ($tags as $tag) {
      Severity: Minor
      Found in class/Tree.php by phpmd

      CamelCaseVariableName

      Since: 0.2

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

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      The variable $prefix_orig is not named in camelCase.
      Open

              public function makeTreeItems($key, &$ret, $prefix_orig, $prefix_curr = '', $tags = null)
              {
                  if ($key > 0) {
                      if ($tags && \is_array($tags)) {
                          foreach ($tags as $tag) {
      Severity: Minor
      Found in class/Tree.php by phpmd

      CamelCaseVariableName

      Since: 0.2

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

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      The variable $prefix_orig is not named in camelCase.
      Open

              public function makeTreeItems($key, &$ret, $prefix_orig, $prefix_curr = '', $tags = null)
              {
                  if ($key > 0) {
                      if ($tags && \is_array($tags)) {
                          foreach ($tags as $tag) {
      Severity: Minor
      Found in class/Tree.php by phpmd

      CamelCaseVariableName

      Since: 0.2

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

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      There are no issues that match your filters.

      Category
      Status