YetiForceCompany/YetiForceCRM

View on GitHub
app/Mail/ScannerAction/CreatedMail.php

Summary

Maintainability
A
2 hrs
Test Coverage
F
0%

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;
Severity: Minor
Found in app/Mail/ScannerAction/CreatedMail.php - About 1 hr to fix

    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;
    Severity: Minor
    Found in app/Mail/ScannerAction/CreatedMail.php - About 35 mins to fix

    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())))));

    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;

    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()));

    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())))));

    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');

    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())))));

    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));

    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()));

    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())))));

    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'));

    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));

    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')));

    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')) {

    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')) {

    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()) {

    Avoid variables with short names like $id. Configured minimum length is 3.
    Open

            if ($id = $record->getId()) {

    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));

    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())))));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $record->set('to_email', implode(',', $scanner->get('to_email')));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if ($scanner->has('cc_email')) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if ($scanner->has('bcc_email')) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $toEmails = array_merge($toEmails, $scanner->get('bcc_email'));

    Spaces must be used to indent lines; tabs are not allowed
    Open

                return;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $record->set('ossmailview_sendtype', \App\Mail\ScannerEngine\Base::MAIL_TYPES[$type]);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if ($this->checkExceptions('CreatedMail') || false !== $scanner->getMailCrmId()) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $record->set('assigned_user_id', $scanner->getUserId());

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'cid' => $scanner->getCid(),

    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())))));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $scanner = $this->scannerEngine;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            ]]);

    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())))));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $record->set('created_user_id', $scanner->getUserId());

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $record->set('createdtime', $scanner->get('date'));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $record->set('uid', $scanner->get('message_id'));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $toEmails = $scanner->get('to_email') ?? [];

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $record = \OSSMailView_Record_Model::getCleanInstance('OSSMailView');

    Line exceeds 120 characters; contains 153 characters
    Open

            $record->setFromUserValue('subject', \App\TextUtils::textTruncate($scanner->get('subject'), $record->getField('subject')->getMaxValue(), false));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Line exceeds 120 characters; contains 143 characters
    Open

            $record->set('orginal_mail', \App\TextUtils::htmlTruncate($scanner->get('headers'), $record->getField('orginal_mail')->getMaxValue()));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if ($scanner->has('cc_email')) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $toEmails = array_merge($toEmails, $scanner->get('cc_email'));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $record->set('from_email', $scanner->get('from_email'));

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $record->set('bcc_email', implode(',', $scanner->get('bcc_email')));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $record->set('date', $scanner->get('date'));

    Line exceeds 120 characters; contains 130 characters
    Open

            $record->set('content', \App\TextUtils::htmlTruncate($scanner->get('body'), $record->getField('content')->getMaxValue()));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $record->setDataForSave(['vtiger_ossmailview' => [

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $type = $scanner->getMailType();

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $record->set('type', $type);

    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()));

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function process(): void

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $record->set('cc_email', implode(',', $scanner->get('cc_email')));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $record->setHandlerExceptions(['disableHandlers' => true]);

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public static $priority = 2;

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if ($scanner->has('bcc_email')) {

    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()));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $record->setHandlerExceptions([]);

    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())))));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if ($id = $record->getId()) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $scanner->processData['CreatedMail'] = $id;

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $record->save();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $scanner->set('mailCrmId', $id);

    There are no issues that match your filters.

    Category
    Status