qcubed/framework

View on GitHub
includes/base_controls/QAutocompleteBase.class.php

Summary

Maintainability
B
5 hrs
Test Coverage

Function __set has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

        public function __set($strName, $mixValue) {
            switch ($strName) {
                case 'DataSource':
                    // Assign data to a DataSource from within the data binder function only.
                    // Data should be array items that at a minimum contain a 'value' and an 'id'
Severity: Minor
Found in includes/base_controls/QAutocompleteBase.class.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 __set has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        public function __set($strName, $mixValue) {
            switch ($strName) {
                case 'DataSource':
                    // Assign data to a DataSource from within the data binder function only.
                    // Data should be array items that at a minimum contain a 'value' and an 'id'
Severity: Minor
Found in includes/base_controls/QAutocompleteBase.class.php - About 1 hr to fix

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

            public function __construct($strName, $strValue, $blnSelected = false, $strItemGroup = null, $strOverrideParameters = null) {
    Severity: Minor
    Found in includes/base_controls/QAutocompleteBase.class.php - About 35 mins to fix

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

              public function __set($strName, $mixValue) {
                  switch ($strName) {
                      case 'DataSource':
                          // Assign data to a DataSource from within the data binder function only.
                          // Data should be array items that at a minimum contain a 'value' and an 'id'

      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 class QAutocompleteBase has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13.
      Open

          class QAutocompleteBase extends QAutocompleteGen
          {
              /** @var string */
              protected $strSelectedId = null;
              /** @var boolean */

      CouplingBetweenObjects

      Since: 1.1.0

      A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

      Example

      class Foo {
          /**
           * @var \foo\bar\X
           */
          private $x = null;
      
          /**
           * @var \foo\bar\Y
           */
          private $y = null;
      
          /**
           * @var \foo\bar\Z
           */
          private $z = null;
      
          public function setFoo(\Foo $foo) {}
          public function setBar(\Bar $bar) {}
          public function setBaz(\Baz $baz) {}
      
          /**
           * @return \SplObjectStorage
           * @throws \OutOfRangeException
           * @throws \InvalidArgumentException
           * @throws \ErrorException
           */
          public function process(\Iterator $it) {}
      
          // ...
      }

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

      Missing class import via use statement (line '146', column '25').
      Open

                  $this->AddAction(new QAutocomplete_SourceEvent(), $objAction);

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

                  $this->mixSource = new QJsVarName('qcubed.acSourceFunction');

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

              public function __construct($strName, $strValue, $blnSelected = false, $strItemGroup = null, $strOverrideParameters = null) {

      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 '117', column '20').
      Open

                      $filter =  new QJsClosure ($filter, ['term']);

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

                      throw new QCallerException("filter must be either a string or an instance of QJsClosure");

      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 '142', column '22').
      Open

                      $objAction = new QAjaxControlAction($objParentControl, $strMethodName, 'default', null, 'ui');

      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 '144', column '22').
      Open

                      $objAction = new QAjaxAction($strMethodName, 'default', null, 'ui');

      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 '305', column '9').
      Open

                      new QModelConnectorParam (QModelConnectorParam::GeneralCategory, 'NoAutoLoad', 'Prevent automatically populating a list type control. Set this if you are doing more complex list loading.', QType::Boolean)

      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 'QApplication' in method 'UseFilter'.
      Open

                  QApplication::ExecuteJsFunction('qcubed.acUseFilter', $filter);

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

                  } else {
                      $objAction = new QAjaxAction($strMethodName, 'default', null, 'ui');
                  }

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

                          } else {
                              $this->Source = $mixValue;
                          }

      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 'JavaScriptHelper' in method 'toJsObject'.
      Open

                  return JavaScriptHelper::toJsObject(array("value" => $this->Name, "id" => $this->Value));

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

                                  $this->strSelectedId = QType::Cast($mixValue, 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

      Avoid using static access to class 'QApplication' in method 'prepareAjaxList'.
      Open

                  QApplication::ExecuteJsFunction('qc.acSetData', $this->getJqControlId(), $dataSource, QJsPriority::Exclusive);

      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 static access to class 'QApplication' in method 'GetEndScript'.
      Open

                  QApplication::ExecuteJsFunction('qc.autocomplete', $this->GetJqControlId(), QJsPriority::High);

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

                              } else {
                                  $this->strSelectedId = QType::Cast($mixValue, QType::String);
                              }

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

              public function __construct($strName, $strValue, $blnSelected = false, $strItemGroup = null, $strOverrideParameters = null) {

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

          class QAutocomplete_SourceEvent extends QEvent {
              /** Event Name */
              const EventName = 'QAutocomplete_Source';
              const JsReturnParam = 'ui'; // ends up being the request.term value
          }

      CamelCaseClassName

      Since: 0.2

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

      Example

      class class_name {
      }

      Source

      Constant JsReturnParam should be defined in uppercase
      Open

              const JsReturnParam = 'ui'; // ends up being the request.term value

      ConstantNamingConventions

      Since: 0.2

      Class/Interface constant names should always be defined in uppercase.

      Example

      class Foo {
          const MY_NUM = 0; // ok
          const myTest = ""; // fail
      }

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

      Constant EventName should be defined in uppercase
      Open

              const EventName = 'QAutocomplete_Source';

      ConstantNamingConventions

      Since: 0.2

      Class/Interface constant names should always be defined in uppercase.

      Example

      class Foo {
          const MY_NUM = 0; // ok
          const myTest = ""; // fail
      }

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

      The method SetEmpty is not named in camelCase.
      Open

              public function SetEmpty() {
                  $this->Text = '';
                  $this->SelectedId = null;
              }

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

              protected function PutState($state) {
                  parent::PutState($state);
                  if (isset($state['selectedId'])) {
                      $this->SelectedId = $state['selectedId'];
                  }

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

              public static function GetModelConnectorParams() {
                  return array_merge(parent::GetModelConnectorParams(), array(
                      new QModelConnectorParam (QModelConnectorParam::GeneralCategory, 'NoAutoLoad', 'Prevent automatically populating a list type control. Set this if you are doing more complex list loading.', QType::Boolean)
                  ));
              }

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

              public function GetEndScript() {
                  $strJS = parent::GetEndScript();
                  QApplication::ExecuteJsFunction('qc.autocomplete', $this->GetJqControlId(), QJsPriority::High);
      
                  return $strJS;

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

              static public function UseFilter($filter) {
                  if (is_string($filter)) {
                      $filter =  new QJsClosure ($filter, ['term']);
                  }
                  else if (!($filter instanceof QJsClosure)) {

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

              public function SetDataBinder($strMethodName, $objParentControl = null) {
                  if ($objParentControl) {
                      $objAction = new QAjaxControlAction($objParentControl, $strMethodName, 'default', null, 'ui');
                  } else {
                      $objAction = new QAjaxAction($strMethodName, 'default', null, 'ui');

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

              protected function GetState() {
                  $state = parent::GetState();
                  $state['selectedId']=$this->SelectedId;
                  return $state;
              }

      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