attogram/attogram-modulemanager

View on GitHub
includes/ModuleManager.php

Summary

Maintainability
B
5 hrs
Test Coverage

Method moduleRow has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function moduleRow($moduleBaseName, $moduleInfo, $enabled = true)
    {
        $homepage = (
            isset($moduleInfo['homepage'])
            ? '<br /><a href="'.$moduleInfo['homepage'].'">'.$moduleInfo['homepage'].'</a>'
Severity: Minor
Found in includes/ModuleManager.php - About 1 hr to fix

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

        public function getModuleInfo($moduleDir)
        {
            $result['basename'] = basename($moduleDir);
            $result['name'] = $result['basename'];
            $result['description'] = '';
    Severity: Minor
    Found in includes/ModuleManager.php - About 1 hr to fix

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

          private function getModuleList($directory)
          {
              $modules = array();
              $directories = array_diff(
                  scandir($directory),
      Severity: Minor
      Found in includes/ModuleManager.php - About 1 hr to fix

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

            private function getModuleList($directory)
            {
                $modules = array();
                $directories = array_diff(
                    scandir($directory),
        Severity: Minor
        Found in includes/ModuleManager.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

        Avoid too many return statements within this method.
        Open

                return true;
        Severity: Major
        Found in includes/ModuleManager.php - About 30 mins to fix

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

              public function getModuleInfo($moduleDir)
              {
                  $result['basename'] = basename($moduleDir);
                  $result['name'] = $result['basename'];
                  $result['description'] = '';
          Severity: Minor
          Found in includes/ModuleManager.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

          Avoid using undefined variables such as '$result' which will lead to PHP notices.
          Open

                      $result['description'] = $composerData->description;
          Severity: Minor
          Found in includes/ModuleManager.php by phpmd

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

          Avoid using undefined variables such as '$result' which will lead to PHP notices.
          Open

                      $result['homepage'] = $composerData->homepage;
          Severity: Minor
          Found in includes/ModuleManager.php by phpmd

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

          Avoid using undefined variables such as '$result' which will lead to PHP notices.
          Open

                  $result['basename'] = basename($moduleDir);
          Severity: Minor
          Found in includes/ModuleManager.php by phpmd

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

          Avoid using undefined variables such as '$result' which will lead to PHP notices.
          Open

                  $result['name'] = $result['basename'];
          Severity: Minor
          Found in includes/ModuleManager.php by phpmd

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

          Avoid using undefined variables such as '$result' which will lead to PHP notices.
          Open

                      return $result;
          Severity: Minor
          Found in includes/ModuleManager.php by phpmd

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

          Avoid using undefined variables such as '$result' which will lead to PHP notices.
          Open

                  $result['description'] = '';
          Severity: Minor
          Found in includes/ModuleManager.php by phpmd

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

          Avoid using undefined variables such as '$result' which will lead to PHP notices.
          Open

                      $result['name'] = $composerData->name;
          Severity: Minor
          Found in includes/ModuleManager.php by phpmd

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

          Avoid using undefined variables such as '$result' which will lead to PHP notices.
          Open

                  $result['license'] = '';
          Severity: Minor
          Found in includes/ModuleManager.php by phpmd

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

          Avoid using undefined variables such as '$result' which will lead to PHP notices.
          Open

                      return $result;
          Severity: Minor
          Found in includes/ModuleManager.php by phpmd

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

          Avoid using undefined variables such as '$result' which will lead to PHP notices.
          Open

                  $result['name'] = $result['basename'];
          Severity: Minor
          Found in includes/ModuleManager.php by phpmd

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

          Avoid using undefined variables such as '$result' which will lead to PHP notices.
          Open

                  $result['homepage'] = '';
          Severity: Minor
          Found in includes/ModuleManager.php by phpmd

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

          Avoid using undefined variables such as '$result' which will lead to PHP notices.
          Open

                      $result['license'] = $composerData->license;
          Severity: Minor
          Found in includes/ModuleManager.php by phpmd

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

          Avoid using undefined variables such as '$result' which will lead to PHP notices.
          Open

                  return $result;
          Severity: Minor
          Found in includes/ModuleManager.php by phpmd

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

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

              public function moduleRow($moduleBaseName, $moduleInfo, $enabled = true)
          Severity: Minor
          Found in includes/ModuleManager.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

          Remove error control operator '@' on line 203.
          Open

              public function getModuleInfo($moduleDir)
              {
                  $result['basename'] = basename($moduleDir);
                  $result['name'] = $result['basename'];
                  $result['description'] = '';
          Severity: Minor
          Found in includes/ModuleManager.php by phpmd

          ErrorControlOperator

          Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

          Example

          function foo($filePath) {
              $file = @fopen($filPath); // hides exceptions
              $key = @$array[$notExistingKey]; // assigns null to $key
          }

          Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

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

                  } else {
                      $frag .= '<div class="col-sm-3"><a href="?e='
                          .urlencode($moduleBaseName).'">(enable)</a> DISABLED</div>';
                  }
          Severity: Minor
          Found in includes/ModuleManager.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

          Suspicious attempt to unset class \Attogram\ModuleManager's property disabledModules declared at /code/includes/ModuleManager.php:14 (This can be done, but is more commonly done for dynamic properties and Phan does not expect this)
          Open

                  unset($this->disabledModules);
          Severity: Info
          Found in includes/ModuleManager.php by phan

          Variable $result was undeclared, but array fields are being added to it.
          Open

                  $result['basename'] = basename($moduleDir);
          Severity: Info
          Found in includes/ModuleManager.php by phan

          Suspicious attempt to unset class \Attogram\ModuleManager's property enabledModules declared at /code/includes/ModuleManager.php:12 (This can be done, but is more commonly done for dynamic properties and Phan does not expect this)
          Open

                  unset($this->enabledModules);
          Severity: Info
          Found in includes/ModuleManager.php by phan

          There are no issues that match your filters.

          Category
          Status