YetiForceCompany/YetiForceCRM

View on GitHub
app/EmailParser.php

Summary

Maintainability
A
1 hr
Test Coverage
D
67%

Function getContent has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    public function getContent($trim = false)
    {
        if (!$trim) {
            return $this->content;
        }
Severity: Minor
Found in app/EmailParser.php - About 1 hr 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

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();
Severity: Minor
Found in app/EmailParser.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

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)
Severity: Minor
Found in app/EmailParser.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

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;
            }
Severity: Minor
Found in app/EmailParser.php by phpmd

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',
Severity: Critical
Found in app/EmailParser.php by sonar-php

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)
Severity: Minor
Found in app/EmailParser.php by phpmd

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;
Severity: Minor
Found in app/EmailParser.php by phan

Reference to undeclared property \App\EmailParser->content (Did you mean $content)
Open

        foreach (explode(',', $this->content) as $content) {
Severity: Minor
Found in app/EmailParser.php by phan

Reference to undeclared property \App\EmailParser->recordModel
Open

            return ($permissionFieldModel && $permissionFieldModel->isActiveField() && $this->recordModel->has($checkFieldName)) ? (bool) $this->recordModel->get($checkFieldName) : true;
Severity: Minor
Found in app/EmailParser.php by phan

Reference to undeclared property \App\EmailParser->recordModel
Open

            $permissionFieldModel = $this->recordModel->getModule()->getField($checkFieldName);
Severity: Minor
Found in app/EmailParser.php by phan

Class extends undeclared class \App\TextParser (Did you mean class \Tests\App\TextParser)
Open

class EmailParser extends TextParser
Severity: Critical
Found in app/EmailParser.php by phan

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

    {
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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;
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

    {
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

            }
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

    private static $permissionToSend = [
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

     * @param \Vtiger_Field_Model $fieldModel
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

                continue;
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        'Accounts' => 'emailoptout',
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

     * @param string              $moduleName
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

            $checkFieldName = self::$permissionToSend[$moduleName];
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        return true;
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

    public function getContent($trim = false)
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

                [$fromName, $fromEmail] = explode('<', $content);
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

                $fromEmail = rtrim($fromEmail, '>');
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

     * @return bool
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

            return $this->content;
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        $emails = [];
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

                $emails[$fromEmail] = $fromName;
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        return $emails;
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

            } else {
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

Line exceeds 120 characters; contains 186 characters
Open

            return ($permissionFieldModel && $permissionFieldModel->isActiveField() && $this->recordModel->has($checkFieldName)) ? (bool) $this->recordModel->get($checkFieldName) : true;
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

     * Get content parsed for emails.
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        foreach (explode(',', $this->content) as $content) {
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

            }
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

            if (empty($content) || '-' === $content) {
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        'Users' => 'emailoptout',
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

     * @return array|string
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        if (!$trim) {
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

            $content = trim($content);
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

                $emails[] = $content;
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

    {
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        'Leads' => 'noapprovalemails',
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

    protected function useValue($fieldModel, $moduleName)
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        if ($this->emailoptout && isset(self::$permissionToSend[$moduleName])) {
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

            $permissionFieldModel = $this->recordModel->getModule()->getField($checkFieldName);
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

    /** {@inheritdoc} */
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        'Contacts' => 'emailoptout',
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

    public $emailoptout = true;
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

     * Check if this content can be used.
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

    ];
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

            if (strpos($content, '<') && strpos($content, '>')) {
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

     * @param bool $trim
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

Line exceeds 120 characters; contains 157 characters
Open

    protected function relatedRecordsListPrinter(\Vtiger_RelationListView_Model $relationListView, \Vtiger_Paging_Model $pagingModel, int $maxLength): string
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        return rtrim($rows, ',');
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

                if ($fieldModel && 'email' === $fieldModel->getFieldDataType() && $this->useValue($fieldModel, $relatedModuleName)) {
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

                }
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

                    $rows .= $relatedRecordModel->get($fieldName) . ',';
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

            }
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        $fields = $relationListView->getHeaders();
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        $rows = '';
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

            foreach ($fields as $fieldName => $fieldModel) {
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        $relatedModuleName = $relationListView->getRelationModel()->getRelationModuleName();
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

Line exceeds 120 characters; contains 133 characters
Open

                if ($fieldModel && 'email' === $fieldModel->getFieldDataType() && $this->useValue($fieldModel, $relatedModuleName)) {
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

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

        foreach ($relationListView->getEntries($pagingModel) as $relatedRecordModel) {
Severity: Minor
Found in app/EmailParser.php by phpcodesniffer

There are no issues that match your filters.

Category
Status