Function getContent
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function getContent($trim = false)
{
if (!$trim) {
return $this->content;
}
- 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 relatedRecordsListPrinter
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function relatedRecordsListPrinter(\Vtiger_RelationListView_Model $relationListView, \Vtiger_Paging_Model $pagingModel, int $maxLength): string
{
$relatedModuleName = $relationListView->getRelationModel()->getRelationModuleName();
$rows = '';
$fields = $relationListView->getHeaders();
- 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 getContent has a boolean flag argument $trim, which is a certain sign of a Single Responsibility Principle violation. Open
public function getContent($trim = 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
The method getContent uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$emails[] = $content;
}
- 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 "emailoptout" 3 times. Open
'Accounts' => 'emailoptout',
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Avoid unused parameters such as '$fieldModel'. Open
protected function useValue($fieldModel, $moduleName)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Reference to undeclared property \App\EmailParser->content
Open
return $this->content;
- Exclude checks
Reference to undeclared property \App\EmailParser->content
(Did you mean $content) Open
foreach (explode(',', $this->content) as $content) {
- Exclude checks
Reference to undeclared property \App\EmailParser->recordModel
Open
return ($permissionFieldModel && $permissionFieldModel->isActiveField() && $this->recordModel->has($checkFieldName)) ? (bool) $this->recordModel->get($checkFieldName) : true;
- Exclude checks
Reference to undeclared property \App\EmailParser->recordModel
Open
$permissionFieldModel = $this->recordModel->getModule()->getField($checkFieldName);
- Exclude checks
Class extends undeclared class \App\TextParser
(Did you mean class \Tests\App\TextParser) Open
class EmailParser extends TextParser
- 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 ($permissionFieldModel && $permissionFieldModel->isActiveField() && $this->recordModel->has($checkFieldName)) ? (bool) $this->recordModel->get($checkFieldName) : 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
{
- 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
private static $permissionToSend = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \Vtiger_Field_Model $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
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Accounts' => 'emailoptout',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $moduleName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$checkFieldName = self::$permissionToSend[$moduleName];
- 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
public function getContent($trim = false)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
[$fromName, $fromEmail] = explode('<', $content);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fromEmail = rtrim($fromEmail, '>');
- 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
return $this->content;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$emails = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$emails[$fromEmail] = $fromName;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $emails;
- 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
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Line exceeds 120 characters; contains 186 characters Open
return ($permissionFieldModel && $permissionFieldModel->isActiveField() && $this->recordModel->has($checkFieldName)) ? (bool) $this->recordModel->get($checkFieldName) : true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get content parsed for emails.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (explode(',', $this->content) as $content) {
- 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($content) || '-' === $content) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Users' => 'emailoptout',
- 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 array|string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$trim) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$content = trim($content);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$emails[] = $content;
- 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
'Leads' => 'noapprovalemails',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected function useValue($fieldModel, $moduleName)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($this->emailoptout && isset(self::$permissionToSend[$moduleName])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$permissionFieldModel = $this->recordModel->getModule()->getField($checkFieldName);
- 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
protected function relatedRecordsListPrinter(\Vtiger_RelationListView_Model $relationListView, \Vtiger_Paging_Model $pagingModel, int $maxLength): 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
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Contacts' => 'emailoptout',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $emailoptout = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Check if this content can be used.
- 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 (strpos($content, '<') && strpos($content, '>')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $trim
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 157 characters Open
protected function relatedRecordsListPrinter(\Vtiger_RelationListView_Model $relationListView, \Vtiger_Paging_Model $pagingModel, int $maxLength): 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
return rtrim($rows, ',');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($fieldModel && 'email' === $fieldModel->getFieldDataType() && $this->useValue($fieldModel, $relatedModuleName)) {
- 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
$rows .= $relatedRecordModel->get($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
$fields = $relationListView->getHeaders();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$rows = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($fields as $fieldName => $fieldModel) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relatedModuleName = $relationListView->getRelationModel()->getRelationModuleName();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 133 characters Open
if ($fieldModel && 'email' === $fieldModel->getFieldDataType() && $this->useValue($fieldModel, $relatedModuleName)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($relationListView->getEntries($pagingModel) as $relatedRecordModel) {
- Exclude checks