Function getFields
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getFields(bool $editable = false)
{
$fields = [];
$sourceModule = $this->relationModel->getParentModuleModel();
if ('Occurrences' !== $sourceModule->getName()) {
- 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
Missing class import via use statement (line '56', column '17'). Open
$field = new \Vtiger_Field_Model();
- 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 '126', column '15'). Open
return (new \App\Db\Query())->from(static::TABLE_NAME)->where([
- 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 getFields has a boolean flag argument $editable, which is a certain sign of a Single Responsibility Principle violation. Open
public function getFields(bool $editable = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Avoid using static access to class '\App\User' in method 'create'. Open
'rel_created_user' => \App\User::getCurrentUserRealId(),
- 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 "uitype" 3 times. Open
'uitype' => 16,
- 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" 5 times. Open
'crmid' => $sourceRecordId,
- 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 "label" 3 times. Open
'label' => 'LBL_STATUS_REL',
- 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 "relcrmid" 5 times. Open
'relcrmid' => $destinationRecordId,
- 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 getCurrentUserRealId
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
'rel_created_user' => \App\User::getCurrentUserRealId(),
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
return (new \App\Db\Query())->from(static::TABLE_NAME)->where([
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$result = (bool) \App\Db::getInstance()->createCommand()->update(static::TABLE_NAME, $updateData, $conditions)->execute();
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$result = \App\Db::getInstance()->createCommand()->insert(static::TABLE_NAME, [
- Exclude checks
Call to method setCustomColumn
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->setCustomColumn(["{$tableName}.{$fieldName}"]);
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Occurrences_GetRelatedMembers_Relation extends Vtiger_GetRelatedList_Relation
- Exclude checks
The class Occurrences_GetRelatedMembers_Relation is not named in CamelCase. Open
class Occurrences_GetRelatedMembers_Relation extends Vtiger_GetRelatedList_Relation
{
/** {@inheritdoc} */
public const TABLE_NAME = 'u_#__relations_members_entity';
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($this->customFields as $fieldName => $data) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tableName = static::TABLE_NAME;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (array_keys($this->customFields) as $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
])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($data as $key => $value) {
- 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
$queryGenerator = $this->relationModel->getQueryGenerator();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$sourceModule = $this->relationModel->getRelationModuleModel();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$editable || !$field->isEditableReadOnly()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'relcrmid' => $destinationRecordId,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $updateData
- 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 $result;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'or',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $destinationRecordId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'label' => 'LBL_RELATION_CREATED_USER',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- 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 = (bool) \App\Db::getInstance()->createCommand()->update(static::TABLE_NAME, $updateData, $conditions)->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
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $customFields = [
- 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
'comment_rel' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$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
$fields[$fieldName] = $field;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
parent::getQuery();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->setCustomColumn(["{$tableName}.{$fieldName}"]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'crmid' => $sourceRecordId,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$conditions = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = (bool) $this->getRelationData($sourceRecordId, $destinationRecordId);
- 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
public const TABLE_NAME = 'u_#__relations_members_entity';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'uitype' => 21,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Field list.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $editable
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function create(int $sourceRecordId, int $destinationRecordId): bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $destinationRecordId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $sourceRecordId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getRelationData(int $sourceRecordId, int $destinationRecordId)
- 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
$sourceModule = $this->relationModel->getParentModuleModel();
- 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
['crmid' => $destinationRecordId, 'relcrmid' => $sourceRecordId],
- 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
'displaytype' => 10
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getFields(bool $editable = false)
- Exclude checks
Line exceeds 120 characters; contains 161 characters Open
$field->set('name', $fieldName)->set('column', $fieldName)->set('table', static::TABLE_NAME)->set('fromOutsideList', true)->setModule($sourceModule);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getQuery()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function updateRelationData(int $sourceRecordId, int $destinationRecordId, array $updateData): bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$field->set($key, $value);
- 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 ($result) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get relation data.
- 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
$field = new \Vtiger_Field_Model();
- 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 (!$this->getRelationData($sourceRecordId, $destinationRecordId)) {
- 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 bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'maximumlength' => 65535
- 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
'status_rel' => [
- 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
'uitype' => 52,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* updateRelationData function.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $sourceRecordId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['crmid' => $sourceRecordId, 'relcrmid' => $destinationRecordId],
- 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 (new \App\Db\Query())->from(static::TABLE_NAME)->where([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'or',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['crmid' => $sourceRecordId, 'relcrmid' => $destinationRecordId],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Field custom list.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'label' => 'LBL_STATUS_REL',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'rel_created_user' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- 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 $result;
- 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
'uitype' => 16,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'label' => 'LBL_COMMENT_REL',
- 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
['crmid' => $destinationRecordId, 'relcrmid' => $sourceRecordId],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
])->one();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $fields;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = \App\Db::getInstance()->createCommand()->insert(static::TABLE_NAME, [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Line exceeds 120 characters; contains 134 characters Open
$result = (bool) \App\Db::getInstance()->createCommand()->update(static::TABLE_NAME, $updateData, $conditions)->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
if ('Occurrences' !== $sourceModule->getName()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$field->set('name', $fieldName)->set('column', $fieldName)->set('table', static::TABLE_NAME)->set('fromOutsideList', true)->setModule($sourceModule);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'rel_created_user' => \App\User::getCurrentUserRealId(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Class name "Occurrences_GetRelatedMembers_Relation" is not in camel caps format Open
class Occurrences_GetRelatedMembers_Relation extends Vtiger_GetRelatedList_Relation
- Exclude checks