YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

Method getDetailViewLinks has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getDetailViewLinks(array $linkParams): array
    {
        $linkModelList = parent::getDetailViewLinks($linkParams);
        $recordModel = $this->getRecord();
        foreach ($linkModelList['DETAIL_VIEW_BASIC'] as $index => $link) {
Severity: Minor
Found in modules/Leads/models/DetailView.php - About 1 hr to fix

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

        public function getDetailViewLinks(array $linkParams): array
        {
            $linkModelList = parent::getDetailViewLinks($linkParams);
            $recordModel = $this->getRecord();
            foreach ($linkModelList['DETAIL_VIEW_BASIC'] as $index => $link) {
    Severity: Minor
    Found in modules/Leads/models/DetailView.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

    Avoid using static access to class 'Leads_Module_Model' in method 'getDetailViewLinks'.
    Open

                $convert = !Leads_Module_Model::checkIfAllowedToConvert($recordModel->get('leadstatus')) ? 'd-none' : '';
    Severity: Minor
    Found in modules/Leads/models/DetailView.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\Language' in method 'getDetailViewLinks'.
    Open

                    'linkhint' => \App\Language::translate('LBL_CONVERT_LEAD', $this->getModule()->getName()),
    Severity: Minor
    Found in modules/Leads/models/DetailView.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_Link_Model' in method 'getDetailViewLinks'.
    Open

                $linkModelList['DETAIL_VIEW_ADDITIONAL'][] = Vtiger_Link_Model::getInstanceFromValues([
                    'linktype' => 'DETAIL_VIEW_ADDITIONAL',
                    'linklabel' => '',
                    'linkclass' => 'btn-sm btn-outline-info btn-convertLead ' . $convert,
                    'linkhint' => \App\Language::translate('LBL_CONVERT_LEAD', $this->getModule()->getName()),
    Severity: Minor
    Found in modules/Leads/models/DetailView.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 "DETAIL_VIEW_BASIC" 5 times.
    Open

            foreach ($linkModelList['DETAIL_VIEW_BASIC'] as $index => $link) {
    Severity: Critical
    Found in modules/Leads/models/DetailView.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.

    Call to undeclared method \Leads_DetailView_Model::getModule
    Open

                    'linkhint' => \App\Language::translate('LBL_CONVERT_LEAD', $this->getModule()->getName()),
    Severity: Critical
    Found in modules/Leads/models/DetailView.php by phan

    Call to undeclared method \Leads_DetailView_Model::getRecord
    Open

            $recordModel = $this->getRecord();
    Severity: Critical
    Found in modules/Leads/models/DetailView.php by phan

    This branch's code block is the same as the block for the branch on line 20.
    Open

                } elseif ('LBL_TRANSFER_OWNERSHIP' == $link->linklabel) {
                    unset($linkModelList['DETAIL_VIEW_BASIC'][$index]);
                }

    Having two cases in a switch statement or two branches in an if chain with the same implementation is at best duplicate code, and at worst a coding error. If the same logic is truly needed for both instances, then in an if chain they should be combined, or for a switch, one should fall through to the other.

    Noncompliant Code Example

    switch ($i) {
      case 1:
        doSomething();
        break;
      case 2:
        doSomethingDifferent();
        break;
      case 3:  // Noncompliant; duplicates case 1's implementation
        doSomething();
        break;
      default:
        doTheRest();
    }
    
    if ($a >= 0 && $a < 10) {
      doTheThing();
    else if ($a >= 10 && $a < 20) {
      doTheOtherThing();
    }
    else if ($a >= 20 && $a < 50) {
      doTheThing();  // Noncompliant; duplicates first condition
    }
    else {
      doTheRest();
    }
    
    if ($b == 0) {
      doOneMoreThing();
    }
    else {
      doOneMoreThing(); // Noncompliant; duplicates then-branch
    }
    
    var b = a ? 12 > 4 : 4;  // Noncompliant; always results in the same value
    

    Compliant Solution

    switch ($i) {
      case 1:
      case 3:
        doSomething();
        break;
      case 2:
        doSomethingDifferent();
        break;
      default:
        doTheRest();
    }
    
    if (($a >= 0 && $a < 10) || ($a >= 20 && $a < 50)) {
      doTheThing();
    else if ($a >= 10 && $a < 20) {
      doTheOtherThing();
    }
    else {
      doTheRest();
    }
    
    doOneMoreThing();
    
    b = 4;
    

    or

    switch ($i) {
      case 1:
        doSomething();
        break;
      case 2:
        doSomethingDifferent();
        break;
      case 3:
        doThirdThing();
        break;
      default:
        doTheRest();
    }
    
    if ($a >= 0 && $a < 10) {
      doTheThing();
    else if ($a >= 10 && $a < 20) {
      doTheOtherThing();
    }
    else if ($a >= 20 && $a < 50) {
      doTheThirdThing();
    }
    else {
      doTheRest();
    }
    
    if ($b == 0) {
      doOneMoreThing();
    }
    else {
      doTheRest();
    }
    
    int b = a ? 12 > 4 : 8;
    

    Exceptions

    Blocks in an if chain that contain a single line of code are ignored, as are blocks in a switch statement that contain a single line of code with or without a following break.

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

    class Leads_DetailView_Model extends Accounts_DetailView_Model

    The class Leads_DetailView_Model is not named in CamelCase.
    Open

    class Leads_DetailView_Model extends Accounts_DetailView_Model
    {
        /** {@inheritdoc} */
        public function getDetailViewLinks(array $linkParams): array
        {
    Severity: Minor
    Found in modules/Leads/models/DetailView.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

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

            $linkModelList = parent::getDetailViewLinks($linkParams);

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

            }

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

                    unset($linkModelList['DETAIL_VIEW_BASIC'][$index]);

    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

                    $linkModelList['DETAIL_VIEW_BASIC'][$index] = $link;

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

                $convert = !Leads_Module_Model::checkIfAllowedToConvert($recordModel->get('leadstatus')) ? 'd-none' : '';

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

                    'linkicon' => 'fas fa-exchange-alt',

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

        {

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

                    $link->linklabel = 'LBL_SHOW_ACCOUNT_HIERARCHY';

    Line exceeds 120 characters; contains 121 characters
    Open

                    'linkurl' => 'javascript:Leads_Detail_Js.convertLead("' . $recordModel->getConvertLeadUrl() . '",this);',

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

                if ('View History' == $link->linklabel) {

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

                    'linktype' => 'DETAIL_VIEW_ADDITIONAL',

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

            if (!$recordModel->isReadOnly() && $recordModel->isPermitted('ConvertLead') && $recordModel->isEditable()) {

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

                $linkModelList['DETAIL_VIEW_ADDITIONAL'][] = Vtiger_Link_Model::getInstanceFromValues([

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

                    'linkclass' => 'btn-sm btn-outline-info btn-convertLead ' . $convert,

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

                    'linklabel' => '',

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

                    'linkurl' => 'javascript:Leads_Detail_Js.convertLead("' . $recordModel->getConvertLeadUrl() . '",this);',

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

        public function getDetailViewLinks(array $linkParams): array

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

                    $link->linkurl = 'javascript:Accounts_Detail_Js.triggerAccountHierarchy("' . $linkURL . '");';

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

                } elseif ('LBL_SHOW_ACCOUNT_HIERARCHY' == $link->linklabel) {

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

                    unset($linkModelList['DETAIL_VIEW_BASIC'][$index]);

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

                }

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

                    'linkhint' => \App\Language::translate('LBL_CONVERT_LEAD', $this->getModule()->getName()),

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

            return $linkModelList;

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

        }

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

                } elseif ('LBL_TRANSFER_OWNERSHIP' == $link->linklabel) {

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

            $recordModel = $this->getRecord();

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

            foreach ($linkModelList['DETAIL_VIEW_BASIC'] as $index => $link) {

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

                    $linkURL = 'index.php?module=Accounts&view=AccountHierarchy&record=' . $recordModel->getId();

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

                    unset($linkModelList['DETAIL_VIEW_BASIC'][$index]);

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

                ]);

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

            }

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

    class Leads_DetailView_Model extends Accounts_DetailView_Model

    There are no issues that match your filters.

    Category
    Status