YetiForceCompany/YetiForceCRM

View on GitHub
modules/Occurrences/models/RelationListView.php

Summary

Maintainability
A
2 hrs
Test Coverage
F
0%

Method getLinks has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getLinks(): array
    {
        $relatedLink = parent::getLinks();
        if (!$this->getParentRecordModel()->isReadOnly()) {
            $relationModelInstance = $this->getRelationModel();
Severity: Minor
Found in modules/Occurrences/models/RelationListView.php - About 1 hr to fix

    Consider simplifying this complex logical expression.
    Open

                if ($contactModel->getName() === $relatedModuleModel->getName() && $contactModel->isActive()
                    && $contactModel->isPermitted('CreateView') && $contactModel->isPermitted('Import')
                    && $relationModelInstance->isAddActionSupported()
                    && $this->getParentRecordModel()->isViewable()
                    && $relationModelInstance->getParentModuleModel()->getName() === $this->getParentRecordModel()->getModuleName()
    Severity: Major
    Found in modules/Occurrences/models/RelationListView.php - About 1 hr to fix

      Function getLinks has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getLinks(): array
          {
              $relatedLink = parent::getLinks();
              if (!$this->getParentRecordModel()->isReadOnly()) {
                  $relationModelInstance = $this->getRelationModel();
      Severity: Minor
      Found in modules/Occurrences/models/RelationListView.php - About 35 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

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

          public function getLinks(): array
          {
              $relatedLink = parent::getLinks();
              if (!$this->getParentRecordModel()->isReadOnly()) {
                  $relationModelInstance = $this->getRelationModel();

      CyclomaticComplexity

      Since: 0.1

      Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

      Example

      // Cyclomatic Complexity = 11
      class Foo {
      1   public function example() {
      2       if ($a == $b) {
      3           if ($a1 == $b1) {
                      fiddle();
      4           } elseif ($a2 == $b2) {
                      fiddle();
                  } else {
                      fiddle();
                  }
      5       } elseif ($c == $d) {
      6           while ($c == $d) {
                      fiddle();
                  }
      7        } elseif ($e == $f) {
      8           for ($n = 0; $n < $h; $n++) {
                      fiddle();
                  }
              } else {
                  switch ($z) {
      9               case 1:
                          fiddle();
                          break;
      10              case 2:
                          fiddle();
                          break;
      11              case 3:
                          fiddle();
                          break;
                      default:
                          fiddle();
                          break;
                  }
              }
          }
      }

      Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

      Avoid using static access to class 'Vtiger_Link_Model' in method 'getLinks'.
      Open

                      $relatedLink['RELATEDLIST_MASSACTIONS'][] = Vtiger_Link_Model::getInstanceFromValues([
                          'linktype' => 'LISTVIEWMASSACTION',
                          'linklabel' => 'LBL_IMPORT',
                          'linkurl' => $contactModel->getImportUrl() . '&relationId=' . $relationModelInstance->getId() . '&src_record=' . $this->getParentRecordModel()->getId(),
                          'linkicon' => 'fas fa-download',

      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_Link_Model' in method 'getLinks'.
      Open

                      $relatedLink['RELATEDLIST_MASSACTIONS'][] = Vtiger_Link_Model::getInstanceFromValues([
                          'linktype' => 'LISTVIEWMASSACTION',
                          'linklabel' => 'LBL_MASS_SEND_EMAIL',
                          'linkurl' => 'javascript:Vtiger_RelatedList_Js.triggerSendEmail();',
                          'linkicon' => 'fas fa-envelope',

      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 'getLinks'.
      Open

                  $contactModel = Vtiger_Module_Model::getInstance('Contacts');

      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\Config' in method 'getLinks'.
      Open

                  if ('Contacts' === $relatedModuleModel->getName() && $relatedModuleModel->isPermitted('MassComposeEmail') && App\Config::main('isActiveSendingMails') && App\Mail::getDefaultSmtp()) {

      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\Mail' in method 'getLinks'.
      Open

                  if ('Contacts' === $relatedModuleModel->getName() && $relatedModuleModel->isPermitted('MassComposeEmail') && App\Config::main('isActiveSendingMails') && App\Mail::getDefaultSmtp()) {

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

                  $relationModelInstance = $this->getRelationModel();

      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

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

      class Occurrences_RelationListView_Model extends Vtiger_RelationListView_Model

      The class Occurrences_RelationListView_Model is not named in CamelCase.
      Open

      class Occurrences_RelationListView_Model extends Vtiger_RelationListView_Model
      {
          /** {@inheritdoc} */
          public function getLinks(): array
          {

      CamelCaseClassName

      Since: 0.2

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

      Example

      class class_name {
      }

      Source

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

                  $relationModelInstance = $this->getRelationModel();

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

                          'linktype' => 'LISTVIEWMASSACTION',

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

              return $relatedLink;

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

                      && $relationModelInstance->isAddActionSupported()

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

                  if ('Contacts' === $relatedModuleModel->getName() && $relatedModuleModel->isPermitted('MassComposeEmail') && App\Config::main('isActiveSendingMails') && App\Mail::getDefaultSmtp()) {

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

                      && $relationModelInstance->getParentModuleModel()->getName() === $this->getParentRecordModel()->getModuleName()

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

                          'linkurl' => $contactModel->getImportUrl() . '&relationId=' . $relationModelInstance->getId() . '&src_record=' . $this->getParentRecordModel()->getId(),

      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

                          'linklabel' => 'LBL_MASS_SEND_EMAIL',

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

                  }

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

                  $contactModel = Vtiger_Module_Model::getInstance('Contacts');

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

          {

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

                          'linkurl' => 'javascript:Vtiger_RelatedList_Js.triggerSendEmail();',

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

                      && $contactModel->isPermitted('CreateView') && $contactModel->isPermitted('Import')

      Line exceeds 120 characters; contains 127 characters
      Open

                      && $relationModelInstance->getParentModuleModel()->getName() === $this->getParentRecordModel()->getModuleName()

      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 (!$this->getParentRecordModel()->isReadOnly()) {

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

                      && $this->getParentRecordModel()->isViewable()

      Line exceeds 120 characters; contains 172 characters
      Open

                          'linkurl' => $contactModel->getImportUrl() . '&relationId=' . $relationModelInstance->getId() . '&src_record=' . $this->getParentRecordModel()->getId(),

      Line exceeds 120 characters; contains 194 characters
      Open

                  if ('Contacts' === $relatedModuleModel->getName() && $relatedModuleModel->isPermitted('MassComposeEmail') && App\Config::main('isActiveSendingMails') && App\Mail::getDefaultSmtp()) {

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

                  if ($contactModel->getName() === $relatedModuleModel->getName() && $contactModel->isActive()

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

                      $relatedLink['RELATEDLIST_MASSACTIONS'][] = Vtiger_Link_Model::getInstanceFromValues([

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

                          'linktype' => 'LISTVIEWMASSACTION',

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

                          'linklabel' => 'LBL_IMPORT',

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

          public function getLinks(): array

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

                      $relatedLink['RELATEDLIST_MASSACTIONS'][] = Vtiger_Link_Model::getInstanceFromValues([

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

                          'linkicon' => 'fas fa-download',

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

          /** {@inheritdoc} */

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

              $relatedLink = parent::getLinks();

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

                          'linkicon' => 'fas fa-envelope',

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

                      ]);

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

                  $relatedModuleModel = $relationModelInstance->getRelationModuleModel();

      Line indented incorrectly; expected at least 12 spaces, found 8
      Open

              ) {

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

      class Occurrences_RelationListView_Model extends Vtiger_RelationListView_Model

      There are no issues that match your filters.

      Category
      Status