Method process
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process(OSSMail_Mail_Model $mail)
{
$type = $mail->getTypeEmail();
$exceptionsAll = OSSMailScanner_Record_Model::getConfig('exceptions');
if (!empty($exceptionsAll['crating_mails'])) {
Function process
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function process(OSSMail_Mail_Model $mail)
{
$type = $mail->getTypeEmail();
$exceptionsAll = OSSMailScanner_Record_Model::getConfig('exceptions');
if (!empty($exceptionsAll['crating_mails'])) {
- 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 process() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public function process(OSSMail_Mail_Model $mail)
{
$type = $mail->getTypeEmail();
$exceptionsAll = OSSMailScanner_Record_Model::getConfig('exceptions');
if (!empty($exceptionsAll['crating_mails'])) {
- 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
Reduce the number of returns of this function 4, down to the maximum allowed 3. Open
public function process(OSSMail_Mail_Model $mail)
- Read upRead up
- Exclude checks
Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.
Noncompliant Code Example
With the default threshold of 3:
function myFunction(){ // Noncompliant as there are 4 return statements if (condition1) { return true; } else { if (condition2) { return false; } else { return true; } } return false; }
Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed. Open
public function process(OSSMail_Mail_Model $mail)
- 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
Avoid using static access to class 'OSSMailScanner_Record_Model' in method 'process'. Open
$exceptionsAll = OSSMailScanner_Record_Model::getConfig('exceptions');
- 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 process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
App\Db::getInstance()->createCommand()->update('vtiger_ossmailview', [
'id' => $mail->get('id'),
], ['ossmailviewid' => $mail->getMailCrmId()]
)->execute();
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid assigning values to variables in if clauses and the like (line '62', column '8'). Open
public function process(OSSMail_Mail_Model $mail)
{
$type = $mail->getTypeEmail();
$exceptionsAll = OSSMailScanner_Record_Model::getConfig('exceptions');
if (!empty($exceptionsAll['crating_mails'])) {
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid using static access to class '\App\TextUtils' in method 'process'. Open
$record->set('content', \App\TextUtils::htmlTruncate($mail->getContent(), $record->getField('content')->getMaxValue()));
- 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\TextUtils' in method 'process'. Open
$record->set('orginal_mail', \App\TextUtils::htmlTruncate($mail->get('clean'), $record->getField('orginal_mail')->getMaxValue()));
- 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 'OSSMailView_Record_Model' in method 'process'. Open
$record = OSSMailView_Record_Model::getCleanInstance('OSSMailView');
- 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 "subject" 3 times. Open
$record->setFromUserValue('subject', $mail->isEmpty('subject') ? '-' : $mail->get('subject'));
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "from_email" 4 times. Open
$mailForExceptions = (0 === $type) ? $mail->get('to_email') : $mail->get('from_email');
- 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 "to_email" 4 times. Open
$mailForExceptions = (0 === $type) ? $mail->get('to_email') : $mail->get('from_email');
- 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 "cc_email" 3 times. Open
$toIds = array_merge($mail->findEmailAddress('to_email'), $mail->findEmailAddress('cc_email'), $mail->findEmailAddress('bcc_email'));
- 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 "bcc_email" 3 times. Open
$toIds = array_merge($mail->findEmailAddress('to_email'), $mail->findEmailAddress('cc_email'), $mail->findEmailAddress('bcc_email'));
- 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 getConfig
from undeclared class \OSSMailScanner_Record_Model
Open
$exceptionsAll = OSSMailScanner_Record_Model::getConfig('exceptions');
- Exclude checks
Returning type array{mailViewId:bool|int}
but process()
is declared to return int
Open
return ['mailViewId' => $mail->getMailCrmId()];
- Exclude checks
Returning type false
but process()
is declared to return int
Open
return false;
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
App\Db::getInstance()->createCommand()->update('vtiger_ossmailview', [
- Exclude checks
Returning type array{mailViewId:int,attachments:array<int>|array<int>|mixed}</int></int>
but process()
is declared to return int
Open
return ['mailViewId' => $id, 'attachments' => $mail->saveAttachments()];
- Exclude checks
Returning type false
but process()
is declared to return int
Open
return false;
- Exclude checks
Avoid excessively long class names like OSSMailScanner_CreatedEmail_ScannerAction. Keep class name length under 40. Open
class OSSMailScanner_CreatedEmail_ScannerAction
{
/**
* Process.
*
- Read upRead up
- Exclude checks
LongClassName
Since: 2.9
Detects when classes or interfaces are declared with excessively long names.
Example
class ATooLongClassNameThatHintsAtADesignProblem {
}
interface ATooLongInterfaceNameThatHintsAtADesignProblem {
}
Source https://phpmd.org/rules/naming.html#longclassname
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class OSSMailScanner_CreatedEmail_ScannerAction
- Exclude checks
Avoid variables with short names like $id. Configured minimum length is 3. Open
if ($id = $record->getId()) {
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The class OSSMailScanner_CreatedEmail_ScannerAction is not named in CamelCase. Open
class OSSMailScanner_CreatedEmail_ScannerAction
{
/**
* Process.
*
- 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
if (false === $mail->getMailCrmId()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('assigned_user_id', $mail->getAccountOwner());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('to_email', $mail->get('to_email'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$type = $mail->getTypeEmail();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('cc_email', $mail->get('cc_email'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record = OSSMailView_Record_Model::getCleanInstance('OSSMailView');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($exceptions as $exception) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->setFromUserValue('subject', $mail->isEmpty('subject') ? '-' : $mail->get('subject'));
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (false !== strpos($mailForExceptions, $exception)) {
- 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
$exceptionsAll = OSSMailScanner_Record_Model::getConfig('exceptions');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($exceptionsAll['crating_mails'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$exceptions = explode(',', $exceptionsAll['crating_mails']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$mailForExceptions = (0 === $type) ? $mail->get('to_email') : $mail->get('from_email');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('reply_to_email', $mail->get('reply_toaddress'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Process.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param OSSMail_Mail_Model $mail
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function process(OSSMail_Mail_Model $mail)
- Exclude checks
Line exceeds 120 characters; contains 145 characters Open
$toIds = array_merge($mail->findEmailAddress('to_email'), $mail->findEmailAddress('cc_email'), $mail->findEmailAddress('bcc_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
*
- 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
$fromIds = array_merge($mail->findEmailAddress('from_email'), $mail->findEmailAddress('reply_toaddress'));
- 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
$record->set('bcc_email', $mail->get('bcc_email'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('orginal_mail', \App\TextUtils::htmlTruncate($mail->get('clean'), $record->getField('orginal_mail')->getMaxValue()));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'cid' => $mail->getUniqueId(),
- 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 ['mailViewId' => $mail->getMailCrmId()];
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
App\Db::getInstance()->createCommand()->update('vtiger_ossmailview', [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$account = $mail->getAccount();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('from_email', $mail->get('from_email'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->setHandlerExceptions(['disableHandlers' => true]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->setHandlerExceptions([]);
- 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
return false;
- Exclude checks
Line exceeds 120 characters; contains 132 characters Open
$record->set('content', \App\TextUtils::htmlTruncate($mail->getContent(), $record->getField('content')->getMaxValue()));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('attachments_exist', 1);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$mail->setMailCrmId($id);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$toIds = array_merge($mail->findEmailAddress('to_email'), $mail->findEmailAddress('cc_email'), $mail->findEmailAddress('bcc_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
$record->set('ossmailview_sendtype', $mail->getTypeEmail(true));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($mail->get('isAttachments') || $mail->get('attachments')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
], ['ossmailviewid' => $mail->getMailCrmId()]
- Exclude checks
Line exceeds 120 characters; contains 142 characters Open
$record->set('orginal_mail', \App\TextUtils::htmlTruncate($mail->get('clean'), $record->getField('orginal_mail')->getMaxValue()));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('created_user_id', $mail->getAccountOwner())->set('createdtime', $mail->get('date'));
- 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
$record->set('mbox', $mail->getFolder())->set('type', $type)->set('mid', $mail->get('id'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('content', \App\TextUtils::htmlTruncate($mail->getContent(), $record->getField('content')->getMaxValue()));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($id = $record->getId()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('uid', $mail->get('message_id'))->set('rc_user', $account['user_id']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
)->execute();
- Exclude checks
Line exceeds 120 characters; contains 124 characters Open
$record->set('from_id', implode(',', array_unique($fromIds)))->set('to_id', implode(',', array_unique($toIds)));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return ['mailViewId' => $id, 'attachments' => $mail->saveAttachments()];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('from_id', implode(',', array_unique($fromIds)))->set('to_id', implode(',', array_unique($toIds)));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('date', $mail->get('date'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->setDataForSave(['vtiger_ossmailview' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'id' => $mail->get('id'),
- Exclude checks
Class name "OSSMailScanner_CreatedEmail_ScannerAction" is not in camel caps format Open
class OSSMailScanner_CreatedEmail_ScannerAction
- Exclude checks
Expected 0 spaces before closing bracket; newline found Open
App\Db::getInstance()->createCommand()->update('vtiger_ossmailview', [
- Exclude checks