qcubed/framework

View on GitHub
includes/qform_state_handlers/QDbBackedFormStateHandler.class.php

Summary

Maintainability
C
7 hrs
Test Coverage

Save accesses the super-global variable $_POST.
Open

        public static function Save($strFormState, $blnBackButtonFlag) {
            $objDatabase = QApplication::$Database[self::$intDbIndex];
            $strOriginal = $strFormState;

            // compress (if available)

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

Save accesses the super-global variable $_POST.
Open

        public static function Save($strFormState, $blnBackButtonFlag) {
            $objDatabase = QApplication::$Database[self::$intDbIndex];
            $strOriginal = $strFormState;

            // compress (if available)

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

Method Save has 63 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        public static function Save($strFormState, $blnBackButtonFlag) {
            $objDatabase = QApplication::$Database[self::$intDbIndex];
            $strOriginal = $strFormState;

            // compress (if available)
Severity: Major
Found in includes/qform_state_handlers/QDbBackedFormStateHandler.class.php - About 2 hrs to fix

    Function Save has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

            public static function Save($strFormState, $blnBackButtonFlag) {
                $objDatabase = QApplication::$Database[self::$intDbIndex];
                $strOriginal = $strFormState;
    
                // compress (if available)
    Severity: Minor
    Found in includes/qform_state_handlers/QDbBackedFormStateHandler.class.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

    Method Load has 41 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            public static function Load($strPostDataState) {
                // Pull Out strPageId
                $strPageId = $strPostDataState;
    
                //Get database
    Severity: Minor
    Found in includes/qform_state_handlers/QDbBackedFormStateHandler.class.php - About 1 hr to fix

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

              public static function Load($strPostDataState) {
                  // Pull Out strPageId
                  $strPageId = $strPostDataState;
      
                  //Get database
      Severity: Minor
      Found in includes/qform_state_handlers/QDbBackedFormStateHandler.class.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

      The method Save() has an NPath complexity of 432. The configured NPath complexity threshold is 200.
      Open

              public static function Save($strFormState, $blnBackButtonFlag) {
                  $objDatabase = QApplication::$Database[self::$intDbIndex];
                  $strOriginal = $strFormState;
      
                  // compress (if available)

      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 Load() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
      Open

              public static function Load($strPostDataState) {
                  // Pull Out strPageId
                  $strPageId = $strPostDataState;
      
                  //Get database

      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 Save() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
      Open

              public static function Save($strFormState, $blnBackButtonFlag) {
                  $objDatabase = QApplication::$Database[self::$intDbIndex];
                  $strOriginal = $strFormState;
      
                  // compress (if available)

      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

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

                  $objDatabase = QApplication::$Database[self::$intDbIndex];

      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 '$Database' which will lead to PHP notices.
      Open

                  $objDatabase = QApplication::$Database[self::$intDbIndex];

      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 '$Database' which will lead to PHP notices.
      Open

                  $objDatabase = QApplication::$Database[self::$intDbIndex];

      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 '$Database' which will lead to PHP notices.
      Open

                  $objDatabase = QApplication::$Database[self::$intDbIndex];

      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

      Missing class import via use statement (line '140', column '19').
      Open

                          $crypt = new QCryptography(__DB_BACKED_FORM_STATE_HANDLER_ENCRYPTION_KEY__, false, null, __DB_BACKED_FORM_STATE_HANDLER_HASH_KEY__);

      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 '150', column '16').
      Open

                          throw new Exception ("Base64 Encoding Failed on " . $strOriginal);

      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 '76', column '15').
      Open

                      throw new QCallerException('Table ' . self::$strTableName . ' not found in database at DB_CONNECTION index ' . self::$intDbIndex . '. Correct your settings in configuration.inc.php.');

      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 '257', column '16').
      Open

                          throw new Exception("Failed decoding formstate " . $strSerializedForm);

      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 '263', column '19').
      Open

                          $crypt = new QCryptography(__DB_BACKED_FORM_STATE_HANDLER_ENCRYPTION_KEY__, false, null, __DB_BACKED_FORM_STATE_HANDLER_HASH_KEY__);

      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 '71', column '15').
      Open

                      throw new QCallerException('No database defined at DB_CONNECTION index ' . self::$intDbIndex . '. Correct your settings in configuration.inc.php.');

      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

      Avoid assigning values to variables in if clauses and the like (line '236', column '8').
      Open

              public static function Load($strPostDataState) {
                  // Pull Out strPageId
                  $strPageId = $strPostDataState;
      
                  //Get database

      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

      Avoid using static access to class 'QType' in method 'Initialize'.
      Open

                  self::$strTableName = QType::Cast(self::$strTableName, QType::String);

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

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

                      else {
                          $strFormState = $encoded;
                      }

      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 using static access to class 'QType' in method 'Initialize'.
      Open

                  self::$intDbIndex = QType::Cast(self::$intDbIndex, QType::Integer);

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using empty try-catch blocks in Save.
      Open

                      catch(Exception $e) {
                      }

      EmptyCatchBlock

      Since: 2.7.0

      Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.

      Example

      class Foo {
      
        public function bar()
        {
            try {
                // ...
            } catch (Exception $e) {} // empty catch block
        }
      }

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

      Avoid unused parameters such as '$blnBackButtonFlag'.
      Open

              public static function Save($strFormState, $blnBackButtonFlag) {

      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 local variables such as '$result'.
      Open

                  $result = $objDatabase->NonQuery($query);

      UnusedLocalVariable

      Since: 0.2

      Detects when a local variable is declared and/or assigned, but not used.

      Example

      class Foo {
          public function doSomething()
          {
              $i = 5; // Unused
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

      Avoid unused local variables such as '$result'.
      Open

                  $result = $objDatabase->NonQuery($strQuery);

      UnusedLocalVariable

      Since: 0.2

      Detects when a local variable is declared and/or assigned, but not used.

      Example

      class Foo {
          public function doSomething()
          {
              $i = 5; // Unused
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

      Avoid unused private methods such as 'Initialize'.
      Open

              private static function Initialize() {
                  self::$intDbIndex = QType::Cast(self::$intDbIndex, QType::Integer);
                  self::$strTableName = QType::Cast(self::$strTableName, QType::String);
      
                  // If the database index exists

      UnusedPrivateMethod

      Since: 0.2

      Unused Private Method detects when a private method is declared but is unused.

      Example

      class Something
      {
          private function foo() {} // unused
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedprivatemethod

      Avoid using empty try-catch blocks in Load.
      Open

                      catch(Exception $e) {
                      }

      EmptyCatchBlock

      Since: 2.7.0

      Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.

      Example

      class Foo {
      
        public function bar()
        {
            try {
                // ...
            } catch (Exception $e) {} // empty catch block
        }
      }

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

      Avoid excessively long variable names like $intGarbageCollectOnHitCount. Keep variable name length under 20.
      Open

              public static $intGarbageCollectOnHitCount = 20000;

      LongVariable

      Since: 0.2

      Detects when a field, formal or local variable is declared with a long name.

      Example

      class Something {
          protected $reallyLongIntName = -3; // VIOLATION - Field
          public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
              $otherReallyLongName = -5; // VIOLATION - Local
              for ($interestingIntIndex = 0; // VIOLATION - For
                   $interestingIntIndex < 10;
                   $interestingIntIndex++ ) {
              }
          }
      }

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

      Avoid excessively long variable names like $intGarbageCollectDaysOld. Keep variable name length under 20.
      Open

              public static $intGarbageCollectDaysOld = 2;

      LongVariable

      Since: 0.2

      Detects when a field, formal or local variable is declared with a long name.

      Example

      class Something {
          protected $reallyLongIntName = -3; // VIOLATION - Field
          public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
              $otherReallyLongName = -5; // VIOLATION - Local
              for ($interestingIntIndex = 0; // VIOLATION - For
                   $interestingIntIndex < 10;
                   $interestingIntIndex++ ) {
              }
          }
      }

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

      The variable $Database is not named in camelCase.
      Open

              public static function GarbageCollect() {
                  // Its not perfect and not sure but should be executed on expected intervals
                  $objDatabase = QApplication::$Database[self::$intDbIndex];
                  $query = '
                                          DELETE FROM

      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 $Database is not named in camelCase.
      Open

              public static function Load($strPostDataState) {
                  // Pull Out strPageId
                  $strPageId = $strPostDataState;
      
                  //Get database

      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 $Database is not named in camelCase.
      Open

              public static function Save($strFormState, $blnBackButtonFlag) {
                  $objDatabase = QApplication::$Database[self::$intDbIndex];
                  $strOriginal = $strFormState;
      
                  // compress (if available)

      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 $Database is not named in camelCase.
      Open

              public static function DeleteFormStateForSession() {
                  // Figure Out Session Id (if applicable)
                  $strSessionId = session_id();
      
                  //Get database

      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 $Database is not named in camelCase.
      Open

              private static function Initialize() {
                  self::$intDbIndex = QType::Cast(self::$intDbIndex, QType::Integer);
                  self::$strTableName = QType::Cast(self::$strTableName, QType::String);
      
                  // If the database index exists

      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 Initialize is not named in camelCase.
      Open

              private static function Initialize() {
                  self::$intDbIndex = QType::Cast(self::$intDbIndex, QType::Integer);
                  self::$strTableName = QType::Cast(self::$strTableName, QType::String);
      
                  // If the database index exists

      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 Load is not named in camelCase.
      Open

              public static function Load($strPostDataState) {
                  // Pull Out strPageId
                  $strPageId = $strPostDataState;
      
                  //Get database

      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 Save is not named in camelCase.
      Open

              public static function Save($strFormState, $blnBackButtonFlag) {
                  $objDatabase = QApplication::$Database[self::$intDbIndex];
                  $strOriginal = $strFormState;
      
                  // compress (if available)

      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 GarbageCollect is not named in camelCase.
      Open

              public static function GarbageCollect() {
                  // Its not perfect and not sure but should be executed on expected intervals
                  $objDatabase = QApplication::$Database[self::$intDbIndex];
                  $query = '
                                          DELETE FROM

      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 DeleteFormStateForSession is not named in camelCase.
      Open

              public static function DeleteFormStateForSession() {
                  // Figure Out Session Id (if applicable)
                  $strSessionId = session_id();
      
                  //Get database

      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