Method process
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process(): void
{
$scanner = $this->scannerEngine;
if ($this->checkExceptions('CreatedMail') || false !== $scanner->getMailCrmId()) {
return;
Function process
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function process(): void
{
$scanner = $this->scannerEngine;
if ($this->checkExceptions('CreatedMail') || false !== $scanner->getMailCrmId()) {
return;
- 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
Avoid using static access to class '\App\Mail\RecordFinder' in method 'process'. Open
$record->set('from_id', implode(',', array_unique(\App\Utils::flatten(\App\Mail\RecordFinder::findByEmail([$scanner->get('from_email')], $scanner->getEmailsFields())))));
- 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 assigning values to variables in if clauses and the like (line '64', column '7'). Open
public function process(): void
{
$scanner = $this->scannerEngine;
if ($this->checkExceptions('CreatedMail') || false !== $scanner->getMailCrmId()) {
return;
- 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($scanner->get('body'), $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\Mail\RecordFinder' in method 'process'. Open
$record->set('to_id', implode(',', array_unique(\App\Utils::flatten(\App\Mail\RecordFinder::findByEmail($toEmails, $scanner->getEmailsFields())))));
- 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
Avoid using static access to class '\App\Utils' in method 'process'. Open
$record->set('from_id', implode(',', array_unique(\App\Utils::flatten(\App\Mail\RecordFinder::findByEmail([$scanner->get('from_email')], $scanner->getEmailsFields())))));
- 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->setFromUserValue('subject', \App\TextUtils::textTruncate($scanner->get('subject'), $record->getField('subject')->getMaxValue(), false));
- 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($scanner->get('headers'), $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 '\App\Utils' in method 'process'. Open
$record->set('to_id', implode(',', array_unique(\App\Utils::flatten(\App\Mail\RecordFinder::findByEmail($toEmails, $scanner->getEmailsFields())))));
- 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 "from_email" 3 times. Open
$record->set('from_email', $scanner->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 "subject" 3 times. Open
$record->setFromUserValue('subject', \App\TextUtils::textTruncate($scanner->get('subject'), $record->getField('subject')->getMaxValue(), false));
- 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" 3 times. Open
$record->set('to_email', implode(',', $scanner->get('to_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" 5 times. Open
if ($scanner->has('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 "cc_email" 5 times. Open
if ($scanner->has('cc_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.
false
to array comparison Open
if ($this->checkExceptions('CreatedMail') || false !== $scanner->getMailCrmId()) {
- 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
Spaces must be used to indent lines; tabs are not allowed Open
$record->setFromUserValue('subject', \App\TextUtils::textTruncate($scanner->get('subject'), $record->getField('subject')->getMaxValue(), false));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('from_id', implode(',', array_unique(\App\Utils::flatten(\App\Mail\RecordFinder::findByEmail([$scanner->get('from_email')], $scanner->getEmailsFields())))));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('to_email', implode(',', $scanner->get('to_email')));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($scanner->has('cc_email')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($scanner->has('bcc_email')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$toEmails = array_merge($toEmails, $scanner->get('bcc_email'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('ossmailview_sendtype', \App\Mail\ScannerEngine\Base::MAIL_TYPES[$type]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($this->checkExceptions('CreatedMail') || false !== $scanner->getMailCrmId()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('assigned_user_id', $scanner->getUserId());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'cid' => $scanner->getCid(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('to_id', implode(',', array_unique(\App\Utils::flatten(\App\Mail\RecordFinder::findByEmail($toEmails, $scanner->getEmailsFields())))));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$scanner = $this->scannerEngine;
- 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 178 characters Open
$record->set('from_id', implode(',', array_unique(\App\Utils::flatten(\App\Mail\RecordFinder::findByEmail([$scanner->get('from_email')], $scanner->getEmailsFields())))));
- 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('created_user_id', $scanner->getUserId());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('createdtime', $scanner->get('date'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('uid', $scanner->get('message_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
$toEmails = $scanner->get('to_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 = \OSSMailView_Record_Model::getCleanInstance('OSSMailView');
- Exclude checks
Line exceeds 120 characters; contains 153 characters Open
$record->setFromUserValue('subject', \App\TextUtils::textTruncate($scanner->get('subject'), $record->getField('subject')->getMaxValue(), false));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 143 characters Open
$record->set('orginal_mail', \App\TextUtils::htmlTruncate($scanner->get('headers'), $record->getField('orginal_mail')->getMaxValue()));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($scanner->has('cc_email')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$toEmails = array_merge($toEmails, $scanner->get('cc_email'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('from_email', $scanner->get('from_email'));
- 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
$record->set('bcc_email', implode(',', $scanner->get('bcc_email')));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('date', $scanner->get('date'));
- Exclude checks
Line exceeds 120 characters; contains 130 characters Open
$record->set('content', \App\TextUtils::htmlTruncate($scanner->get('body'), $record->getField('content')->getMaxValue()));
- 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
$type = $scanner->getMailType();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('type', $type);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('orginal_mail', \App\TextUtils::htmlTruncate($scanner->get('headers'), $record->getField('orginal_mail')->getMaxValue()));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function process(): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('cc_email', implode(',', $scanner->get('cc_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
public static $priority = 2;
- 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
if ($scanner->has('bcc_email')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('content', \App\TextUtils::htmlTruncate($scanner->get('body'), $record->getField('content')->getMaxValue()));
- 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->setHandlerExceptions([]);
- Exclude checks
Line exceeds 120 characters; contains 156 characters Open
$record->set('to_id', implode(',', array_unique(\App\Utils::flatten(\App\Mail\RecordFinder::findByEmail($toEmails, $scanner->getEmailsFields())))));
- 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
$scanner->processData['CreatedMail'] = $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
$record->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$scanner->set('mailCrmId', $id);
- Exclude checks