YetiForceCompany/YetiForceCRM

View on GitHub
modules/Leads/models/Module.php

Summary

Maintainability
C
7 hrs
Test Coverage
F
0%

Function searchAccountsToConvert has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    public function searchAccountsToConvert(Vtiger_Record_Model $recordModel)
    {
        \App\Log::trace('Start ' . __METHOD__);
        if ($recordModel) {
            $mappingFields = Vtiger_Processes_Model::getConfig('marketing', 'conversion', 'mapping');
Severity: Minor
Found in modules/Leads/models/Module.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 searchAccountsToConvert has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function searchAccountsToConvert(Vtiger_Record_Model $recordModel)
    {
        \App\Log::trace('Start ' . __METHOD__);
        if ($recordModel) {
            $mappingFields = Vtiger_Processes_Model::getConfig('marketing', 'conversion', 'mapping');
Severity: Minor
Found in modules/Leads/models/Module.php - About 1 hr to fix

    Method getQueryByModuleField has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function getQueryByModuleField($sourceModule, $field, $record, App\QueryGenerator $queryGenerator)
        {
            if (!empty($record) && \in_array($sourceModule, ['Campaigns', 'Products', 'Services'])) {
                switch ($sourceModule) {
                    case 'Campaigns':
    Severity: Minor
    Found in modules/Leads/models/Module.php - About 1 hr to fix

      Function getQueryByModuleField has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getQueryByModuleField($sourceModule, $field, $record, App\QueryGenerator $queryGenerator)
          {
              if (!empty($record) && \in_array($sourceModule, ['Campaigns', 'Products', 'Services'])) {
                  switch ($sourceModule) {
                      case 'Campaigns':
      Severity: Minor
      Found in modules/Leads/models/Module.php - About 55 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

      Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed.
      Open

          public function searchAccountsToConvert(Vtiger_Record_Model $recordModel)
      Severity: Critical
      Found in modules/Leads/models/Module.php by sonar-php

      Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

      See

      Missing class import via use statement (line '108', column '18').
      Open

                  $query = (new App\Db\Query())->select(['vtiger_account.accountid'])
      Severity: Minor
      Found in modules/Leads/models/Module.php by phpmd

      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 '119', column '17').
      Open

                              throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED');
      Severity: Minor
      Found in modules/Leads/models/Module.php by phpmd

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

                      $subQuery = (new App\Db\Query())
      Severity: Minor
      Found in modules/Leads/models/Module.php by phpmd

      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 '50').
      Open

                  $query->andWhere(['not in', 'csl.crmid', (new \App\Db\Query())->select(['leadid'])->from('vtiger_leaddetails')->where(['converted' => 1])]);
      Severity: Minor
      Found in modules/Leads/models/Module.php by phpmd

      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 '81', column '28').
      Open

                      $secondSubQuery = (new App\Db\Query())
      Severity: Minor
      Found in modules/Leads/models/Module.php by phpmd

      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 '87', column '63').
      Open

                      $condition = ['not in', 'vtiger_leaddetails.leadid', (new App\Db\Query())->select([$fieldName])->from($tableName)->where([$relatedFieldName => $record])];
      Severity: Minor
      Found in modules/Leads/models/Module.php by phpmd

      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 '25', column '17').
      Open

              $query = (new App\Db\Query())->select(['count' => 'COUNT(*)', 'time' => 'date(createdtime)'])
      Severity: Minor
      Found in modules/Leads/models/Module.php by phpmd

      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 'Settings_MarketingProcesses_Module_Model' in method 'checkIfAllowedToConvert'.
      Open

              $leadConfig = Settings_MarketingProcesses_Module_Model::getConfig('lead');
      Severity: Minor
      Found in modules/Leads/models/Module.php by phpmd

      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 '\App\Log' in method 'searchAccountsToConvert'.
      Open

              \App\Log::trace('End ' . __METHOD__);
      Severity: Minor
      Found in modules/Leads/models/Module.php by phpmd

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

              } else {
                  $query->andWhere(['not in', 'csl.crmid', (new \App\Db\Query())->select(['leadid'])->from('vtiger_leaddetails')->where(['converted' => 1])]);
              }
      Severity: Minor
      Found in modules/Leads/models/Module.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 getQueryByModuleField uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      $condition = ['not in', 'vtiger_leaddetails.leadid', (new App\Db\Query())->select([$fieldName])->from($tableName)->where([$relatedFieldName => $record])];
                  }
      Severity: Minor
      Found in modules/Leads/models/Module.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 using static access to class '\App\Json' in method 'searchAccountsToConvert'.
      Open

                  $mappingFields = \App\Json::decode($mappingFields);
      Severity: Minor
      Found in modules/Leads/models/Module.php by phpmd

      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 'Settings_MarketingProcesses_Module_Model' in method 'getConversionAvaibleStatuses'.
      Open

              $leadConfig = Settings_MarketingProcesses_Module_Model::getConfig('lead');
      Severity: Minor
      Found in modules/Leads/models/Module.php by phpmd

      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 'Vtiger_Processes_Model' in method 'searchAccountsToConvert'.
      Open

                  $mappingFields = Vtiger_Processes_Model::getConfig('marketing', 'conversion', 'mapping');
      Severity: Minor
      Found in modules/Leads/models/Module.php by phpmd

      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 '\App\Log' in method 'searchAccountsToConvert'.
      Open

                      \App\Log::trace('End ' . __METHOD__);
      Severity: Minor
      Found in modules/Leads/models/Module.php by phpmd

      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 'Vtiger_Module_Model' in method 'searchAccountsToConvert'.
      Open

                  $moduleModel = Vtiger_Module_Model::getInstance('Accounts');
      Severity: Minor
      Found in modules/Leads/models/Module.php by phpmd

      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 '\App\PrivilegeQuery' in method 'getLeadsCreated'.
      Open

              \App\PrivilegeQuery::getConditions($query, $this->getName());
      Severity: Minor
      Found in modules/Leads/models/Module.php by phpmd

      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 '\App\Log' in method 'searchAccountsToConvert'.
      Open

              \App\Log::trace('Start ' . __METHOD__);
      Severity: Minor
      Found in modules/Leads/models/Module.php by phpmd

      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 '\App\Log' in method 'searchAccountsToConvert'.
      Open

                      \App\Log::trace('End ' . __METHOD__);
      Severity: Minor
      Found in modules/Leads/models/Module.php by phpmd

      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

      Define a constant instead of duplicating this literal "vtiger_crmentity" 3 times.
      Open

                  ->innerJoin('vtiger_crmentity', 'vtiger_leaddetails.leadid = vtiger_crmentity.crmid')
      Severity: Critical
      Found in modules/Leads/models/Module.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "vtiger_leaddetails" 3 times.
      Open

                  ->from('vtiger_leaddetails')
      Severity: Critical
      Found in modules/Leads/models/Module.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "crmid" 4 times.
      Open

                          $fieldName = 'crmid';
      Severity: Critical
      Found in modules/Leads/models/Module.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "convert_status" 3 times.
      Open

              return $leadConfig['convert_status'];
      Severity: Critical
      Found in modules/Leads/models/Module.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "not in" 4 times.
      Open

                      $condition = ['and', ['not in', 'vtiger_leaddetails.leadid', $subQuery], ['not in', 'vtiger_leaddetails.leadid', $secondSubQuery]];
      Severity: Critical
      Found in modules/Leads/models/Module.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "vtiger_leaddetails.leadid" 3 times.
      Open

                      $condition = ['and', ['not in', 'vtiger_leaddetails.leadid', $subQuery], ['not in', 'vtiger_leaddetails.leadid', $secondSubQuery]];
      Severity: Critical
      Found in modules/Leads/models/Module.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Avoid unused parameters such as '$field'.
      Open

          public function getQueryByModuleField($sourceModule, $field, $record, App\QueryGenerator $queryGenerator)
      Severity: Minor
      Found in modules/Leads/models/Module.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

      Call to method trace from undeclared class \App\Log
      Open

              \App\Log::trace('End ' . __METHOD__);
      Severity: Critical
      Found in modules/Leads/models/Module.php by phan

      Call to undeclared method \App\Db\Query::select
      Open

                  $query->andWhere(['not in', 'csl.crmid', (new \App\Db\Query())->select(['leadid'])->from('vtiger_leaddetails')->where(['converted' => 1])]);
      Severity: Critical
      Found in modules/Leads/models/Module.php by phan

      Saw unextractable annotation for comment '* @return <array>'</array>
      Open

           * @return <Array>
      Severity: Info
      Found in modules/Leads/models/Module.php by phan

      Call to method addNativeCondition from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
      Open

                  $queryGenerator->addNativeCondition($condition);
      Severity: Critical
      Found in modules/Leads/models/Module.php by phan

      Call to undeclared method \App\Db\Query::andWhere
      Open

                  $query->andWhere(['vtiger_leaddetails.converted' => 0]);
      Severity: Critical
      Found in modules/Leads/models/Module.php by phan

      Argument 1 (encodedValue) is array but \App\Json::decode() takes string defined at /code/app/Json.php:37
      Open

                  $mappingFields = \App\Json::decode($mappingFields);
      Severity: Minor
      Found in modules/Leads/models/Module.php by phan

      Call to undeclared method \App\Db\Query::select
      Open

                      $subQuery = (new App\Db\Query())
      Severity: Critical
      Found in modules/Leads/models/Module.php by phan

      Doc-block of $recordSearch in searchRecordCondition is phpdoc param type \App\RecordSearch which is not a permitted replacement of the nullable param type ?\App\RecordSearch declared in the signature ('?T' should be documented as 'T|null' or '?T')
      Open

           * @param App\RecordSearch $recordSearch
      Severity: Minor
      Found in modules/Leads/models/Module.php by phan

      Call to undeclared method \App\Db\Query::select
      Open

              $query = (new App\Db\Query())->select(['count' => 'COUNT(*)', 'time' => 'date(createdtime)'])
      Severity: Critical
      Found in modules/Leads/models/Module.php by phan

      Returning type int but searchAccountsToConvert() is declared to return bool
      Open

                      return (int) $dataReader->readColumn(0);
      Severity: Minor
      Found in modules/Leads/models/Module.php by phan

      Call to undeclared method \App\Db\Query::select
      Open

                      $secondSubQuery = (new App\Db\Query())
      Severity: Critical
      Found in modules/Leads/models/Module.php by phan

      Call to method trace from undeclared class \App\Log
      Open

              \App\Log::trace('Start ' . __METHOD__);
      Severity: Critical
      Found in modules/Leads/models/Module.php by phan

      Call to method trace from undeclared class \App\Log
      Open

                      \App\Log::trace('End ' . __METHOD__);
      Severity: Critical
      Found in modules/Leads/models/Module.php by phan

      Parameter $queryGenerator has undeclared type \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
      Open

          public function getQueryByModuleField($sourceModule, $field, $record, App\QueryGenerator $queryGenerator)
      Severity: Minor
      Found in modules/Leads/models/Module.php by phan

      Call to undeclared method \App\Db\Query::select
      Open

                  $query = (new App\Db\Query())->select(['vtiger_account.accountid'])
      Severity: Critical
      Found in modules/Leads/models/Module.php by phan

      Call to method trace from undeclared class \App\Log
      Open

                      \App\Log::trace('End ' . __METHOD__);
      Severity: Critical
      Found in modules/Leads/models/Module.php by phan

      Call to undeclared method \App\Db\Query::innerJoin
      Open

                  $query->innerJoin('vtiger_leaddetails', 'csl.crmid = vtiger_leaddetails.leadid');
      Severity: Critical
      Found in modules/Leads/models/Module.php by phan

      Call to undeclared method \App\Db\Query::andWhere
      Open

                  $query->andWhere(['not in', 'csl.crmid', (new \App\Db\Query())->select(['leadid'])->from('vtiger_leaddetails')->where(['converted' => 1])]);
      Severity: Critical
      Found in modules/Leads/models/Module.php by phan

      Call to undeclared method \App\Db\Query::select
      Open

                      $condition = ['not in', 'vtiger_leaddetails.leadid', (new App\Db\Query())->select([$fieldName])->from($tableName)->where([$relatedFieldName => $record])];
      Severity: Critical
      Found in modules/Leads/models/Module.php by phan

      Saw unextractable annotation for comment '* @return <array> array of statuses'</array>
      Open

           * @return <Array> array of statuses
      Severity: Info
      Found in modules/Leads/models/Module.php by phan

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

                  if ('Services' === $sourceModule) {
                      $subQuery = (new App\Db\Query())
                          ->select(['relcrmid'])
                          ->from('vtiger_crmentityrel')
                          ->where(['crmid' => $record]);
      Severity: Major
      Found in modules/Leads/models/Module.php and 1 other location - About 1 hr to fix
      modules/Contacts/models/Module.php on lines 45..60

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

      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

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

      class Leads_Module_Model extends Vtiger_Module_Model

      The class Leads_Module_Model is not named in CamelCase.
      Open

      class Leads_Module_Model extends Vtiger_Module_Model
      {
          /**
           * Function returns the Number of Leads created per week.
           *
      Severity: Minor
      Found in modules/Leads/models/Module.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

      Line exceeds 120 characters; contains 127 characters
      Open

                  $query->andWhere(['between', 'createdtime', $dateFilter['start'] . ' 00:00:00', $dateFilter['end'] . ' 23:59:59']);

      Spaces must be used to indent lines; tabs are not allowed
      Open

              while ($row = $dataReader->read()) {

      Line exceeds 120 characters; contains 170 characters
      Open

                      $condition = ['not in', 'vtiger_leaddetails.leadid', (new App\Db\Query())->select([$fieldName])->from($tableName)->where([$relatedFieldName => $record])];

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @throws \App\Exceptions\NoPermitted

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  foreach ($mappingFields as $mappingField) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          $query->andWhere(["{$tableName}.{$fieldModel->getColumnName()}" => $recordModel->get($leadFieldName)]);

      Line exceeds 120 characters; contains 123 characters
      Open

                          $query->andWhere(["{$tableName}.{$fieldModel->getColumnName()}" => $recordModel->get($leadFieldName)]);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $numberRows = $dataReader->count();

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $dataReader->close();

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  if (1 === $numberRows) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

           */

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          $relatedFieldName = 'productid';

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          ->from('vtiger_crmentityrel')

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $secondSubQuery = (new App\Db\Query())

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          ->select(['crmid'])

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $mappingFields = \App\Json::decode($mappingFields);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  if ($numberRows > 1) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

          /**

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  ->where(['deleted' => 0, 'converted' => 0]);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  ->query();

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param string              $sourceModule   Parent module

      Spaces must be used to indent lines; tabs are not allowed
      Open

           */

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          break;

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  } else {

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      ->from('vtiger_account')

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      ->where(['vtiger_crmentity.deleted' => 0]);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $joinTable = ['vtiger_account', 'vtiger_crmentity'];

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      foreach ($mappingField as $leadFieldName => $accountFieldName) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          $fieldModel = $moduleModel->getFieldByName($accountFieldName);

      Spaces must be used to indent lines; tabs are not allowed
      Open

          /**

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * Function that returns status that allow to convert Lead.

      Spaces must be used to indent lines; tabs are not allowed
      Open

           */

      Spaces must be used to indent lines; tabs are not allowed
      Open

              \App\PrivilegeQuery::getConditions($query, $this->getName());

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          ->from('vtiger_crmentityrel')

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $condition = ['and', ['not in', 'vtiger_leaddetails.leadid', $subQuery], ['not in', 'vtiger_leaddetails.leadid', $secondSubQuery]];

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

              \App\Log::trace('Start ' . __METHOD__);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $query = (new App\Db\Query())->select(['vtiger_account.accountid'])

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $query->limit(2);

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param array $dateFilter

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param Vtiger_Record_Model $recordModel

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if ($recordModel) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      ->innerJoin('vtiger_crmentity', 'vtiger_crmentity.crmid = vtiger_account.accountid')

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      \App\Log::trace('End ' . __METHOD__);

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $query = (new App\Db\Query())->select(['count' => 'COUNT(*)', 'time' => 'date(createdtime)'])

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  ->innerJoin('vtiger_crmentity', 'vtiger_leaddetails.leadid = vtiger_crmentity.crmid')

      Spaces must be used to indent lines; tabs are not allowed
      Open

              return $response;

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if (!empty($record) && \in_array($sourceModule, ['Campaigns', 'Products', 'Services'])) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  switch ($sourceModule) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          $tableName = 'vtiger_campaign_records';

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      case 'Products':

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          $fieldName = 'crmid';

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @return <Array>

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $query->andWhere(['between', 'createdtime', $dateFilter['start'] . ' 00:00:00', $dateFilter['end'] . ' 23:59:59']);

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param \App\QueryGenerator $queryGenerator

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $queryGenerator->addNativeCondition($condition);

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * Function to search accounts.

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          $tableName = $fieldModel->get('table');

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  ];

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param string              $record         parent id

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          ->where(['crmid' => $record]);

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $mappingFields = Vtiger_Processes_Model::getConfig('marketing', 'conversion', 'mapping');

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $moduleModel = Vtiger_Module_Model::getInstance('Accounts');

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          if (!$fieldModel) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @return <Array> array of statuses

      Spaces must be used to indent lines; tabs are not allowed
      Open

          public function getLeadsCreated($owner, $dateFilter)

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $dataReader = $query->groupBy('date(createdtime)')

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $row['time'],

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      case 'Campaigns':

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          $tableName = 'vtiger_seproductsrel';

      Line exceeds 120 characters; contains 147 characters
      Open

                      $condition = ['and', ['not in', 'vtiger_leaddetails.leadid', $subQuery], ['not in', 'vtiger_leaddetails.leadid', $secondSubQuery]];

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

          /**

      Spaces must be used to indent lines; tabs are not allowed
      Open

                              throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED');

      Spaces must be used to indent lines; tabs are not allowed
      Open

                              $joinTable[] = $tableName;

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          $relatedFieldName = 'campaignid';

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          break;

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      default:

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @return bool

      Spaces must be used to indent lines; tabs are not allowed
      Open

          public function searchAccountsToConvert(Vtiger_Record_Model $recordModel)

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $focus = $moduleModel->getEntityInstance();

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          if (!\in_array($tableName, $joinTable)) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      return false;

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * Function that checks if lead record can be converted.

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if (!empty($dateFilter)) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      return (int) $dataReader->readColumn(0);

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * Function returns the Number of Leads created per week.

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $response = [];

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }

      Spaces must be used to indent lines; tabs are not allowed
      Open

          /**

      Spaces must be used to indent lines; tabs are not allowed
      Open

          public function getQueryByModuleField($sourceModule, $field, $record, App\QueryGenerator $queryGenerator)

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          $fieldName = 'crmid';

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          break;

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  if ('Services' === $sourceModule) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $condition = ['not in', 'vtiger_leaddetails.leadid', (new App\Db\Query())->select([$fieldName])->from($tableName)->where([$relatedFieldName => $record])];

      Spaces must be used to indent lines; tabs are not allowed
      Open

           */

      Line exceeds 120 characters; contains 134 characters
      Open

                              $query->innerJoin($tableName, "{$tableName}.{$focus->tab_name_index[$tableName]} = vtiger_account.accountid");

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      }

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }

      Spaces must be used to indent lines; tabs are not allowed
      Open

           */

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @return void

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $query->andWhere(['not in', 'csl.crmid', (new \App\Db\Query())->select(['leadid'])->from('vtiger_leaddetails')->where(['converted' => 1])]);

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $query->innerJoin('vtiger_leaddetails', 'csl.crmid = vtiger_leaddetails.leadid');

      Spaces must be used to indent lines; tabs are not allowed
      Open

          /**

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param App\RecordSearch $recordSearch

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if ($recordSearch->moduleName === $this->getName()) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $query->andWhere(['smownerid' => $owner]);

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $subQuery = (new App\Db\Query())

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                              $query->innerJoin($tableName, "{$tableName}.{$focus->tab_name_index[$tableName]} = vtiger_account.accountid");

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

              \App\Log::trace('End ' . __METHOD__);

      Spaces must be used to indent lines; tabs are not allowed
      Open

              return true;

      Spaces must be used to indent lines; tabs are not allowed
      Open

          public static function getConversionAvaibleStatuses()

      Spaces must be used to indent lines; tabs are not allowed
      Open

          public static function checkIfAllowedToConvert($status)

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $query->andWhere(['vtiger_leaddetails.converted' => 0]);

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if (!empty($owner)) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  ->createCommand()

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  ->from('vtiger_leaddetails')

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $response[] = [

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $row['count'],

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          ->select(['relcrmid'])

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      \App\Log::trace('End ' . __METHOD__);

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param string $status - lead status

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  return true;

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param int   $owner

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * Function to get list view query for popup window.

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param string              $field          parent fieldname

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          ->where(['relcrmid' => $record]);

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $dataReader = $query->createCommand()->query();

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param App\Db\Query     $query

      Spaces must be used to indent lines; tabs are not allowed
      Open

          public function searchRecordCondition(App\Db\Query $query, App\RecordSearch $recordSearch = null): void

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if (empty($leadConfig['convert_status'])) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * The function adds restrictions to the functionality of searching for records.

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @return bool if or not allowed to convert

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $leadConfig = Settings_MarketingProcesses_Module_Model::getConfig('lead');

      Line exceeds 120 characters; contains 152 characters
      Open

                  $query->andWhere(['not in', 'csl.crmid', (new \App\Db\Query())->select(['leadid'])->from('vtiger_leaddetails')->where(['converted' => 1])]);

      Spaces must be used to indent lines; tabs are not allowed
      Open

              return \in_array($status, $leadConfig['convert_status']);

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $leadConfig = Settings_MarketingProcesses_Module_Model::getConfig('lead');

      Spaces must be used to indent lines; tabs are not allowed
      Open

              return $leadConfig['convert_status'];

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

          /**

      Spaces must be used to indent lines; tabs are not allowed
      Open

           */

      Spaces must be used to indent lines; tabs are not allowed
      Open

              } else {

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

      class Leads_Module_Model extends Vtiger_Module_Model

      There are no issues that match your filters.

      Category
      Status