XoopsModules25x/xoopsinfo

View on GitHub
phpsysinfo/includes/error/class.PSI_Error.inc.php

Summary

Maintainability
B
4 hrs
Test Coverage

Function _trace has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    private function _trace($strMessage)
    {
        $arrTrace = array_reverse(debug_backtrace());
        $strFunc = '';
        $strBacktrace = htmlspecialchars($strMessage)."\n\n";
Severity: Minor
Found in phpsysinfo/includes/error/class.PSI_Error.inc.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 _trace has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function _trace($strMessage)
    {
        $arrTrace = array_reverse(debug_backtrace());
        $strFunc = '';
        $strBacktrace = htmlspecialchars($strMessage)."\n\n";
Severity: Minor
Found in phpsysinfo/includes/error/class.PSI_Error.inc.php - About 1 hr to fix

    Function _printVar has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        private function _printVar($var)
        {
            if (is_string($var)) {
                $search = array("\x00", "\x0a", "\x0d", "\x1a", "\x09");
                $replace = array('\0', '\n', '\r', '\Z', '\t');
    Severity: Minor
    Found in phpsysinfo/includes/error/class.PSI_Error.inc.php - About 45 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 (var_export($var, true));
    Severity: Major
    Found in phpsysinfo/includes/error/class.PSI_Error.inc.php - About 30 mins to fix

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

          private function _trace($strMessage)
          {
              $arrTrace = array_reverse(debug_backtrace());
              $strFunc = '';
              $strBacktrace = htmlspecialchars($strMessage)."\n\n";

      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

      Missing class import via use statement (line '163', column '20').
      Open

              $xml = new SimpleXMLExtended(simplexml_import_dom($dom), 'UTF-8');

      MissingImport

      Since: 2.7.0

      Importing all external classes in a file through use statements makes them clearly visible.

      Example

      function make() {
          return new \stdClass();
      }

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

      Missing class import via use statement (line '192', column '23').
      Open

              $xmlerr = new SimpleXMLExtended($xml, $encoding);

      MissingImport

      Since: 2.7.0

      Importing all external classes in a file through use statements makes them clearly visible.

      Example

      function make() {
          return new \stdClass();
      }

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

      Missing class import via use statement (line '160', column '20').
      Open

              $dom = new DOMDocument('1.0', 'UTF-8');

      MissingImport

      Since: 2.7.0

      Importing all external classes in a file through use statements makes them clearly visible.

      Example

      function make() {
          return new \stdClass();
      }

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

      Missing class import via use statement (line '188', column '20').
      Open

              $dom = new DOMDocument('1.0', 'UTF-8');

      MissingImport

      Since: 2.7.0

      Importing all external classes in a file through use statements makes them clearly visible.

      Example

      function make() {
          return new \stdClass();
      }

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

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

                  } else {
                      return ('false');
                  }

      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 errorsExist uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  return false;
              }

      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 _trace uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      $strFunc = $val['function'].'(';
                      if (isset($val['args'][0])) {
                          $strFunc .= ' ';
                          $strComma = '';

      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 errorsAsXML() contains an exit expression.
      Open

              exit();

      ExitExpression

      Since: 0.2

      An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

      Example

      class Foo {
          public function bar($param)  {
              if ($param === 42) {
                  exit(23);
              }
          }
      }

      Source https://phpmd.org/rules/design.html#exitexpression

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

      class PSI_Error

      The property $_instance is not named in camelCase.
      Open

      class PSI_Error
      {
          /**
           * holds the instance of this class
           *

      CamelCasePropertyName

      Since: 0.2

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

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      Avoid variables with short names like $c. Configured minimum length is 3.
      Open

                  $c = __CLASS__;

      ShortVariable

      Since: 0.2

      Detects when a field, local, or parameter has a very short name.

      Example

      class Something {
          private $q = 15; // VIOLATION - Field
          public static function main( array $as ) { // VIOLATION - Formal
              $r = 20 + $this->q; // VIOLATION - Local
              for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                  $r += $this->q;
              }
          }
      }

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

      The property $_arrErrorList is not named in camelCase.
      Open

      class PSI_Error
      {
          /**
           * holds the instance of this class
           *

      CamelCasePropertyName

      Since: 0.2

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

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      The class PSI_Error is not named in CamelCase.
      Open

      class PSI_Error
      {
          /**
           * holds the instance of this class
           *

      CamelCaseClassName

      Since: 0.2

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

      Example

      class class_name {
      }

      Source

      The property $_errors is not named in camelCase.
      Open

      class PSI_Error
      {
          /**
           * holds the instance of this class
           *

      CamelCasePropertyName

      Since: 0.2

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

      Example

      class ClassName {
          protected $property_name;
      }

      Source

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

          private $_errors = 0;

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

          private function _addError($strCommand, $strMessage)

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

          private function _printVar($var)

      Expected 1 space before "=>"; 0 found
      Open

                  foreach ($var as $key=>$val) {

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

          private $_arrErrorList = array();

      Expected 1 space after "=>"; 0 found
      Open

                  foreach ($var as $key=>$val) {

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

          private function _trace($strMessage)

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

          private static $_instance;

      Line exceeds 120 characters; contains 132 characters
      Open

       * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version

      Line exceeds 120 characters; contains 131 characters
      Open

           * generate a function backtrace for error diagnostic, function is genearally based on code submitted in the php reference page

      Line exceeds 120 characters; contains 157 characters
      Open

                  if ($val['function'] == 'include' || $val['function'] == 'require' || $val['function'] == 'include_once' || $val['function'] == 'require_once') {

      Line exceeds 120 characters; contains 132 characters
      Open

       * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version

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

      class PSI_Error

      The method _trace is not named in camelCase.
      Open

          private function _trace($strMessage)
          {
              $arrTrace = array_reverse(debug_backtrace());
              $strFunc = '';
              $strBacktrace = htmlspecialchars($strMessage)."\n\n";

      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

      The method _printVar is not named in camelCase.
      Open

          private function _printVar($var)
          {
              if (is_string($var)) {
                  $search = array("\x00", "\x0a", "\x0d", "\x1a", "\x09");
                  $replace = array('\0', '\n', '\r', '\Z', '\t');

      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

      The method _addError is not named in camelCase.
      Open

          private function _addError($strCommand, $strMessage)
          {
              $index = count($this->_arrErrorList) + 1;
              $this->_arrErrorList[$index]['command'] = $strCommand;
              $this->_arrErrorList[$index]['message'] = $strMessage;

      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