Function calculateProgress
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function calculateProgress()
{
$db = \App\Db::getInstance();
$params = [];
- Read upRead up
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 = [];
- Read upRead up
- Exclude checks
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 = [];
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;
- Read upRead up
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'])
- Read upRead up
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 = [];
- Read upRead up
- Exclude checks
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'])
- Read upRead up
- Exclude checks
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'])
- Read upRead up
- Exclude checks
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')
- Read upRead up
- Exclude checks
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'])
- Read upRead up
- Exclude checks
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'] = '';
}
- Read upRead up
- Exclude checks
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'] = '';
}
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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;
}
- Read upRead up
- Exclude checks
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)) {
- Read upRead up
- Exclude checks
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();
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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']);
- Read upRead up
- Exclude checks
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();
}
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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']);
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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'];
- Read upRead up
- Exclude checks
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'];
- Read upRead up
- Exclude checks
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',
- Read upRead up
- Exclude checks
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',
- Read upRead up
- Exclude checks
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]])
- Read upRead up
- Exclude checks
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')
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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'],
- Read upRead up
- Exclude checks
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';
- Read upRead up
- Exclude checks
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'];
- Read upRead up
- Exclude checks
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'])) {
- Read upRead up
- Exclude checks
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',
- Read upRead up
- Exclude checks
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',
- Read upRead up
- Exclude checks
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';
- Read upRead up
- Exclude checks
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',
- Read upRead up
- Exclude checks
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',
- Read upRead up
- Exclude checks
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 = '+')
- Read upRead up
- Exclude checks
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;
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$dbCommand = \App\Db::getInstance()->createCommand();
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$serviceContractsInfo = (new \App\Db\Query())->select(['vtiger_crmentity.setype', 'vtiger_servicecontracts.sc_related_to'])
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
App\Db::getInstance()->createCommand()->update('vtiger_troubletickets', ['parent_id' => $serviceContractsInfo['sc_related_to']], ['ticketid' => $ticketId])->execute();
- Exclude checks
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');
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$dataReader = (new \App\Db\Query())->select(['ticketid'])->from('vtiger_troubletickets')
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$db->createCommand()->update($this->table_name, ['end_date' => $endDate], ['servicecontractsid' => $this->id])->execute();
- Exclude checks
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');
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$db->createCommand()->update($this->table_name, ['end_date' => $endDate], ['servicecontractsid' => $this->id])->execute();
- Exclude checks
Invalid offset "tracking_unit"
of array type array{}
Open
$trackingUnit = strtolower($this->column_fields['tracking_unit']);
- Exclude checks
Reference to undeclared property \CRMEntity->column_fields
Open
$totalUsedUnits += $this->computeUsedUnits($ticketFocus->column_fields);
- Exclude checks
Argument 1 (str)
is null
but \strtolower()
takes string
Open
$trackingUnit = strtolower($this->column_fields['tracking_unit']);
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$db->createCommand()->update($this->table_name, $params, ['servicecontractsid' => $this->id])->execute();
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
\App\Db::getInstance()->createCommand()->update($this->table_name, ['used_units' => $usedUnits], ['servicecontractsid' => $this->id])->execute();
- Exclude checks
Reference to undeclared property \ServiceContracts->id
Open
$db->createCommand()->update($this->table_name, ['end_date' => $endDate], ['servicecontractsid' => $this->id])->execute();
- Exclude checks
Reference to undeclared property \ServiceContracts->id
Open
$db->createCommand()->update($this->table_name, ['end_date' => $endDate], ['servicecontractsid' => $this->id])->execute();
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$dataReader = (new App\Db\Query())->select(['relcrmid'])
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
->union((new App\Db\Query())->select(['crmid'])
- Exclude checks
Reference to undeclared property \ServiceContracts->id
Open
$db->createCommand()->update($this->table_name, $params, ['servicecontractsid' => $this->id])->execute();
- Exclude checks
Reference to undeclared property \CRMEntity->id
Open
$ticketFocus->id = $ticketId;
- Exclude checks
Reference to undeclared property \CRMEntity->column_fields
Open
if ('closed' === strtolower($ticketFocus->column_fields['ticketstatus'])) {
- Exclude checks
Reference to undeclared property \ServiceContracts->id
Open
\App\Db::getInstance()->createCommand()->update($this->table_name, ['used_units' => $usedUnits], ['servicecontractsid' => $this->id])->execute();
- Exclude checks
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');
- Exclude checks
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'],
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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')
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Avoid excessively long variable names like $def_detailview_recname. Keep variable name length under 20. Open
public $def_detailview_recname = 'subject';
- Read upRead up
- Exclude checks
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
- Exclude checks
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 = [];
- Read upRead up
- Exclude checks
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 = [];
- Read upRead up
- Exclude checks
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 = [];
- Read upRead up
- Exclude checks
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 = [];
- Read upRead up
- Exclude checks
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 = [];
- Read upRead up
- Exclude checks
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 = [];
- Read upRead up
- Exclude checks
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 = [];
- Read upRead up
- Exclude checks
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 = [];
- Read upRead up
- Exclude checks
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 = [];
- Read upRead up
- Exclude checks
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 = [];
- Read upRead up
- Exclude checks
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 = [];
- Read upRead up
- Exclude checks
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 = [];
- Read upRead up
- Exclude checks
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 = [];
- Read upRead up
- Exclude checks
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();
- Read upRead up
- Exclude checks
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 = [];
- Read upRead up
- Exclude checks
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 = [];
- Read upRead up
- Exclude checks
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',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var string[] List of fields in the RelationListView
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Status' => ['servicecontracts', 'contract_status'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'vtiger_servicecontracts' => 'servicecontractsid',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'vtiger_servicecontractscf' => 'servicecontractsid',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Subject' => ['servicecontracts', 'subject'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** Indicator if this is a custom module or standard module */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Mandatory for Saving, Include tablename and tablekey columnname here.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Used Units' => 'used_units',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $column_fields = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Status' => 'contract_status',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $table_name = 'vtiger_servicecontracts';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'vtiger_entity_stats' => 'crmid', ];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Mandatory for Saving, Include tables related to this module.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Assigned To' => 'assigned_user_id',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// For Popup listview and UI type support
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Due Date' => ['servicecontracts', 'due_date'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $tab_name_index = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $search_fields = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $tab_name = ['vtiger_crmentity', 'vtiger_servicecontracts', 'vtiger_servicecontractscf', 'vtiger_entity_stats'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $relationFields = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Start Date' => ['servicecontracts', 'start_date'],
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
public $tab_name = ['vtiger_crmentity', 'vtiger_servicecontracts', 'vtiger_servicecontractscf', 'vtiger_entity_stats'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Related To' => 'sc_related_to',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Subject' => 'subject',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Format: Field Label => Array(tablename, columnname)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $table_index = 'servicecontractsid';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'vtiger_crmentity' => 'crmid',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $list_fields_name = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Format: Field Label => fieldname
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Column value to use on detail view record text display
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function moduleHandler($moduleName, $eventType)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ('module.disabled' === $eventType) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$usedUnits = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function updateUsedUnits($usedUnits)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Assigned To' => ['crmentity', 'smownerid'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $default_sort_order = 'ASC';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('module.postinstall' === $eventType) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$accModuleInstance = vtlib\Module::getInstance('Accounts');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$helpDeskInstance = vtlib\Module::getInstance('HelpDesk');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Mark the module as Standard module
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->id = $focusId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->calculateProgress();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $IsCustomModule = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Mandatory table for supporting custom fields.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $customFieldTable = ['vtiger_servicecontractscf', 'servicecontractsid'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $search_fields_name = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $popup_fields = ['subject'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $def_detailview_recname = 'subject';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Total Units' => 'total_units',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ('module.enabled' === $eventType) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// tablename should not have prefix 'vtiger_'
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
App\EventHandler::setActive('ServiceContracts_ServiceContractsHandler_Handler');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['vtiger_servicecontracts.servicecontractsid' => $focusId])->one();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleInstance = vtlib\Module::getInstance($moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->retrieveEntityInfo($focusId, 'ServiceContracts');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('vtiger_crmentityrel')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->union((new App\Db\Query())->select(['crmid'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$contractStatus = $this->column_fields['contract_status'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['relmodule' => 'ServiceContracts', 'module' => 'HelpDesk', 'relcrmid' => $focusId]))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$ticketFocus->retrieveEntityInfo($ticketId, 'HelpDesk');
- Exclude checks
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.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to Upate the Used Units of the Service Contract.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$db = \App\Db::getInstance();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$accModuleInstance->setRelatedList($moduleInstance, 'Service Contracts', ['add'], 'getDependentsList');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
App\EventHandler::setInActive('ServiceContracts_ServiceContractsHandler_Handler');
- Exclude checks
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();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\App\Record::isExists($ticketId)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$usedUnits = $ticketData['hours'] / $workingHoursPerDay;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($ticketData['hours'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Total Units' => ['servicecontracts', 'total_units'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Refers to vtiger_field.fieldname values.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['module' => 'ServiceContracts', 'relmodule' => 'HelpDesk', 'crmid' => $focusId])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$totalUsedUnits = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function computeUsedUnits($ticketData, $operator = '+')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$trackingUnit = strtolower($this->column_fields['tracking_unit']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Used when enabling/disabling the mandatory fields for the module.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $special_functions = ['set_import_assigned_user'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Invoked when special actions are performed on the module.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
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.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = (new \App\Db\Query())->select(['ticketid'])->from('vtiger_troubletickets')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($ticketId = $dataReader->readColumn(0)) {
- Exclude checks
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.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function updateServiceContractState($focusId)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader->close();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->updateUsedUnits($totalUsedUnits);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($ticketData['days'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$usedUnits = $ticketData['days'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif (!empty($ticketData['hours'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
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();
- Exclude checks
Line exceeds 120 characters; contains 153 characters Open
\App\Db::getInstance()->createCommand()->update($this->table_name, ['used_units' => $usedUnits], ['servicecontractsid' => $this->id])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$usedUnits = \vtlib\Functions::formatDecimal($this->column_fields['used_units']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$totalUnits = \vtlib\Functions::formatDecimal($this->column_fields['total_units']);
- Exclude checks
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
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Related to' => ['servicecontracts', 'sc_related_to'],
- Exclude checks
Line exceeds 120 characters; contains 135 characters Open
$serviceContractsInfo = (new \App\Db\Query())->select(['vtiger_crmentity.setype', 'vtiger_servicecontracts.sc_related_to'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('Accounts' === $serviceContractsInfo['setype']) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ('hours' == $trackingUnit) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->column_fields['used_units'] = $usedUnits;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$endDate = $this->column_fields['end_date'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $def_basicsearch_col = 'subject';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $default_order_by = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $moduleName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$conModuleInstance = vtlib\Module::getInstance('Contacts');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$ticketFocus->id = $ticketId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('incidents' == $trackingUnit) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$usedUnits = $ticketData['hours'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dueDate = $this->column_fields['due_date'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$db->createCommand()->update($this->table_name, $params, ['servicecontractsid' => $this->id])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $mandatory_fields = ['subject', 'assigned_user_id'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dbCommand = \App\Db::getInstance()->createCommand();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $focusId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->leftJoin('vtiger_crmentity', 'vtiger_crmentity.crmid = vtiger_servicecontracts.sc_related_to')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$workingHoursPerDay = 24;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $usedUnits;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['actual_duration'] = \App\Fields\DateTime::getDiff($startDate, $endDate, 'days');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// For Alphabetical search
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
$dbCommand->update('vtiger_contract_status', ['presence' => 0], ['contract_status' => 'Complete'])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dbCommand->update('vtiger_tab', ['customized' => 0], ['name' => $moduleName])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
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.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = (new App\Db\Query())->select(['relcrmid'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($ticketId = $dataReader->readColumn(0)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('closed' === strtolower($ticketFocus->column_fields['ticketstatus'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($endDate) && !empty($startDate)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['progress'] = null;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Contract No' => ['servicecontracts', 'contract_no'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Callback function list during Importing
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $entityIds
- Exclude checks
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'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('vtiger_crmentityrel')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param float $usedUnits
- Exclude checks
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
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Used Units' => ['servicecontracts', 'used_units'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// For Popup window record selection
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Make the picklist value 'Complete' for status as non-editable
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dbCommand->update('vtiger_contract_status', ['presence' => 0], ['contract_status' => 'Complete'])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$usedUnits = $ticketData['days'] * $workingHoursPerDay;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$startDate = $this->column_fields['start_date'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('vtiger_servicecontracts')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$ticketFocus = CRMEntity::getInstance('HelpDesk');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ('days' == $trackingUnit) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
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.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('Complete' === $contractStatus || (!empty($usedUnits) && !empty($totalUnits) && $usedUnits >= $totalUnits)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$endDate = date('Y-m-d');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['planned_duration'] = '';
- Exclude checks
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)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Type' => ['servicecontracts', 'contract_type'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $eventType
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$helpDeskInstance->setRelatedList($moduleInstance, 'Service Contracts', ['ADD', 'SELECT']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Initialize module sequence for the module
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$totalUsedUnits += $this->computeUsedUnits($ticketFocus->column_fields);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$usedUnits = 1;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif (!empty($ticketData['days'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params = [];
- Exclude checks
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();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($endDate)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($dueDate) && !empty($startDate)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$conModuleInstance->setRelatedList($moduleInstance, 'Service Contracts', ['add'], 'getDependentsList');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function updateHelpDeskRelatedTo($focusId, $entityIds)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['and', ['or', ['parent_id' => null], ['parent_id' => 0]], ['ticketid' => $entityIds]])
- Exclude checks
Line exceeds 120 characters; contains 183 characters Open
App\Db::getInstance()->createCommand()->update('vtiger_troubletickets', ['parent_id' => $serviceContractsInfo['sc_related_to']], ['ticketid' => $ticketId])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function calculateProgress()
- Exclude checks
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)
- Exclude checks
Line exceeds 120 characters; contains 138 characters Open
$db->createCommand()->update($this->table_name, ['end_date' => $endDate], ['servicecontractsid' => $this->id])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$endDate = null;
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
if ('Complete' === $contractStatus || (!empty($usedUnits) && !empty($totalUnits) && $usedUnits >= $totalUnits)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($usedUnits) && !empty($totalUnits)) {
- Exclude checks
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();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['planned_duration'] = \App\Fields\DateTime::getDiff($startDate, $dueDate, 'days');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['actual_duration'] = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 134 characters Open
$db->createCommand()->update($this->table_name, ['end_date' => $endDate], ['servicecontractsid' => $this->id])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Update the Progress based on Used Units and Total Units (in percentage)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['progress'] = (float) (($usedUnits * 100) / $totalUnits);
- Exclude checks