Function vtwsConvertlead
has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring. Open
public static function vtwsConvertlead($entityvalues, Users_Record_Model $user)
{
\App\Log::trace('Start ' . __METHOD__);
if (empty($entityvalues['assignedTo'])) {
$entityvalues['assignedTo'] = $user->id;
- 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
Method vtwsConvertlead
has 78 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function vtwsConvertlead($entityvalues, Users_Record_Model $user)
{
\App\Log::trace('Start ' . __METHOD__);
if (empty($entityvalues['assignedTo'])) {
$entityvalues['assignedTo'] = $user->id;
Function vtwsPopulateConvertLeadEntities
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
public static function vtwsPopulateConvertLeadEntities($entityvalue, $entity, Vtiger_Record_Model $recordModel, $leadinfo)
{
$targetModuleModel = Vtiger_Module_Model::getInstance($entityvalue['name']);
$entityName = $entityvalue['name'];
$dataReader = (new \App\Db\Query())->from('vtiger_convertleadmapping')->createCommand()->query();
- 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
Method vtwsPopulateConvertLeadEntities
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function vtwsPopulateConvertLeadEntities($entityvalue, $entity, Vtiger_Record_Model $recordModel, $leadinfo)
{
$targetModuleModel = Vtiger_Module_Model::getInstance($entityvalue['name']);
$entityName = $entityvalue['name'];
$dataReader = (new \App\Db\Query())->from('vtiger_convertleadmapping')->createCommand()->query();
Function vtwsValidateConvertLeadEntityMandatoryValues
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static function vtwsValidateConvertLeadEntityMandatoryValues($entity, Vtiger_Module_Model $targetModuleModel)
{
$mandatoryFields = $targetModuleModel->getMandatoryFieldModels();
foreach ($mandatoryFields as $field => $fieldModel) {
if (empty($entity[$field])) {
- 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 vtwsUpdateConvertLeadStatus
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function vtwsUpdateConvertLeadStatus($entityIds, $leadId, Users_Record_Model $user)
{
$db = \App\Db::getInstance();
if ('' != $entityIds['Accounts'] || '' != $entityIds['Contacts']) {
\App\Cache::delete('Leads.converted', $leadId);
- 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 vtwsConvertlead() has an NPath complexity of 4680. The configured NPath complexity threshold is 200. Open
public static function vtwsConvertlead($entityvalues, Users_Record_Model $user)
{
\App\Log::trace('Start ' . __METHOD__);
if (empty($entityvalues['assignedTo'])) {
$entityvalues['assignedTo'] = $user->id;
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method vtwsPopulateConvertLeadEntities() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
public static function vtwsPopulateConvertLeadEntities($entityvalue, $entity, Vtiger_Record_Model $recordModel, $leadinfo)
{
$targetModuleModel = Vtiger_Module_Model::getInstance($entityvalue['name']);
$entityName = $entityvalue['name'];
$dataReader = (new \App\Db\Query())->from('vtiger_convertleadmapping')->createCommand()->query();
- 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
The method vtwsConvertlead() has a Cyclomatic Complexity of 20. The configured cyclomatic complexity threshold is 10. Open
public static function vtwsConvertlead($entityvalues, Users_Record_Model $user)
{
\App\Log::trace('Start ' . __METHOD__);
if (empty($entityvalues['assignedTo'])) {
$entityvalues['assignedTo'] = $user->id;
- 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
Refactor this function to reduce its Cognitive Complexity from 22 to the 15 allowed. Open
public static function vtwsPopulateConvertLeadEntities($entityvalue, $entity, Vtiger_Record_Model $recordModel, $leadinfo)
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Refactor this function to reduce its Cognitive Complexity from 41 to the 15 allowed. Open
public static function vtwsConvertlead($entityvalues, Users_Record_Model $user)
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
The class WebservicesConvertLead has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13. Open
class WebservicesConvertLead
{
/**
* The function convert the lead.
*
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
Missing class import via use statement (line '40', column '23'). Open
$eventHandler = new App\EventHandler();
- 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 '88', column '16'). Open
throw new WebServiceException('UNKNOWN_OPERATION', $e->getMessage() . ' : ' . $entityvalue['name']);
- 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 '132', column '22'). Open
$dataReader = (new \App\Db\Query())->from('vtiger_convertleadmapping')->createCommand()->query();
- 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 '236', column '15'). Open
throw new WebServiceException('FAILED_TO_MARK_LEAD_CONVERTED', 'Failed mark lead converted');
- 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 '34', column '12'). Open
if ((new \App\Db\Query())->select(['converted'])->from('vtiger_leaddetails')->where(['converted' => 1, 'leadid' => $leadIdComponents])->exists()) {
- 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 '37', column '14'). Open
throw new WebServiceException('LEAD_ALREADY_CONVERTED', $translateAlreadyConvertedError);
- 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
Avoid using static access to class '\WebservicesUtils' in method 'vtwsConvertlead'. Open
\WebservicesUtils::vtwsGetRelatedActivities($leadIdComponents, $accountId, $contactId, $relatedId);
- 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\Log' in method 'vtwsConvertlead'. Open
\App\Log::trace('End ' . __METHOD__);
- 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 '\WebservicesUtils' in method 'vtwsConvertLeadTransferHandler'. Open
\WebservicesUtils::vtwsTransferLeadRelatedRecords($leadIdComponents, $entityidComponents, $entityvalues['transferRelatedRecordsTo']);
- 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\Log' in method 'vtwsConvertlead'. Open
\App\Log::trace('Start ' . __METHOD__);
- 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\Log' in method 'vtwsConvertlead'. Open
\App\Log::error('Error converting a lead: ' . $translateAlreadyConvertedError);
- 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\Log' in method 'vtwsConvertlead'. Open
\App\Log::error('Error converting a lead: ' . $e->getMessage());
- 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 vtwsConvertlead uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$defaultValue = $fieldModel->getDefaultFieldValue();
if ('' !== $defaultValue) {
$recordModel->set($fieldName, $defaultValue);
}
- 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 'Vtiger_Module_Model' in method 'vtwsPopulateConvertLeadEntities'. Open
$targetModuleModel = Vtiger_Module_Model::getInstance($entityvalue['name']);
- 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 'Vtiger_Record_Model' in method 'vtwsConvertlead'. Open
$recordModel = Vtiger_Record_Model::getInstanceById($entityvalues['leadId']);
- 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\Language' in method 'vtwsConvertlead'. Open
$translateAlreadyConvertedError = \App\Language::translate('LBL_LEAD_ALREADY_CONVERTED', 'Leads');
- 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 'vtwsUpdateConvertLeadStatus'. 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 '\WebservicesUtils' in method 'vtwsPopulateConvertLeadEntities'. Open
$entityField = \WebservicesUtils::vtwsGetFieldfromFieldId($row[$column], $targetModuleModel);
- 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 '\WebservicesUtils' in method 'vtwsPopulateConvertLeadEntities'. Open
$leadField = \WebservicesUtils::vtwsGetFieldfromFieldId($row['leadfid'], $recordModel->getModule());
- 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 'Vtiger_Record_Model' in method 'vtwsConvertlead'. Open
$recordModel = Vtiger_Record_Model::getCleanInstance($entityvalue['name']);
- 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\Cache' in method 'vtwsUpdateConvertLeadStatus'. Open
\App\Cache::delete('Leads.converted', $leadId);
- 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 'Vtiger_Module_Model' in method 'vtwsUpdateConvertLeadStatus'. Open
$moduleModel = Vtiger_Module_Model::getInstance($module);
- 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\Log' in method 'vtwsConvertlead'. Open
\App\Log::error('Error converting a lead: ' . $e->getMessage());
- 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 vtwsValidateConvertLeadEntityMandatoryValues uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$entity[$field] = '????';
}
- 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
Define a constant instead of duplicating this literal "Contacts" 7 times. Open
$availableModules = ['Accounts', 'Contacts'];
- 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 "create" 3 times. Open
if (empty($entityvalues['entities']['Accounts']['create']) && empty($entityvalues['entities']['Contacts']['create'])) {
- 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 "converted" 3 times. Open
if ((new \App\Db\Query())->select(['converted'])->from('vtiger_leaddetails')->where(['converted' => 1, 'leadid' => $leadIdComponents])->exists()) {
- 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 "convert_to_id" 3 times. Open
if ('Accounts' == $entityvalue['name'] && !empty($entityvalue['convert_to_id']) && \is_int($entityvalue['convert_to_id'])) {
- 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 "Accounts" 10 times. Open
$entityvalues['transferRelatedRecordsTo'] = 'Accounts';
- 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 "Error converting a lead: " 3 times. Open
\App\Log::error('Error converting a lead: ' . $translateAlreadyConvertedError);
- 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 "leadId" 3 times. Open
$recordModel = Vtiger_Record_Model::getInstanceById($entityvalues['leadId']);
- 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 "assignedTo" 3 times. Open
if (empty($entityvalues['assignedTo'])) {
- 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 "transferRelatedRecordsTo" 5 times. Open
if (empty($entityvalues['transferRelatedRecordsTo'])) {
- 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 "entities" 4 times. Open
if (empty($entityvalues['entities']['Accounts']['create']) && empty($entityvalues['entities']['Contacts']['create'])) {
- 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.
Call to method error
from undeclared class \App\Log
Open
\App\Log::error('Error converting a lead: ' . $e->getMessage());
- Exclude checks
Invalid offset "leadId"
of array type array{assignedTo:}|array{transferRelatedRecordsTo:'Accounts'}|array{transferRelatedRecordsTo:mixed,assignedTo:}|string
Open
$recordModel = Vtiger_Record_Model::getInstanceById($entityvalues['leadId']);
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
if ((new \App\Db\Query())->select(['converted'])->from('vtiger_leaddetails')->where(['converted' => 1, 'leadid' => $leadIdComponents])->exists()) {
- Exclude checks
Call to method trace
from undeclared class \App\Log
Open
\App\Log::trace('End ' . __METHOD__);
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$db->createCommand()
- Exclude checks
Argument 2 (entityIds)
is array<string>|array<string>|array{Accounts:mixed}|array{}</string></string>
but \WebservicesConvertLead::vtwsConvertLeadTransferHandler()
takes int
defined at /code/include/Webservices/ConvertLead.php:209
Open
static::vtwsConvertLeadTransferHandler($leadIdComponents, $entityIds, $entityvalues);
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$dataReader = (new \App\Db\Query())->from('vtiger_convertleadmapping')->createCommand()->query();
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$result = $db->createCommand()
- Exclude checks
When fetching an array index from a value of type string,
found an array index of type 'transferRelatedRecordsTo',
but expected the index to be of type int
Open
\WebservicesUtils::vtwsTransferLeadRelatedRecords($leadIdComponents, $entityidComponents, $entityvalues['transferRelatedRecordsTo']);
- Exclude checks
When appending to a value of type string,
found an array access index of type 'assignedTo',
but expected the index to be of type int
Open
$entityvalues['assignedTo'] = $user->id;
- Exclude checks
Invalid offset "entities"
of array type array{assignedTo:}|array{transferRelatedRecordsTo:'Accounts'}|array{transferRelatedRecordsTo:mixed,assignedTo:}|string
Open
if (empty($entityvalues['entities']['Accounts']['create']) && empty($entityvalues['entities']['Contacts']['create'])) {
- Exclude checks
Argument 2 (entity)
is array{assigned_user_id:}
but \WebservicesConvertLead::vtwsPopulateConvertLeadEntities()
takes string
defined at /code/include/Webservices/ConvertLead.php:128
Open
$entityObjectValues = static::vtwsPopulateConvertLeadEntities($entityvalue, $entityObjectValues, $recordModel, $leadInfo);
- Exclude checks
Returning type array<string>|array<string>|array{Accounts:mixed}|array{}</string></string>
but vtwsConvertlead()
is declared to return int
Open
return $entityIds;
- Exclude checks
Call to method error
from undeclared class \App\Log
Open
\App\Log::error('Error converting a lead: ' . $e->getMessage());
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$db->createCommand()
- Exclude checks
Argument 1 (leadIdComponents)
is null
but \WebservicesConvertLead::vtwsConvertLeadTransferHandler()
takes int
defined at /code/include/Webservices/ConvertLead.php:209
Open
static::vtwsConvertLeadTransferHandler($leadIdComponents, $entityIds, $entityvalues);
- Exclude checks
Suspicious array access to \entity
Open
$entityObjectValues['parent_id'] = $entityIds['Accounts'];
- Exclude checks
Invalid offset "leadId"
of array type array{entities:mixed,assignedTo:,transferRelatedRecordsTo:'Accounts'|mixed}|string
Open
static::vtwsUpdateConvertLeadStatus($entityIds, $entityvalues['leadId'], $user);
- Exclude checks
When fetching an array index from a value of type string,
found an array index of type string,
but expected the index to be of type int
Open
$entity[$entityFieldName] = $leadinfo[$leadFieldName];
- Exclude checks
Argument 2 (key)
is int
but \App\Cache::delete()
takes string
defined at /code/app/Cache.php:105
Open
\App\Cache::delete('Leads.converted', $leadId);
- Exclude checks
Returning type null
but vtwsConvertlead()
is declared to return int
Open
return null;
- Exclude checks
Call to deprecated function \Vtiger_Field_Model::getFieldName()
defined at /code/modules/Vtiger/models/Field.php:203
Open
$entityFieldName = $entityField->getFieldName();
- Exclude checks
When fetching an array index from a value of type string,
found an array index of type 'transferRelatedRecordsTo',
but expected the index to be of type int
Open
$entityidComponents = $entityIds[$entityvalues['transferRelatedRecordsTo']];
- Exclude checks
Reference to undeclared property \Users_Record_Model->id
Open
$entityvalues['assignedTo'] = $user->id;
- Exclude checks
Invalid offset "leadId"
of array type array{assignedTo:}|array{transferRelatedRecordsTo:'Accounts'}|array{transferRelatedRecordsTo:mixed,assignedTo:}|string
Open
$leadIdComponents = $entityvalues['leadId'];
- Exclude checks
Argument 1 (leadId)
is null
but \WebservicesUtils::vtwsGetRelatedActivities()
takes int
defined at /code/include/Webservices/Utils.php:167
Open
\WebservicesUtils::vtwsGetRelatedActivities($leadIdComponents, $accountId, $contactId, $relatedId);
- Exclude checks
Returning type null
but vtwsConvertlead()
is declared to return int
Open
return null;
- Exclude checks
Return type of vtwsPopulateConvertLeadEntities()
is undeclared type \entity
Open
public static function vtwsPopulateConvertLeadEntities($entityvalue, $entity, Vtiger_Record_Model $recordModel, $leadinfo)
- Exclude checks
Call to deprecated function \Vtiger_Field_Model::getFieldName()
defined at /code/modules/Vtiger/models/Field.php:203
Open
$leadFieldName = $leadField->getFieldName();
- Exclude checks
Suspicious array access to int
Open
if ('' != $entityIds['Accounts'] || '' != $entityIds['Contacts']) {
- Exclude checks
Returning type string
but vtwsPopulateConvertLeadEntities()
is declared to return \entity
Open
return $entity;
- Exclude checks
Suspicious array access to int
Open
$entityidComponents = $entityIds[$entityvalues['transferRelatedRecordsTo']];
- Exclude checks
Suspicious array access to int
Open
->update($tablename, ['isconvertedfromlead' => 1], [$moduleModel->getEntityInstance()->tab_name_index[$tablename] => $entityIds[$module]])
- Exclude checks
When appending to a value of type string,
found an array access index of type string,
but expected the index to be of type int
Open
$entity[$entityFieldName] = $leadinfo[$leadFieldName];
- Exclude checks
Call to method trace
from undeclared class \App\Log
Open
\App\Log::trace('Start ' . __METHOD__);
- Exclude checks
Argument 4 (leadinfo)
is array
but \WebservicesConvertLead::vtwsPopulateConvertLeadEntities()
takes string
defined at /code/include/Webservices/ConvertLead.php:128
Open
$entityObjectValues = static::vtwsPopulateConvertLeadEntities($entityvalue, $entityObjectValues, $recordModel, $leadInfo);
- Exclude checks
Argument 1 (recordId)
is null
but \Vtiger_Record_Model::getInstanceById()
takes int
defined at /code/modules/Vtiger/models/Record.php:763
Open
$recordModel = Vtiger_Record_Model::getInstanceById($entityvalues['leadId']);
- Exclude checks
Call to method error
from undeclared class \App\Log
Open
\App\Log::error('Error converting a lead: ' . $translateAlreadyConvertedError);
- Exclude checks
Argument 1 (entityIds)
is array<string>|array<string>|array{Accounts:mixed}|array{}</string></string>
but \WebservicesConvertLead::vtwsUpdateConvertLeadStatus()
takes int
defined at /code/include/Webservices/ConvertLead.php:227
Open
static::vtwsUpdateConvertLeadStatus($entityIds, $entityvalues['leadId'], $user);
- Exclude checks
Argument 2 (leadId)
is null
but \WebservicesConvertLead::vtwsUpdateConvertLeadStatus()
takes int
defined at /code/include/Webservices/ConvertLead.php:227
Open
static::vtwsUpdateConvertLeadStatus($entityIds, $entityvalues['leadId'], $user);
- Exclude checks
Call to undeclared function \vtws_delete()
Open
vtws_delete($id, $user);
- Exclude checks
Avoid excessively long variable names like $translateAlreadyConvertedError. Keep variable name length under 20. Open
$translateAlreadyConvertedError = \App\Language::translate('LBL_LEAD_ALREADY_CONVERTED', 'Leads');
- 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 WebservicesConvertLead
- Exclude checks
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
Spaces must be used to indent lines; tabs are not allowed Open
* The function convert the lead.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return null;
- 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
} catch (Exception $e) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
try {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relatedId = $entityIds[$entityvalues['transferRelatedRecordsTo']];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return null;
- 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
$entityvalues['transferRelatedRecordsTo'] = 'Accounts';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$leadInfo = $recordModel->getData();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
try {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set($fieldName, $entityObjectValues[$fieldName]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entityIds[$entityName] = $recordModel->getId();
- 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
* Populate the entity fields with the lead info.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::trace('Start ' . __METHOD__);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entityvalue = $entityvalues['entities'][$entityName];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('Accounts' == $entityvalue['name'] && !empty($entityvalue['convert_to_id']) && \is_int($entityvalue['convert_to_id'])) {
- 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
foreach ($availableModules as $entityName) {
- 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
$recordModel->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$accountId = $entityIds['Accounts'];
- 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
* @return int
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ((new \App\Db\Query())->select(['converted'])->from('vtiger_leaddetails')->where(['converted' => 1, 'leadid' => $leadIdComponents])->exists()) {
- 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
$eventHandler->trigger('EntityBeforeConvertLead');
- 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
$create = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($create) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\WebservicesUtils::vtwsGetRelatedActivities($leadIdComponents, $accountId, $contactId, $relatedId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $leadinfo
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($entityvalues['assignedTo'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new WebServiceException('LEAD_ALREADY_CONVERTED', $translateAlreadyConvertedError);
- 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
vtws_delete($id, $user);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $entityvalue
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function vtwsPopulateConvertLeadEntities($entityvalue, $entity, Vtiger_Record_Model $recordModel, $leadinfo)
- 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
$entityObjectValues['assigned_user_id'] = $entityvalues['assignedTo'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('Contacts' == $entityvalue['name'] && !empty($entityIds['Accounts'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldModelList = $recordModel->getModule()->getFields();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$defaultValue = $fieldModel->getDefaultFieldValue();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('' !== $defaultValue) {
- 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
$targetModuleModel = Vtiger_Module_Model::getInstance($entityvalue['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
throw new WebServiceException('UNKNOWN_OPERATION', $e->getMessage() . ' : ' . $entityvalue['name']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::vtwsConvertLeadTransferHandler($leadIdComponents, $entityIds, $entityvalues);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$eventHandler->addParams('entityIds', $entityIds);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$eventHandler->trigger('EntityAfterConvertLead');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::error('Error converting a lead: ' . $e->getMessage());
- 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 Vtiger_Record_Model $recordModel
- 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
foreach ($fieldModelList as $fieldName => &$fieldModel) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::error('Error converting a lead: ' . $e->getMessage());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return entity array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$leadIdComponents = $entityvalues['leadId'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$availableModules = ['Accounts', 'Contacts'];
- Exclude checks
Line exceeds 120 characters; contains 127 characters Open
if (empty($entityvalues['entities']['Accounts']['create']) && empty($entityvalues['entities']['Contacts']['create'])) {
- Exclude checks
Line exceeds 120 characters; contains 138 characters Open
$entityObjectValues = static::vtwsPopulateConvertLeadEntities($entityvalue, $entityObjectValues, $recordModel, $leadInfo);
- 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
foreach ($entityIds as $id) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::trace('End ' . __METHOD__);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $entity
- 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 (empty($entityvalues['transferRelatedRecordsTo'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$eventHandler = new App\EventHandler();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entityObjectValues = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = Vtiger_Record_Model::getCleanInstance($entityvalue['name']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::vtwsUpdateConvertLeadStatus($entityIds, $entityvalues['leadId'], $user);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} catch (Exception $e) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $entityIds;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* If mandatory field is not provided populate with '????'.
- 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 $entityvalues
- 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
Line exceeds 120 characters; contains 144 characters Open
if ('Accounts' == $entityvalue['name'] && !empty($entityvalue['convert_to_id']) && \is_int($entityvalue['convert_to_id'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null === $leadField) {
- 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
try {
- Exclude checks
Line exceeds 120 characters; contains 145 characters Open
\WebservicesUtils::vtwsTransferLeadRelatedRecords($leadIdComponents, $entityidComponents, $entityvalues['transferRelatedRecordsTo']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Cache::delete('Leads.converted', $leadId);
- 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 ($defaultvalue && empty($entity[$fieldname])) {
- 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
$entity = static::vtwsValidateConvertLeadEntityMandatoryValues($entity, $targetModuleModel);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($mandatoryFields as $field => $fieldModel) {
- 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
}
- 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
->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$column = 'contactfid';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$column = 'leadfid';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($targetModuleModel->getFields() as $fieldname => $field) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$defaultvalue = $field->getDefaultFieldValue();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entity[$fieldname] = $defaultvalue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entity[$fieldname] = $fieldvalue;
- 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
* @return bool
- 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
$result = $db->createCommand()
- 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
$eventHandler->setParams(['entityValues' => $entityvalues, 'user' => $user, 'leadInfo' => $leadInfo]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($entityvalues['entities'][$entityName]['create'])) {
- 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
$recordModel = Vtiger_Record_Model::getInstanceById($entityvalues['leadId']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entityObjectValues = static::vtwsPopulateConvertLeadEntities($entityvalue, $entityObjectValues, $recordModel, $leadInfo);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$translateAlreadyConvertedError = \App\Language::translate('LBL_LEAD_ALREADY_CONVERTED', 'Leads');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entityObjectValues['parent_id'] = $entityIds['Accounts'];
- 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
switch ($entityName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$column = 'accountfid';
- 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
case 'Contacts':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = (new \App\Db\Query())->from('vtiger_convertleadmapping')->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} while ($row = $dataReader->read());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Validate convert lead entity mandatory values.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($dataReader->count()) {
- Exclude checks
Line exceeds 120 characters; contains 251 characters Open
if (('picklist' === $fieldModel->getFieldDataType() || 'multipicklist' === $fieldModel->getFieldDataType() || 'date' === $fieldModel->getFieldDataType() || 'datetime' === $fieldModel->getFieldDataType()) && $fieldModel->isEditable()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'Accounts':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new WebServiceException('FAILED_TO_MARK_LEAD_CONVERTED', 'Failed mark lead converted');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 158 characters Open
->update($tablename, ['isconvertedfromlead' => 1], [$moduleModel->getEntityInstance()->tab_name_index[$tablename] => $entityIds[$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
$entityField = \WebservicesUtils::vtwsGetFieldfromFieldId($row[$column], $targetModuleModel);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$leadField = \WebservicesUtils::vtwsGetFieldfromFieldId($row['leadfid'], $recordModel->getModule());
- 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('vtiger_leaddetails', ['converted' => 1], ['leadid' => $leadId])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
//update the modifiedtime and modified by information for the record
- Exclude checks
Line exceeds 120 characters; contains 155 characters Open
if ((new \App\Db\Query())->select(['converted'])->from('vtiger_leaddetails')->where(['converted' => 1, 'leadid' => $leadIdComponents])->exists()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$create = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset($entityObjectValues[$fieldName])) {
- Exclude checks
Line exceeds 120 characters; contains 126 characters Open
public static function vtwsPopulateConvertLeadEntities($entityvalue, $entity, Vtiger_Record_Model $recordModel, $leadinfo)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $entity
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $entity;
- 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
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$db->createCommand()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entityName = $entityvalue['name'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row = $dataReader->read();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
do {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Vtiger_Module_Model $targetModuleModel
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function vtwsValidateConvertLeadEntityMandatoryValues($entity, Vtiger_Module_Model $targetModuleModel)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (('picklist' === $fieldModel->getFieldDataType() || 'multipicklist' === $fieldModel->getFieldDataType() || 'date' === $fieldModel->getFieldDataType() || 'datetime' === $fieldModel->getFieldDataType()) && $fieldModel->isEditable()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entity[$field] = '????';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $leadId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Users_Record_Model $user
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function vtwsConvertlead($entityvalues, Users_Record_Model $user)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entityvalues['assignedTo'] = $user->id;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::error('Error converting a lead: ' . $translateAlreadyConvertedError);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entityIds = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($entityvalues['entities']['Accounts']['create']) && empty($entityvalues['entities']['Contacts']['create'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
//update the contacts relation
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entityIds[$entityName] = $entityvalue['convert_to_id'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set($fieldName, $defaultValue);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$contactId = $entityIds['Contacts'] ?? null;
- 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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$leadFieldName = $leadField->getFieldName();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entity[$entityFieldName] = $leadinfo[$leadFieldName];
- 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 (empty($entity[$field])) {
- 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
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function vtwsConvertLeadTransferHandler($leadIdComponents, $entityIds, $entityvalues)
- 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
$entityidComponents = $entityIds[$entityvalues['transferRelatedRecordsTo']];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* The function updates the status convert lead.
- 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
foreach ($moduleArray as $module) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->update($tablename, ['isconvertedfromlead' => 1], [$moduleModel->getEntityInstance()->tab_name_index[$tablename] => $entityIds[$module]])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\WebservicesUtils::vtwsTransferLeadRelatedRecords($leadIdComponents, $entityidComponents, $entityvalues['transferRelatedRecordsTo']);
- 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
} catch (Exception $e) {
- 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
$moduleArray = ['Accounts', 'Contacts'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleModel = Vtiger_Module_Model::getInstance($module);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$count = 1;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $entity;
- 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
$entity[$field] = $fieldModel->getDefaultFieldValue();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $entityvalues
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Users_Record_Model $user
- Exclude checks
Line exceeds 120 characters; contains 139 characters Open
->update('vtiger_crmentity', ['modifiedtime' => date('Y-m-d H:i:s'), 'modifiedby' => $user->getId()], ['crmid' => $leadId])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tablename = $moduleModel->getFieldByName('isconvertedfromlead')->getTableName();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null === $entityField) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($fieldvalue)) {
- 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
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->update('vtiger_crmentity', ['modifiedtime' => date('Y-m-d H:i:s'), 'modifiedby' => $user->getId()], ['crmid' => $leadId])
- 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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($entityvalue as $fieldname => $fieldvalue) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$mandatoryFields = $targetModuleModel->getMandatoryFieldModels();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function vtwsUpdateConvertLeadStatus($entityIds, $leadId, Users_Record_Model $user)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('' != $entityIds['Accounts'] || '' != $entityIds['Contacts']) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entityFieldName = $entityField->getFieldName();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
++$count;
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
default:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- 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 int $leadIdComponents
- 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
$db->createCommand()
- 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
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* function to handle the transferring of related records for lead.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return true;
- 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
$db = \App\Db::getInstance();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (false === $result) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($entityIds[$module])) {
- Exclude checks