XoopsModules25x/xoopsinfo

View on GitHub
phpsysinfo/tools/checkdistro.php

Summary

Maintainability
C
1 day
Test Coverage

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

    private static function _parse_log_file($string)
    {
        global $log_file;
        if (file_exists($log_file)) {
            $contents = @file_get_contents($log_file);
Severity: Minor
Found in phpsysinfo/tools/checkdistro.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

Avoid deeply nested control flow statements.
Open

                while (false !== ($sentry = readdir($shandle))) {
                    if (($sentry!=".")&&($sentry!="..")) {
                        $log_file=PSI_APP_ROOT.'/sample/distrotest/'.$entry.'/'.$sentry;
                        echo "<tr>";
                        echo "<td>".$entry.'/'.$sentry."</td>";
Severity: Major
Found in phpsysinfo/tools/checkdistro.php - About 45 mins to fix

    Consider simplifying this complex logical expression.
    Open

            if (file_exists($log_file)
                && ($lsb || $lsbfile || ($strFileName != "/etc/lsb-release"))
                && ($contents = @file_get_contents($log_file))
                && preg_match("/^\-\-\-\-\-\-\-\-\-\-".preg_quote($strFileName, '/')."\-\-\-\-\-\-\-\-\-\-\r?\n/m", $contents)) {
                return true;
    Severity: Major
    Found in phpsysinfo/tools/checkdistro.php - About 40 mins to fix

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

          public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true)
      Severity: Minor
      Found in phpsysinfo/tools/checkdistro.php - About 35 mins to fix

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

            public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $booErrorRep = true, $timeout = 30)
        Severity: Minor
        Found in phpsysinfo/tools/checkdistro.php - About 35 mins to fix

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

              public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true)
              {
                  global $lsb;
                  global $lsbfile;
                  if ($lsb || $lsbfile || ($strFileName != "/etc/lsb-release")) {
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 method rfts has a boolean flag argument $booErrorRep, which is a certain sign of a Single Responsibility Principle violation.
          Open

              public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true)
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 executeProgram has a boolean flag argument $booErrorRep, which is a certain sign of a Single Responsibility Principle violation.
          Open

              public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $booErrorRep = true, $timeout = 30)
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 47.
          Open

              private static function _parse_log_file($string)
              {
                  global $log_file;
                  if (file_exists($log_file)) {
                      $contents = @file_get_contents($log_file);
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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

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

              public static function fileexists($strFileName)
              {
                  global $log_file;
                  global $lsb;
                  global $lsbfile;
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 rfts uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      return false;
                  }
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 assigning values to variables in if clauses and the like (line '101', column '17').
          Open

              public static function fileexists($strFileName)
              {
                  global $log_file;
                  global $lsb;
                  global $lsbfile;
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.php by phpmd

          IfStatementAssignment

          Since: 2.7.0

          Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

          Example

          class Foo
          {
              public function bar($flag)
              {
                  if ($foo = 'bar') { // possible typo
                      // ...
                  }
                  if ($baz = 0) { // always false
                      // ...
                  }
              }
          }

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

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

                  } else {
                      return $strBuffer = self::_parse_log_file($strProgramname);
                  }
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 _parse_log_file uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                              } else {
                                  return substr($contents, $startIndex);
                              }
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 '$booErrorRep'.
          Open

              public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true)
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 '$timeout'.
          Open

              public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $booErrorRep = true, $timeout = 30)
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 '$strElem'.
          Open

              public static function readenv($strElem, &$strBuffer)
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 '$booErrorRep'.
          Open

              public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $booErrorRep = true, $timeout = 30)
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 '$strBuffer'.
          Open

              public static function readenv($strElem, &$strBuffer)
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 '$strArgs'.
          Open

              public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $booErrorRep = true, $timeout = 30)
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 '$intBytes'.
          Open

              public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true)
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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

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

                      if ($contents && preg_match("/^\-\-\-\-\-\-\-\-\-\-".preg_quote($string, '/')."\-\-\-\-\-\-\-\-\-\-\n/m", $contents, $matches, PREG_OFFSET_CAPTURE)) {
                          $findIndex = $matches[0][1];
                          if (preg_match("/\n/m", $contents, $matches, PREG_OFFSET_CAPTURE, $findIndex)) {
                              $startIndex = $matches[0][1]+1;
                              if (preg_match("/^\-\-\-\-\-\-\-\-\-\-/m", $contents, $matches, PREG_OFFSET_CAPTURE, $startIndex)) {
          Severity: Major
          Found in phpsysinfo/tools/checkdistro.php and 1 other location - About 5 hrs to fix
          phpsysinfo/includes/class.CommonFunctions.inc.php on lines 46..58

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

          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 using short method names like Parser::df(). The configured minimum method name length is 3.
          Open

              public static function df()
              {
                  return array();
              }
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.php by phpmd

          ShortMethodName

          Since: 0.2

          Detects when very short method names are used.

          Example

          class ShortMethod {
              public function a( $index ) { // Violation
              }
          }

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

          Each class must be in a namespace of at least one level (a top-level vendor name)
          Open

          class PSI_Error

          Each class must be in a namespace of at least one level (a top-level vendor name)
          Open

          class CommonFunctions

          Each class must be in a namespace of at least one level (a top-level vendor name)
          Open

          class _Linux extends Linux

          Each class must be in a namespace of at least one level (a top-level vendor name)
          Open

          class Parser

          The class PSI_Error is not named in CamelCase.
          Open

          class PSI_Error
          {
              public static function singleton()
              {
              }
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.php by phpmd

          CamelCaseClassName

          Since: 0.2

          It is considered best practice to use the CamelCase notation to name classes.

          Example

          class class_name {
          }

          Source

          The class _Linux is not named in CamelCase.
          Open

          class _Linux extends Linux
          {
              public function build()
              {
                  parent::_distro();
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.php by phpmd

          CamelCaseClassName

          Since: 0.2

          It is considered best practice to use the CamelCase notation to name classes.

          Example

          class class_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 9 and the first side effect is on line 2.
          Open

          <?php

          Each class must be in a file by itself
          Open

          class Parser

          Each class must be in a file by itself
          Open

          class CommonFunctions

          Each class must be in a file by itself
          Open

          class _Linux extends Linux

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

              private static function _parse_log_file($string)

          Method name "CommonFunctions::_parse_log_file" is not in camel caps format
          Open

              private static function _parse_log_file($string)

          Inline control structures are not allowed
          Open

                                  else

          Inline control structures are not allowed
          Open

                                  if ($icon != $entry.'.png')

          Inline control structures are not allowed
          Open

                                  else

          Line exceeds 120 characters; contains 162 characters
          Open

                      if ($contents && preg_match("/^\-\-\-\-\-\-\-\-\-\-".preg_quote($string, '/')."\-\-\-\-\-\-\-\-\-\-\n/m", $contents, $matches, PREG_OFFSET_CAPTURE)) {

          Inline control structures are not allowed
          Open

                                  if ($icon == '') $icon="unknown.png";

          Inline control structures are not allowed
          Open

                                  if ($icon != $entry.'.png')

          Inline control structures are not allowed
          Open

                                  if ($icon != $entry.'.png')

          Inline control structures are not allowed
          Open

                                  if ($icon != $entry.'.png')

          Inline control structures are not allowed
          Open

                                  else

          Inline control structures are not allowed
          Open

                                  if ($icon == '') $icon="unknown.png";

          Inline control structures are not allowed
          Open

                                  if ($icon != $entry.'.png')

          Inline control structures are not allowed
          Open

                                  else

          Line exceeds 120 characters; contains 125 characters
          Open

                      && preg_match("/^\-\-\-\-\-\-\-\-\-\-".preg_quote($strFileName, '/')."\-\-\-\-\-\-\-\-\-\-\r?\n/m", $contents)) {

          Inline control structures are not allowed
          Open

                                  if ($icon == '') $icon="unknown.png";

          Inline control structures are not allowed
          Open

                                  else

          Inline control structures are not allowed
          Open

                                  if ($icon != $entry.'.png')

          Inline control structures are not allowed
          Open

                                  else

          Expected 1 space after ELSE keyword; newline found
          Open

                                  else

          Class name "_Linux" is not in camel caps format
          Open

          class _Linux extends Linux

          Class name "PSI_Error" is not in camel caps format
          Open

          class PSI_Error

          Expected 1 space after ELSE keyword; newline found
          Open

                                  else

          Expected 1 space after ELSE keyword; newline found
          Open

                                  else

          Expected 1 space after ELSE keyword; newline found
          Open

                                  else

          Expected 1 space after ELSE keyword; newline found
          Open

                                  else

          Expected 1 space after ELSE keyword; newline found
          Open

                                  else

          The variable $log_file is not named in camelCase.
          Open

              private static function _parse_log_file($string)
              {
                  global $log_file;
                  if (file_exists($log_file)) {
                      $contents = @file_get_contents($log_file);
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 $log_file is not named in camelCase.
          Open

              public static function fileexists($strFileName)
              {
                  global $log_file;
                  global $lsb;
                  global $lsbfile;
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 $log_file is not named in camelCase.
          Open

              private static function _parse_log_file($string)
              {
                  global $log_file;
                  if (file_exists($log_file)) {
                      $contents = @file_get_contents($log_file);
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 $log_file is not named in camelCase.
          Open

              private static function _parse_log_file($string)
              {
                  global $log_file;
                  if (file_exists($log_file)) {
                      $contents = @file_get_contents($log_file);
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 $log_file is not named in camelCase.
          Open

              public static function fileexists($strFileName)
              {
                  global $log_file;
                  global $lsb;
                  global $lsbfile;
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 $log_file is not named in camelCase.
          Open

              public static function fileexists($strFileName)
              {
                  global $log_file;
                  global $lsb;
                  global $lsbfile;
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.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 method _parse_log_file is not named in camelCase.
          Open

              private static function _parse_log_file($string)
              {
                  global $log_file;
                  if (file_exists($log_file)) {
                      $contents = @file_get_contents($log_file);
          Severity: Minor
          Found in phpsysinfo/tools/checkdistro.php by phpmd

          CamelCaseMethodName

          Since: 0.2

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

          Example

          class ClassName {
              public function get_name() {
              }
          }

          Source

          There are no issues that match your filters.

          Category
          Status