YetiForceCompany/YetiForceCRM

View on GitHub
modules/ServiceContracts/ServiceContracts.php

Summary

Maintainability
C
7 hrs
Test Coverage
F
48%

Function calculateProgress has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    public function calculateProgress()
    {
        $db = \App\Db::getInstance();
        $params = [];

Severity: Minor
Found in modules/ServiceContracts/ServiceContracts.php - About 1 hr 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 class ServiceContracts has 18 fields. Consider redesigning ServiceContracts to keep the number of fields under 15.
Open

class ServiceContracts extends CRMEntity
{
    public $table_name = 'vtiger_servicecontracts';
    public $table_index = 'servicecontractsid';
    public $column_fields = [];

TooManyFields

Since: 0.1

Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

Example

class Person {
   protected $one;
   private $two;
   private $three;
   [... many more fields ...]
}

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

Method calculateProgress has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function calculateProgress()
    {
        $db = \App\Db::getInstance();
        $params = [];

Severity: Minor
Found in modules/ServiceContracts/ServiceContracts.php - About 1 hr to fix

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

        public function computeUsedUnits($ticketData, $operator = '+')
        {
            $trackingUnit = strtolower($this->column_fields['tracking_unit']);
            $workingHoursPerDay = 24;
    
    
    Severity: Minor
    Found in modules/ServiceContracts/ServiceContracts.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

    Function updateServiceContractState has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        public function updateServiceContractState($focusId)
        {
            $this->id = $focusId;
            $this->retrieveEntityInfo($focusId, 'ServiceContracts');
            $dataReader = (new App\Db\Query())->select(['relcrmid'])
    Severity: Minor
    Found in modules/ServiceContracts/ServiceContracts.php - About 25 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 calculateProgress() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
    Open

        public function calculateProgress()
        {
            $db = \App\Db::getInstance();
            $params = [];
    
    

    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

    Missing class import via use statement (line '147', column '17').
    Open

                ->union((new App\Db\Query())->select(['crmid'])

    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

            $dataReader = (new App\Db\Query())->select(['relcrmid'])

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

            $dataReader = (new \App\Db\Query())->select(['ticketid'])->from('vtiger_troubletickets')

    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 '129', column '33').
    Open

                $serviceContractsInfo = (new \App\Db\Query())->select(['vtiger_crmentity.setype', 'vtiger_servicecontracts.sc_related_to'])

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

            } else {
                $params['planned_duration'] = '';
            }

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

            } else {
                $params['actual_duration'] = '';
            }

    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 'vtlib\Module' in method 'moduleHandler'.
    Open

                $conModuleInstance = vtlib\Module::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\EventHandler' in method 'moduleHandler'.
    Open

                App\EventHandler::setInActive('ServiceContracts_ServiceContractsHandler_Handler');

    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 'CRMEntity' in method 'updateServiceContractState'.
    Open

            $ticketFocus = CRMEntity::getInstance('HelpDesk');

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

            } else {
                $params['progress'] = null;
            }

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

    Source https://phpmd.org/rules/cleancode.html#elseexpression

    Avoid using static access to class '\App\Record' in method 'updateServiceContractState'.
    Open

                if (\App\Record::isExists($ticketId)) {

    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\Db' in method 'calculateProgress'.
    Open

            $db = \App\Db::getInstance();

    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\Fields\DateTime' in method 'calculateProgress'.
    Open

                $params['actual_duration'] = \App\Fields\DateTime::getDiff($startDate, $endDate, 'days');

    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 'vtlib\Module' in method 'moduleHandler'.
    Open

                $helpDeskInstance = vtlib\Module::getInstance('HelpDesk');

    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 'vtlib\Module' in method 'moduleHandler'.
    Open

                $accModuleInstance = vtlib\Module::getInstance('Accounts');

    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\EventHandler' in method 'moduleHandler'.
    Open

                App\EventHandler::setActive('ServiceContracts_ServiceContractsHandler_Handler');

    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 '\vtlib\Functions' in method 'calculateProgress'.
    Open

            $totalUnits = \vtlib\Functions::formatDecimal($this->column_fields['total_units']);

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

            } else {
                $endDate = null;
                $db->createCommand()->update($this->table_name, ['end_date' => $endDate], ['servicecontractsid' => $this->id])->execute();
            }

    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 'vtlib\Module' in method 'moduleHandler'.
    Open

                $moduleInstance = vtlib\Module::getInstance($moduleName);

    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\Fields\DateTime' in method 'calculateProgress'.
    Open

                $params['planned_duration'] = \App\Fields\DateTime::getDiff($startDate, $dueDate, 'days');

    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 '\vtlib\Functions' in method 'calculateProgress'.
    Open

            $usedUnits = \vtlib\Functions::formatDecimal($this->column_fields['used_units']);

    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 "Service Contracts" 3 times.
    Open

                $accModuleInstance->setRelatedList($moduleInstance, 'Service Contracts', ['add'], 'getDependentsList');

    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 "end_date" 3 times.
    Open

            $endDate = $this->column_fields['end_date'];

    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_crmentity" 3 times.
    Open

        public $tab_name = ['vtiger_crmentity', 'vtiger_servicecontracts', 'vtiger_servicecontractscf', 'vtiger_entity_stats'];

    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 "total_units" 3 times.
    Open

            'Total Units' => 'total_units',

    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 "contract_status" 4 times.
    Open

            'Status' => 'contract_status',

    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 "parent_id" 3 times.
    Open

                ->where(['and', ['or', ['parent_id' => null], ['parent_id' => 0]], ['ticketid' => $entityIds]])

    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 "ticketid" 3 times.
    Open

            $dataReader = (new \App\Db\Query())->select(['ticketid'])->from('vtiger_troubletickets')

    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 "ServiceContracts" 3 times.
    Open

            $this->retrieveEntityInfo($focusId, 'ServiceContracts');

    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 "HelpDesk" 5 times.
    Open

                $helpDeskInstance = vtlib\Module::getInstance('HelpDesk');

    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 "servicecontracts" 9 times.
    Open

            'Subject' => ['servicecontracts', 'subject'],

    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_servicecontracts" 4 times.
    Open

        public $table_name = 'vtiger_servicecontracts';

    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_servicecontractscf" 3 times.
    Open

        public $customFieldTable = ['vtiger_servicecontractscf', 'servicecontractsid'];

    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 "hours" 5 times.
    Open

                } elseif (!empty($ticketData['hours'])) {

    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 "subject" 6 times.
    Open

            'Subject' => 'subject',

    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

            'vtiger_crmentity' => 'crmid',

    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 "servicecontractsid" 8 times.
    Open

        public $table_index = 'servicecontractsid';

    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 "sc_related_to" 3 times.
    Open

            'Related To' => 'sc_related_to',

    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 "used_units" 5 times.
    Open

            'Used Units' => 'used_units',

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

        public function computeUsedUnits($ticketData, $operator = '+')

    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

    Reference to undeclared property \ServiceContracts->id
    Open

            $this->id = $focusId;

    Call to undeclared method \App\Db::createCommand
    Open

                $dbCommand = \App\Db::getInstance()->createCommand();

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

                $serviceContractsInfo = (new \App\Db\Query())->select(['vtiger_crmentity.setype', 'vtiger_servicecontracts.sc_related_to'])

    Call to undeclared method \App\Db::createCommand
    Open

                    App\Db::getInstance()->createCommand()->update('vtiger_troubletickets', ['parent_id' => $serviceContractsInfo['sc_related_to']], ['ticketid' => $ticketId])->execute();

    Argument 2 (end) is float but \App\Fields\DateTime::getDiff() takes string defined at /code/app/Fields/DateTime.php:180
    Open

                $params['planned_duration'] = \App\Fields\DateTime::getDiff($startDate, $dueDate, 'days');

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

            $dataReader = (new \App\Db\Query())->select(['ticketid'])->from('vtiger_troubletickets')

    Call to undeclared method \App\Db::createCommand
    Open

                    $db->createCommand()->update($this->table_name, ['end_date' => $endDate], ['servicecontractsid' => $this->id])->execute();

    Argument 1 (start) is float but \App\Fields\DateTime::getDiff() takes string defined at /code/app/Fields/DateTime.php:180
    Open

                $params['actual_duration'] = \App\Fields\DateTime::getDiff($startDate, $endDate, 'days');

    Call to undeclared method \App\Db::createCommand
    Open

                $db->createCommand()->update($this->table_name, ['end_date' => $endDate], ['servicecontractsid' => $this->id])->execute();

    Invalid offset "tracking_unit" of array type array{}
    Open

            $trackingUnit = strtolower($this->column_fields['tracking_unit']);

    Reference to undeclared property \CRMEntity->column_fields
    Open

                        $totalUsedUnits += $this->computeUsedUnits($ticketFocus->column_fields);

    Argument 1 (str) is null but \strtolower() takes string
    Open

            $trackingUnit = strtolower($this->column_fields['tracking_unit']);

    Call to undeclared method \App\Db::createCommand
    Open

            $db->createCommand()->update($this->table_name, $params, ['servicecontractsid' => $this->id])->execute();

    Call to undeclared method \App\Db::createCommand
    Open

            \App\Db::getInstance()->createCommand()->update($this->table_name, ['used_units' => $usedUnits], ['servicecontractsid' => $this->id])->execute();

    Reference to undeclared property \ServiceContracts->id
    Open

                    $db->createCommand()->update($this->table_name, ['end_date' => $endDate], ['servicecontractsid' => $this->id])->execute();

    Reference to undeclared property \ServiceContracts->id
    Open

                $db->createCommand()->update($this->table_name, ['end_date' => $endDate], ['servicecontractsid' => $this->id])->execute();

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

            $dataReader = (new App\Db\Query())->select(['relcrmid'])

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

                ->union((new App\Db\Query())->select(['crmid'])

    Reference to undeclared property \ServiceContracts->id
    Open

            $db->createCommand()->update($this->table_name, $params, ['servicecontractsid' => $this->id])->execute();

    Reference to undeclared property \CRMEntity->id
    Open

                $ticketFocus->id = $ticketId;

    Reference to undeclared property \CRMEntity->column_fields
    Open

                    if ('closed' === strtolower($ticketFocus->column_fields['ticketstatus'])) {

    Reference to undeclared property \ServiceContracts->id
    Open

            \App\Db::getInstance()->createCommand()->update($this->table_name, ['used_units' => $usedUnits], ['servicecontractsid' => $this->id])->execute();

    Argument 1 (start) is float but \App\Fields\DateTime::getDiff() takes string defined at /code/app/Fields/DateTime.php:180
    Open

                $params['planned_duration'] = \App\Fields\DateTime::getDiff($startDate, $dueDate, 'days');

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

        public $search_fields = [
            // Format: Field Label => Array(tablename, columnname)
            // tablename should not have prefix 'vtiger_'
            'Subject' => ['servicecontracts', 'subject'],
            'Status' => ['servicecontracts', 'contract_status'],
    Severity: Major
    Found in modules/ServiceContracts/ServiceContracts.php and 1 other location - About 2 hrs to fix
    modules/com_vtiger_workflow/expression_engine/VTTokenizer.php on lines 15..29

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

    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

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

            $dataReader = (new App\Db\Query())->select(['relcrmid'])
                ->from('vtiger_crmentityrel')
                ->where(['module' => 'ServiceContracts', 'relmodule' => 'HelpDesk', 'crmid' => $focusId])
                ->union((new App\Db\Query())->select(['crmid'])
                ->from('vtiger_crmentityrel')
    Severity: Major
    Found in modules/ServiceContracts/ServiceContracts.php and 1 other location - About 1 hr to fix
    modules/ServiceContracts/handlers/ServiceContractsHandler.php on lines 30..40

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

    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

    Avoid excessively long variable names like $def_detailview_recname. Keep variable name length under 20.
    Open

        public $def_detailview_recname = 'subject';

    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 ServiceContracts extends CRMEntity

    The property $search_fields is not named in camelCase.
    Open

    class ServiceContracts extends CRMEntity
    {
        public $table_name = 'vtiger_servicecontracts';
        public $table_index = 'servicecontractsid';
        public $column_fields = [];

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $mandatory_fields is not named in camelCase.
    Open

    class ServiceContracts extends CRMEntity
    {
        public $table_name = 'vtiger_servicecontracts';
        public $table_index = 'servicecontractsid';
        public $column_fields = [];

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $popup_fields is not named in camelCase.
    Open

    class ServiceContracts extends CRMEntity
    {
        public $table_name = 'vtiger_servicecontracts';
        public $table_index = 'servicecontractsid';
        public $column_fields = [];

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $default_sort_order is not named in camelCase.
    Open

    class ServiceContracts extends CRMEntity
    {
        public $table_name = 'vtiger_servicecontracts';
        public $table_index = 'servicecontractsid';
        public $column_fields = [];

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $tab_name_index is not named in camelCase.
    Open

    class ServiceContracts extends CRMEntity
    {
        public $table_name = 'vtiger_servicecontracts';
        public $table_index = 'servicecontractsid';
        public $column_fields = [];

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $list_fields_name is not named in camelCase.
    Open

    class ServiceContracts extends CRMEntity
    {
        public $table_name = 'vtiger_servicecontracts';
        public $table_index = 'servicecontractsid';
        public $column_fields = [];

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $tab_name is not named in camelCase.
    Open

    class ServiceContracts extends CRMEntity
    {
        public $table_name = 'vtiger_servicecontracts';
        public $table_index = 'servicecontractsid';
        public $column_fields = [];

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $table_name is not named in camelCase.
    Open

    class ServiceContracts extends CRMEntity
    {
        public $table_name = 'vtiger_servicecontracts';
        public $table_index = 'servicecontractsid';
        public $column_fields = [];

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $column_fields is not named in camelCase.
    Open

    class ServiceContracts extends CRMEntity
    {
        public $table_name = 'vtiger_servicecontracts';
        public $table_index = 'servicecontractsid';
        public $column_fields = [];

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $search_fields_name is not named in camelCase.
    Open

    class ServiceContracts extends CRMEntity
    {
        public $table_name = 'vtiger_servicecontracts';
        public $table_index = 'servicecontractsid';
        public $column_fields = [];

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $table_index is not named in camelCase.
    Open

    class ServiceContracts extends CRMEntity
    {
        public $table_name = 'vtiger_servicecontracts';
        public $table_index = 'servicecontractsid';
        public $column_fields = [];

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $default_order_by is not named in camelCase.
    Open

    class ServiceContracts extends CRMEntity
    {
        public $table_name = 'vtiger_servicecontracts';
        public $table_index = 'servicecontractsid';
        public $column_fields = [];

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $def_basicsearch_col is not named in camelCase.
    Open

    class ServiceContracts extends CRMEntity
    {
        public $table_name = 'vtiger_servicecontracts';
        public $table_index = 'servicecontractsid';
        public $column_fields = [];

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    Avoid variables with short names like $db. Configured minimum length is 3.
    Open

            $db = \App\Db::getInstance();

    ShortVariable

    Since: 0.2

    Detects when a field, local, or parameter has a very short name.

    Example

    class Something {
        private $q = 15; // VIOLATION - Field
        public static function main( array $as ) { // VIOLATION - Formal
            $r = 20 + $this->q; // VIOLATION - Local
            for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                $r += $this->q;
            }
        }
    }

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

    The property $def_detailview_recname is not named in camelCase.
    Open

    class ServiceContracts extends CRMEntity
    {
        public $table_name = 'vtiger_servicecontracts';
        public $table_index = 'servicecontractsid';
        public $column_fields = [];

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $special_functions is not named in camelCase.
    Open

    class ServiceContracts extends CRMEntity
    {
        public $table_name = 'vtiger_servicecontracts';
        public $table_index = 'servicecontractsid';
        public $column_fields = [];

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

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

            'Contract No' => 'contract_no',

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

         * @var string[] List of fields in the RelationListView

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

            'Status' => ['servicecontracts', 'contract_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

            'vtiger_servicecontracts' => 'servicecontractsid',

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

            'vtiger_servicecontractscf' => 'servicecontractsid',

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

            'Subject' => ['servicecontracts', 'subject'],

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

        /** Indicator if this is a custom module or standard module */

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

         * Mandatory for Saving, Include tablename and tablekey columnname here.

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

            'Used Units' => 'used_units',

    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 $column_fields = [];

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

            'Status' => 'contract_status',

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

        public $table_name = 'vtiger_servicecontracts';

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

         */

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

            'vtiger_entity_stats' => 'crmid', ];

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

         * Mandatory for Saving, Include tables related to this module.

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

            'Assigned To' => 'assigned_user_id',

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

        // For Popup listview and UI type support

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

            'Due Date' => ['servicecontracts', 'due_date'],

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

        public $tab_name_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

        public $search_fields = [

    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 $tab_name = ['vtiger_crmentity', 'vtiger_servicecontracts', 'vtiger_servicecontractscf', 'vtiger_entity_stats'];

    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 $relationFields = [];

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

            'Start Date' => ['servicecontracts', 'start_date'],

    Line exceeds 120 characters; contains 123 characters
    Open

        public $tab_name = ['vtiger_crmentity', 'vtiger_servicecontracts', 'vtiger_servicecontractscf', 'vtiger_entity_stats'];

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

            'Related To' => 'sc_related_to',

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

            'Subject' => 'subject',

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

            // Format: Field Label => Array(tablename, columnname)

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

        public $table_index = 'servicecontractsid';

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

            'vtiger_crmentity' => 'crmid',

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

        public $list_fields_name = [

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

            // Format: Field Label => fieldname

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

        // Column value to use on detail view record text display

    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 moduleHandler($moduleName, $eventType)

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

            } elseif ('module.disabled' === $eventType) {

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

        }

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

            $usedUnits = 0;

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

        public function updateUsedUnits($usedUnits)

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

         */

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

            'Assigned To' => ['crmentity', 'smownerid'],

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

        public $default_sort_order = 'ASC';

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

            if ('module.postinstall' === $eventType) {

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

                $accModuleInstance = vtlib\Module::getInstance('Accounts');

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

                $helpDeskInstance = vtlib\Module::getInstance('HelpDesk');

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

                // Mark the module as Standard module

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

            $this->id = $focusId;

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

            $this->calculateProgress();

    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 $IsCustomModule = true;

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

         * Mandatory table for supporting custom fields.

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

        public $customFieldTable = ['vtiger_servicecontractscf', 'servicecontractsid'];

    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 $search_fields_name = [];

    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 $popup_fields = ['subject'];

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

        public $def_detailview_recname = 'subject';

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

            'Total Units' => 'total_units',

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

            } elseif ('module.enabled' === $eventType) {

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

            // tablename should not have prefix 'vtiger_'

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

                App\EventHandler::setActive('ServiceContracts_ServiceContractsHandler_Handler');

    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

                    ->where(['vtiger_servicecontracts.servicecontractsid' => $focusId])->one();

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

                $moduleInstance = vtlib\Module::getInstance($moduleName);

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

        {

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

            $this->retrieveEntityInfo($focusId, 'ServiceContracts');

    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

        }

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

                ->union((new App\Db\Query())->select(['crmid'])

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

            $contractStatus = $this->column_fields['contract_status'];

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

                ->where(['relmodule' => 'ServiceContracts', 'module' => 'HelpDesk', 'relcrmid' => $focusId]))

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

                ->createCommand()->query();

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

                    $ticketFocus->retrieveEntityInfo($ticketId, 'HelpDesk');

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

        // Function to Upate the Used Units of the Service Contract based on the given Ticket id.

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

         * Function to Upate the Used Units of the Service Contract.

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

            $db = \App\Db::getInstance();

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

        /**

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

                $accModuleInstance->setRelatedList($moduleInstance, 'Service Contracts', ['add'], 'getDependentsList');

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

                App\EventHandler::setInActive('ServiceContracts_ServiceContractsHandler_Handler');

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

                    App\Db::getInstance()->createCommand()->update('vtiger_troubletickets', ['parent_id' => $serviceContractsInfo['sc_related_to']], ['ticketid' => $ticketId])->execute();

    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

                if (\App\Record::isExists($ticketId)) {

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

                    }

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

                    $usedUnits = $ticketData['hours'] / $workingHoursPerDay;

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

                if (!empty($ticketData['hours'])) {

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

                }

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

            'Total Units' => ['servicecontracts', 'total_units'],

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

        // Refers to vtiger_field.fieldname values.

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

                ->where(['module' => 'ServiceContracts', 'relmodule' => 'HelpDesk', 'crmid' => $focusId])

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

            $totalUsedUnits = 0;

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

        public function computeUsedUnits($ticketData, $operator = '+')

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

            $trackingUnit = strtolower($this->column_fields['tracking_unit']);

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

        // Used when enabling/disabling the mandatory fields for the module.

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

        public $special_functions = ['set_import_assigned_user'];

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

         * Invoked when special actions are performed on the 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

         * Function to Update the parent_id of HelpDesk with sc_related_to of ServiceContracts if the parent_id is not set.

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

            $dataReader = (new \App\Db\Query())->select(['ticketid'])->from('vtiger_troubletickets')

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

            while ($ticketId = $dataReader->readColumn(0)) {

    Line exceeds 120 characters; contains 131 characters
    Open

        // Function to Compute and Update the Used Units and Progress of the Service Contract based on all the related Trouble tickets.

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

        public function updateServiceContractState($focusId)

    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

            $this->updateUsedUnits($totalUsedUnits);

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

                if (!empty($ticketData['days'])) {

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

                    $usedUnits = $ticketData['days'];

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

                } elseif (!empty($ticketData['hours'])) {

    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\Db::getInstance()->createCommand()->update($this->table_name, ['used_units' => $usedUnits], ['servicecontractsid' => $this->id])->execute();

    Line exceeds 120 characters; contains 153 characters
    Open

            \App\Db::getInstance()->createCommand()->update($this->table_name, ['used_units' => $usedUnits], ['servicecontractsid' => $this->id])->execute();

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

            $usedUnits = \vtlib\Functions::formatDecimal($this->column_fields['used_units']);

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

            $totalUnits = \vtlib\Functions::formatDecimal($this->column_fields['total_units']);

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

            // Update the End date if the status is Complete or if the Used Units reaches/exceeds Total Units

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

            'Related to' => ['servicecontracts', 'sc_related_to'],

    Line exceeds 120 characters; contains 135 characters
    Open

                $serviceContractsInfo = (new \App\Db\Query())->select(['vtiger_crmentity.setype', 'vtiger_servicecontracts.sc_related_to'])

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

                if ('Accounts' === $serviceContractsInfo['setype']) {

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

            } elseif ('hours' == $trackingUnit) {

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

            $this->column_fields['used_units'] = $usedUnits;

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

            $endDate = $this->column_fields['end_date'];

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

        public $def_basicsearch_col = 'subject';

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

        public $default_order_by = '';

    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 $moduleName

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

                $conModuleInstance = vtlib\Module::getInstance('Contacts');

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

                $ticketFocus->id = $ticketId;

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

            if ('incidents' == $trackingUnit) {

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

                    $usedUnits = $ticketData['hours'];

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

        {

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

            $dueDate = $this->column_fields['due_date'];

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

            $db->createCommand()->update($this->table_name, $params, ['servicecontractsid' => $this->id])->execute();

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

        public $mandatory_fields = ['subject', 'assigned_user_id'];

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

                $dbCommand = \App\Db::getInstance()->createCommand();

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

         * @param int $focusId

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

                    ->leftJoin('vtiger_crmentity', 'vtiger_crmentity.crmid = vtiger_servicecontracts.sc_related_to')

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

            $workingHoursPerDay = 24;

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

            return $usedUnits;

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

         *

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

                $params['actual_duration'] = \App\Fields\DateTime::getDiff($startDate, $endDate, 'days');

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

        // For Alphabetical search

    Line exceeds 120 characters; contains 122 characters
    Open

                $dbCommand->update('vtiger_contract_status', ['presence' => 0], ['contract_status' => 'Complete'])->execute();

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

                $dbCommand->update('vtiger_tab', ['customized' => 0], ['name' => $moduleName])->execute();

    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 Compute and Update the Used Units and Progress of the Service Contract based on all the related Trouble tickets.

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

            $dataReader = (new App\Db\Query())->select(['relcrmid'])

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

            while ($ticketId = $dataReader->readColumn(0)) {

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

                    if ('closed' === strtolower($ticketFocus->column_fields['ticketstatus'])) {

    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 {

    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

            if (!empty($endDate) && !empty($startDate)) {

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

                $params['progress'] = null;

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

            'Contract No' => ['servicecontracts', 'contract_no'],

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

        // Callback function list during Importing

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

         * @param int $entityIds

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

                $serviceContractsInfo = (new \App\Db\Query())->select(['vtiger_crmentity.setype', 'vtiger_servicecontracts.sc_related_to'])

    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

                }

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

         * @param float $usedUnits

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

            // We need to do this first to make sure Actual duration is computed properly

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

            'Used Units' => ['servicecontracts', 'used_units'],

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

        // For Popup window record selection

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

                // Make the picklist value 'Complete' for status as non-editable

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

                $dbCommand->update('vtiger_contract_status', ['presence' => 0], ['contract_status' => 'Complete'])->execute();

    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

                    $usedUnits = $ticketData['days'] * $workingHoursPerDay;

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

            $startDate = $this->column_fields['start_date'];

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

                    ->from('vtiger_servicecontracts')

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

            $ticketFocus = CRMEntity::getInstance('HelpDesk');

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

            } elseif ('days' == $trackingUnit) {

    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 Calculate the End Date, Planned Duration, Actual Duration and Progress of a Service Contract.

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

            if ('Complete' === $contractStatus || (!empty($usedUnits) && !empty($totalUnits) && $usedUnits >= $totalUnits)) {

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

                    $endDate = date('Y-m-d');

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

                $params['planned_duration'] = '';

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

            // Calculate the Actual Duration based on End date and Start date. (in days)

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

            'Type' => ['servicecontracts', 'contract_type'],

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

         * @param string $eventType

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

                $helpDeskInstance->setRelatedList($moduleInstance, 'Service Contracts', ['ADD', 'SELECT']);

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

                // Initialize module sequence for the 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

                ->createCommand()->query();

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

                        $totalUsedUnits += $this->computeUsedUnits($ticketFocus->column_fields);

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

                $usedUnits = 1;

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

                } elseif (!empty($ticketData['days'])) {

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

         */

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

            $params = [];

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

                $db->createCommand()->update($this->table_name, ['end_date' => $endDate], ['servicecontractsid' => $this->id])->execute();

    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 {

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

                if (empty($endDate)) {

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

            if (!empty($dueDate) && !empty($startDate)) {

    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

                $conModuleInstance->setRelatedList($moduleInstance, 'Service Contracts', ['add'], 'getDependentsList');

    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 updateHelpDeskRelatedTo($focusId, $entityIds)

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

                ->where(['and', ['or', ['parent_id' => null], ['parent_id' => 0]], ['ticketid' => $entityIds]])

    Line exceeds 120 characters; contains 183 characters
    Open

                    App\Db::getInstance()->createCommand()->update('vtiger_troubletickets', ['parent_id' => $serviceContractsInfo['sc_related_to']], ['ticketid' => $ticketId])->execute();

    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 calculateProgress()

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

            // Calculate the Planned Duration based on Due date and Start date. (in days)

    Line exceeds 120 characters; contains 138 characters
    Open

                    $db->createCommand()->update($this->table_name, ['end_date' => $endDate], ['servicecontractsid' => $this->id])->execute();

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

                $endDate = null;

    Line exceeds 120 characters; contains 121 characters
    Open

            if ('Complete' === $contractStatus || (!empty($usedUnits) && !empty($totalUnits) && $usedUnits >= $totalUnits)) {

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

            if (!empty($usedUnits) && !empty($totalUnits)) {

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

                    $db->createCommand()->update($this->table_name, ['end_date' => $endDate], ['servicecontractsid' => $this->id])->execute();

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

                $params['planned_duration'] = \App\Fields\DateTime::getDiff($startDate, $dueDate, 'days');

    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

                $params['actual_duration'] = '';

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

                }

    Line exceeds 120 characters; contains 134 characters
    Open

                $db->createCommand()->update($this->table_name, ['end_date' => $endDate], ['servicecontractsid' => $this->id])->execute();

    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

            // Update the Progress based on Used Units and Total Units (in percentage)

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

        }

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

                $params['progress'] = (float) (($usedUnits * 100) / $totalUnits);

    There are no issues that match your filters.

    Category
    Status