qcubed/framework

View on GitHub
includes/codegen/controls/QLabelBase_CodeGenerator.class.php

Summary

Maintainability
B
6 hrs
Test Coverage

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

        public function ConnectorRefresh(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn, $blnInit = false) {
            $strObjectName = $objCodeGen->ModelVariableName($objTable->Name);
            $strPropName = QCodeGen::ModelConnectorPropertyName($objColumn);
            $strControlVarName = $this->VarName($strPropName);

Severity: Minor
Found in includes/codegen/controls/QLabelBase_CodeGenerator.class.php - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method ConnectorCreate has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        public function ConnectorCreate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {
            $strLabelName = addslashes(QCodeGen::ModelConnectorControlName($objColumn));
            $strControlType = 'QLabel';

            $strPropName = QCodeGen::ModelConnectorPropertyName($objColumn);
Severity: Minor
Found in includes/codegen/controls/QLabelBase_CodeGenerator.class.php - About 1 hr to fix

    Method ConnectorRefresh has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            public function ConnectorRefresh(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn, $blnInit = false) {
                $strObjectName = $objCodeGen->ModelVariableName($objTable->Name);
                $strPropName = QCodeGen::ModelConnectorPropertyName($objColumn);
                $strControlVarName = $this->VarName($strPropName);
    
    
    Severity: Minor
    Found in includes/codegen/controls/QLabelBase_CodeGenerator.class.php - About 1 hr to fix

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

              public function ConnectorRefresh(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn, $blnInit = false) {
                  $strObjectName = $objCodeGen->ModelVariableName($objTable->Name);
                  $strPropName = QCodeGen::ModelConnectorPropertyName($objColumn);
                  $strControlVarName = $this->VarName($strPropName);
      
      

      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 ConnectorRefresh has a boolean flag argument $blnInit, which is a certain sign of a Single Responsibility Principle violation.
      Open

              public function ConnectorRefresh(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn, $blnInit = false) {

      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

      Missing class import via use statement (line '187', column '15').
      Open

                      throw new Exception ('Unknown column type.');

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

                      self::$instance = new QLabel_CodeGenerator();

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

                  $strPropName = QCodeGen::ModelConnectorPropertyName($objColumn);

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

                      } else {
                          switch ($objColumn->VariableType) {
                              case "boolean":
                                  $strRet = "\$this->{$strControlVarName}->Text = \$this->{$strObjectName}->{$strPropName} ? QApplication::Translate('Yes') : QApplication::Translate('No');";
                                  break;

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

                  } else {
                      $strRet = "\t\t\t" . $strRet;
                  }

      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 '84', column '8').
      Open

              public function ConnectorCreate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {
                  $strLabelName = addslashes(QCodeGen::ModelConnectorControlName($objColumn));
                  $strControlType = 'QLabel';
      
                  $strPropName = QCodeGen::ModelConnectorPropertyName($objColumn);

      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 'QCodeGen' in method 'ConnectorCreate'.
      Open

                  $strLabelName = addslashes(QCodeGen::ModelConnectorControlName($objColumn));

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

                  } else {
                      throw new Exception ('Unknown column type.');
                  }

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

                          } else {
                              $strRet = "\$this->{$strControlVarName}->Text = \$this->{$strObjectName}->{$strPropName} ? \$this->{$strObjectName}->{$strPropName}->__toString() : null;";
                          }

      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 'QCodeGen' in method 'ConnectorRefresh'.
      Open

                  $strPropName = QCodeGen::ModelConnectorPropertyName($objColumn);

      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 unused parameters such as '$objTable'.
      Open

              public function ConnectorUpdate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {

      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 '$objCodeGen'.
      Open

              public function ConnectorUpdate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {

      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 '$objColumn'.
      Open

              public function ConnectorUpdate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {

      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 excessively long variable names like $strDateTimeParamExtra. Keep variable name length under 20.
      Open

                  $strDateTimeParamExtra = '';

      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 class QLabelBase_CodeGenerator is not named in CamelCase.
      Open

          class QLabelBase_CodeGenerator extends QControl_CodeGenerator {
              private static $instance = null;
      
              public function __construct($strControlClassName = 'QLabel') {
                  parent::__construct($strControlClassName);

      CamelCaseClassName

      Since: 0.2

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

      Example

      class class_name {
      }

      Source

      The method ConnectorVariableDeclaration is not named in camelCase.
      Open

              public function ConnectorVariableDeclaration(QCodeGenBase $objCodeGen, $objColumn) {
                  $strPropName = $objCodeGen->ModelConnectorPropertyName($objColumn);
                  $strControlVarName = $this->VarName($strPropName);
      
                  $strRet = <<<TMPL

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

              public function ConnectorUpdate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {
                  return '';
              }

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

              public function ConnectorCreate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn) {
                  $strLabelName = addslashes(QCodeGen::ModelConnectorControlName($objColumn));
                  $strControlType = 'QLabel';
      
                  $strPropName = QCodeGen::ModelConnectorPropertyName($objColumn);

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

              public function ConnectorRefresh(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn, $blnInit = false) {
                  $strObjectName = $objCodeGen->ModelVariableName($objTable->Name);
                  $strPropName = QCodeGen::ModelConnectorPropertyName($objColumn);
                  $strControlVarName = $this->VarName($strPropName);
      
      

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

              public function VarName($strPropName) {
                  return 'lbl' . $strPropName;
              }

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

              public static function Instance() {
                  if (!self::$instance) {
                      self::$instance = new QLabel_CodeGenerator();
                  }
                  return self::$instance;

      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