YetiForceCompany/YetiForceCRM

View on GitHub
app/Mail/ScannerEngine/Base.php

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

The method findRelatedRecords has a boolean flag argument $onlyId, which is a certain sign of a Single Responsibility Principle violation.
Open

    abstract public function findRelatedRecords(bool $onlyId = false): array;
Severity: Minor
Found in app/Mail/ScannerEngine/Base.php by phpmd

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

Missing class import via use statement (line '149', column '17').
Open

        $query = (new \App\Db\Query())->select(['vtiger_crmentity.crmid', 'vtiger_crmentity.setype'])
Severity: Minor
Found in app/Mail/ScannerEngine/Base.php by phpmd

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Avoid using static access to class '\App\Record' in method 'getRelatedRecords'.
Open

                'label' => \App\Record::getLabel($row['crmid']),
Severity: Minor
Found in app/Mail/ScannerEngine/Base.php by phpmd

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

Call to undeclared method \App\Db\Query::select
Open

        $query = (new \App\Db\Query())->select(['vtiger_crmentity.crmid', 'vtiger_crmentity.setype'])
Severity: Critical
Found in app/Mail/ScannerEngine/Base.php by phan

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    public function getCid(): string
    {
        if ($this->has('cid')) {
            return $this->get('cid');
        }
Severity: Major
Found in app/Mail/ScannerEngine/Base.php and 1 other location - About 1 hr to fix
modules/OSSMail/models/Mail.php on lines 193..201

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 104.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

        2 => 'Internal',

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

     * Get emails fields to search.

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

    /**

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

     * @return int[]

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

    const MAIL_TYPES = [

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

     * @var string[]

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

    abstract public function getEmailsFields(?string $searchModuleName = null): array;

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

     */

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

     * Find related records by subject.

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

    protected $emailsFieldsCache = [];

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

     * Number fields cache.

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

     * @return array

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

     * Find related records by emails.

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

     */

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

     * @return int[]

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

     * Process data.

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

    public $processData = [];

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

     * Emails fields cache.

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

     * @var string[]

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

            $class = "App\\Mail\\ScannerAction\\{$action}";

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

     * Get scanner actions.

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

     *

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

    abstract public function getMailCrmId();

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

     *

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

    const MAIL_TYPE_SENT = 0;

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

        foreach ($this->getActions() as $action) {

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

     * @return int

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

     *

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

    const MAIL_TYPE_RECEIVED = 1;

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

     * @param bool $onlyId

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

    abstract public function findRelatedRecordsBySubject(): array;

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

     */

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

    protected $numberFieldsCache = [];

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

     */

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

     */

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

     * @return void

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

    {

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

            (new $class($this))->process();

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

     *

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

        1 => 'Received',

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

     * @return array

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

        0 => 'Sent',

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

    ];

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

     *

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

     * Initialize with request data.

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

    abstract public function findRelatedRecordsByEmail(): array;

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

    abstract public function initFromRequest(\App\Request $request);

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

    /**

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

     * 1 = Received

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

     * @return array

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

     */

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

     */

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

            $relations[] = [

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

        return $relations;

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

                'module' => $row['setype'],

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

    /**

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

        $dataReader->close();

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

    }

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

    const MAIL_TYPE_INTERNAL = 2;

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

    /**

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

     * @return array

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

     * Find related records.

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

            ->from('vtiger_ossmailview_relation')

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

    }

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

            return $this->get('cid');

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

    /**

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

     * Get mail crm id.

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

     * Get user id.

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

    abstract public function findRelatedRecords(bool $onlyId = false): array;

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

     */

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

        $query = (new \App\Db\Query())->select(['vtiger_crmentity.crmid', 'vtiger_crmentity.setype'])

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

     * Mail types map.

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

     * @var array

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

     * Main function to execute scanner engine actions.

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

     * @return int[]

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

    /**

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

     * 0 = Sent

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

     * 2 = Internal.

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

    abstract public function getActions(): array;

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

    abstract public function getUserId(): int;

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

     * @param string|null $searchModuleName

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

                'id' => $row['crmid'],

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

     * Get exceptions.

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

    /**

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

     * @return int

Line exceeds 120 characters; contains 125 characters
Open

            ->where(['vtiger_ossmailview_relation.ossmailviewid' => $this->getMailCrmId(), 'vtiger_crmentity.deleted' => 0]);

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

    public function getCid(): string

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

        $this->set('cid', $cid);

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

    public function getRelatedRecords(): array

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

        while ($row = $dataReader->read()) {

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

     * @return array

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

    {

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

            ->innerJoin('vtiger_crmentity', 'vtiger_ossmailview_relation.crmid = vtiger_crmentity.crmid')

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

        }

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

        $cid = hash('sha256', $this->get('from_email') . '|' . $this->get('date') . '|' . $this->get('subject') . '|' . $this->get('message_id'));

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

            ->where(['vtiger_ossmailview_relation.ossmailviewid' => $this->getMailCrmId(), 'vtiger_crmentity.deleted' => 0]);

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

        }

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

        if ($this->has('cid')) {

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

     *

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

     * @return void

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

     * Get related records.

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

        $relations = [];

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

    abstract public function getExceptions(): array;

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

     * @param \App\Request $request

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

     *

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

     * Get mail type.

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

        $dataReader = $query->createCommand()->query();

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

     *

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

        return $cid;

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

    abstract public function getMailType(): int;

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

     * Generation crm unique id.

Line exceeds 120 characters; contains 146 characters
Open

        $cid = hash('sha256', $this->get('from_email') . '|' . $this->get('date') . '|' . $this->get('subject') . '|' . $this->get('message_id'));

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

                'label' => \App\Record::getLabel($row['crmid']),

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

     * @return string

There are no issues that match your filters.

Category
Status