Method getLinks
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getLinks(): array
{
$relatedLink = parent::getLinks();
if (!$this->getParentRecordModel()->isReadOnly()) {
$relationModelInstance = $this->getRelationModel();
Consider simplifying this complex logical expression. Open
if ($contactModel->getName() === $relatedModuleModel->getName() && $contactModel->isActive()
&& $contactModel->isPermitted('CreateView') && $contactModel->isPermitted('Import')
&& $relationModelInstance->isAddActionSupported()
&& $this->getParentRecordModel()->isViewable()
&& $relationModelInstance->getParentModuleModel()->getName() === $this->getParentRecordModel()->getModuleName()
Function getLinks
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getLinks(): array
{
$relatedLink = parent::getLinks();
if (!$this->getParentRecordModel()->isReadOnly()) {
$relationModelInstance = $this->getRelationModel();
- 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 getLinks() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. Open
public function getLinks(): array
{
$relatedLink = parent::getLinks();
if (!$this->getParentRecordModel()->isReadOnly()) {
$relationModelInstance = $this->getRelationModel();
- 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
Avoid using static access to class 'Vtiger_Link_Model' in method 'getLinks'. Open
$relatedLink['RELATEDLIST_MASSACTIONS'][] = Vtiger_Link_Model::getInstanceFromValues([
'linktype' => 'LISTVIEWMASSACTION',
'linklabel' => 'LBL_IMPORT',
'linkurl' => $contactModel->getImportUrl() . '&relationId=' . $relationModelInstance->getId() . '&src_record=' . $this->getParentRecordModel()->getId(),
'linkicon' => 'fas fa-download',
- 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_Link_Model' in method 'getLinks'. Open
$relatedLink['RELATEDLIST_MASSACTIONS'][] = Vtiger_Link_Model::getInstanceFromValues([
'linktype' => 'LISTVIEWMASSACTION',
'linklabel' => 'LBL_MASS_SEND_EMAIL',
'linkurl' => 'javascript:Vtiger_RelatedList_Js.triggerSendEmail();',
'linkicon' => 'fas fa-envelope',
- 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 'getLinks'. Open
$contactModel = Vtiger_Module_Model::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\Config' in method 'getLinks'. Open
if ('Contacts' === $relatedModuleModel->getName() && $relatedModuleModel->isPermitted('MassComposeEmail') && App\Config::main('isActiveSendingMails') && App\Mail::getDefaultSmtp()) {
- 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\Mail' in method 'getLinks'. Open
if ('Contacts' === $relatedModuleModel->getName() && $relatedModuleModel->isPermitted('MassComposeEmail') && App\Config::main('isActiveSendingMails') && App\Mail::getDefaultSmtp()) {
- 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 excessively long variable names like $relationModelInstance. Keep variable name length under 20. Open
$relationModelInstance = $this->getRelationModel();
- 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 Occurrences_RelationListView_Model extends Vtiger_RelationListView_Model
- Exclude checks
The class Occurrences_RelationListView_Model is not named in CamelCase. Open
class Occurrences_RelationListView_Model extends Vtiger_RelationListView_Model
{
/** {@inheritdoc} */
public function getLinks(): array
{
- 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
$relationModelInstance = $this->getRelationModel();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'linktype' => 'LISTVIEWMASSACTION',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $relatedLink;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
&& $relationModelInstance->isAddActionSupported()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('Contacts' === $relatedModuleModel->getName() && $relatedModuleModel->isPermitted('MassComposeEmail') && App\Config::main('isActiveSendingMails') && App\Mail::getDefaultSmtp()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
&& $relationModelInstance->getParentModuleModel()->getName() === $this->getParentRecordModel()->getModuleName()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'linkurl' => $contactModel->getImportUrl() . '&relationId=' . $relationModelInstance->getId() . '&src_record=' . $this->getParentRecordModel()->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
]);
- 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
'linklabel' => 'LBL_MASS_SEND_EMAIL',
- 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
$contactModel = Vtiger_Module_Model::getInstance('Contacts');
- 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
'linkurl' => 'javascript:Vtiger_RelatedList_Js.triggerSendEmail();',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
&& $contactModel->isPermitted('CreateView') && $contactModel->isPermitted('Import')
- Exclude checks
Line exceeds 120 characters; contains 127 characters Open
&& $relationModelInstance->getParentModuleModel()->getName() === $this->getParentRecordModel()->getModuleName()
- 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->getParentRecordModel()->isReadOnly()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
&& $this->getParentRecordModel()->isViewable()
- Exclude checks
Line exceeds 120 characters; contains 172 characters Open
'linkurl' => $contactModel->getImportUrl() . '&relationId=' . $relationModelInstance->getId() . '&src_record=' . $this->getParentRecordModel()->getId(),
- Exclude checks
Line exceeds 120 characters; contains 194 characters Open
if ('Contacts' === $relatedModuleModel->getName() && $relatedModuleModel->isPermitted('MassComposeEmail') && App\Config::main('isActiveSendingMails') && App\Mail::getDefaultSmtp()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($contactModel->getName() === $relatedModuleModel->getName() && $contactModel->isActive()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relatedLink['RELATEDLIST_MASSACTIONS'][] = Vtiger_Link_Model::getInstanceFromValues([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'linktype' => 'LISTVIEWMASSACTION',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'linklabel' => 'LBL_IMPORT',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getLinks(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relatedLink['RELATEDLIST_MASSACTIONS'][] = Vtiger_Link_Model::getInstanceFromValues([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'linkicon' => 'fas fa-download',
- 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
$relatedLink = parent::getLinks();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'linkicon' => 'fas fa-envelope',
- 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
$relatedModuleModel = $relationModelInstance->getRelationModuleModel();
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
) {
- Exclude checks
Class name "Occurrences_RelationListView_Model" is not in camel caps format Open
class Occurrences_RelationListView_Model extends Vtiger_RelationListView_Model
- Exclude checks