YetiForceCompany/YetiForceCRM

View on GitHub
modules/com_vtiger_workflow/tasks/VTEmailReport.php

Summary

Maintainability
A
25 mins
Test Coverage
F
0%

Function doTask has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function doTask($recordModel = null)
    {
        $users = [];
        foreach ($this->members as $member) {
            $users = array_merge($users, \App\PrivilegeUtil::getUserByMember($member));
Severity: Minor
Found in modules/com_vtiger_workflow/tasks/VTEmailReport.php - About 25 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

Missing class import via use statement (line '46', column '10').
Open

                (new \App\BatchMethod(['method' => '\App\Mailer::sendFromTemplate', 'params' => ['params' => [

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 assigning values to variables in if clauses and the like (line '45', column '63').
Open

    public function doTask($recordModel = null)
    {
        $users = [];
        foreach ($this->members as $member) {
            $users = array_merge($users, \App\PrivilegeUtil::getUserByMember($member));

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 '\Vtiger_Record_Model' in method 'doTask'.
Open

            $userRecordModel = \Vtiger_Record_Model::getInstanceById($user, 'Users');

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\PrivilegeUtil' in method 'doTask'.
Open

            $users = array_merge($users, \App\PrivilegeUtil::getUserByMember($member));

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 unused parameters such as '$recordModel'.
Open

    public function doTask($recordModel = null)

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 \VTEmailReport->emailoptout
Open

            $checkApproval = (bool) ($this->emailoptout ?? null);

Reference to undeclared property \VTEmailReport->members (Did you mean $member)
Open

        foreach ($this->members as $member) {

Reference to undeclared property \VTEmailReport->template
Open

                    'template' => $this->template,

Each class must be in a namespace of at least one level (a top-level vendor name)
Open

class VTEmailReport extends VTTask

Spaces must be used for alignment; tabs are not allowed
Open

        foreach ($this->members as $member) {

Spaces must be used for alignment; tabs are not allowed
Open

    /**

Spaces must be used for alignment; tabs are not allowed
Open

    public function getFieldNames()

Spaces must be used for alignment; tabs are not allowed
Open

        }

Spaces must be used for alignment; tabs are not allowed
Open

        foreach (array_unique($users) as $user) {

Spaces must be used for alignment; tabs are not allowed
Open

     * Get field names.

Spaces must be used for alignment; tabs are not allowed
Open

    {

Spaces must be used for alignment; tabs are not allowed
Open

                (new \App\BatchMethod(['method' => '\App\Mailer::sendFromTemplate', 'params' => ['params' => [

Spaces must be used for alignment; tabs are not allowed
Open

        }

Spaces must be used for alignment; tabs are not allowed
Open

    public $recordEventState = self::RECORD_EVENT_INACTIVE;

Spaces must be used for alignment; tabs are not allowed
Open

    /**

Spaces must be used for alignment; tabs are not allowed
Open

                ]]]))->save();

Spaces must be used for alignment; tabs are not allowed
Open

     *

Spaces must be used for alignment; tabs are not allowed
Open

    }

Spaces must be used for alignment; tabs are not allowed
Open

    public function doTask($recordModel = null)

Spaces must be used for alignment; tabs are not allowed
Open

 * @package     App

Spaces must be used for alignment; tabs are not allowed
Open

     * @param Vtiger_Record_Model $recordModel

Spaces must be used for alignment; tabs are not allowed
Open

                    'textParserParams' => [

Spaces must be used for alignment; tabs are not allowed
Open

                        'userId' => $user

Spaces must be used for alignment; tabs are not allowed
Open

    /** {@inheritdoc} */

Spaces must be used for alignment; tabs are not allowed
Open

     */

Spaces must be used for alignment; tabs are not allowed
Open

    {

Spaces must be used for alignment; tabs are not allowed
Open

            if ('Active' === $userRecordModel->get('status') && !empty($userEmail = $userRecordModel->get('email1')) && (!$checkApproval || $userRecordModel->get('emailoptout'))) {

Spaces must be used for alignment; tabs are not allowed
Open

            $checkApproval = (bool) ($this->emailoptout ?? null);

Spaces must be used for alignment; tabs are not allowed
Open

    }

Spaces must be used for alignment; tabs are not allowed
Open

     */

Spaces must be used for alignment; tabs are not allowed
Open

     * Execute task.

Spaces must be used for alignment; tabs are not allowed
Open

     *

Spaces must be used for alignment; tabs are not allowed
Open

        $users = [];

Spaces must be used for alignment; tabs are not allowed
Open

            $userRecordModel = \Vtiger_Record_Model::getInstanceById($user, 'Users');

Spaces must be used for alignment; tabs are not allowed
Open

                    'to' => $userEmail,

Spaces must be used for alignment; tabs are not allowed
Open

            }

Spaces must be used for alignment; tabs are not allowed
Open

            $users = array_merge($users, \App\PrivilegeUtil::getUserByMember($member));

Spaces must be used for alignment; tabs are not allowed
Open

     * @return string[]

Spaces must be used for alignment; tabs are not allowed
Open

        return ['template', 'members', 'emailoptout'];

Spaces must be used for alignment; tabs are not allowed
Open

                    'template' => $this->template,

Spaces must be used for alignment; tabs are not allowed
Open

                    ]

Line exceeds 120 characters; contains 180 characters
Open

            if ('Active' === $userRecordModel->get('status') && !empty($userEmail = $userRecordModel->get('email1')) && (!$checkApproval || $userRecordModel->get('emailoptout'))) {

There are no issues that match your filters.

Category
Status