YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
35 mins
Test Coverage
A
92%

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

    public function doTask($recordModel)
    {
        $dbCommand = \App\Db::getInstance()->createCommand();
        $moduleName = $recordModel->getModuleName();
        $entityId = $recordModel->getId();
Severity: Minor
Found in modules/com_vtiger_workflow/tasks/VTAddressBookTask.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\Privilege' in method 'doTask'.
Open

            if (\App\Privilege::isPermitted($moduleName, 'DetailView', $entityId, $userId)) {

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

        $moduleModel = Vtiger_Module_Model::getInstance($moduleName);

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

        $usersIds = \App\Fields\Owner::getUsersIds();

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

        $metainfo = \App\Module::getEntityInfo($moduleName);

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 getContents($recordModel)

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

Assigning true to property but \VTAddressBookTask->contents is \Vtiger_Record_Model
Open

        $this->contents = true;

Call to undeclared method \App\Db::createCommand
Open

        $dbCommand = \App\Db::getInstance()->createCommand();

Call to method getUsersIds from undeclared class \App\Fields\Owner
Open

        $usersIds = \App\Fields\Owner::getUsersIds();

Returning type \Vtiger_Record_Model but getContents() is declared to return bool
Open

        return $this->contents;

Declaration of function getContents(\Vtiger_Record_Model $recordModel) : bool should be compatible with function getContents(\Vtiger_Record_Model $recordModel) : \Vtiger_Record_Model defined in /code/modules/com_vtiger_workflow/VTTask.php:63
Open

    public function getContents($recordModel)

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

class VTAddressBookTask extends VTTask

A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 11 and the first side effect is on line 8.
Open

<?php

The 'getContents()' method which returns a boolean should be named 'is...()' or 'has...()'
Open

    public function getContents($recordModel)
    {
        $this->contents = true;

        return $this->contents;

BooleanGetMethodName

Since: 0.2

Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.

Example

class Foo {
    /**
     * @return boolean
     */
    public function getFoo() {} // bad
    /**
     * @return bool
     */
    public function isFoo(); // ok
    /**
     * @return boolean
     */
    public function getFoo($bar); // ok, unless checkParameterizedMethods=true
}

Source https://phpmd.org/rules/naming.html#booleangetmethodname

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

        return ['test'];

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

    public function doTask($recordModel)

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

        $entityId = $recordModel->getId();

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

        foreach ($usersIds as $userId) {

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

        $dbCommand->delete($table, ['id' => $entityId])->execute();

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 Vtiger_Record_Model $recordModel

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

            if (!empty($recordModel->get($fieldname))) {

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

     * Function to get contents of this task.

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

     * Execute task.

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

        $dbCommand = \App\Db::getInstance()->createCommand();

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

        $moduleName = $recordModel->getModuleName();

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 Vtiger_Record_Model $recordModel

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

    }

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

        $users = $name = '';

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

        $metainfo = \App\Module::getEntityInfo($moduleName);

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

        foreach ($metainfo['fieldnameArr'] as $entityName) {

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

    }

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

        $this->contents = true;

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

     *

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

        $usersIds = \App\Fields\Owner::getUsersIds();

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

     * @return bool

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

    public function getContents($recordModel)

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 ($fields as $field) {

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

        }

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

                $dbCommand->insert($table, ['id' => $entityId, 'email' => $recordModel->get($fieldname), 'name' => trim($name), 'users' => $users])->execute();

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

            $name .= ' ' . $recordModel->get($entityName);

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

        $table = OSSMail_AddressBook_Model::TABLE;

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

            if (\App\Privilege::isPermitted($moduleName, 'DetailView', $entityId, $userId)) {

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

     *

Line exceeds 120 characters; contains 159 characters
Open

                $dbCommand->insert($table, ['id' => $entityId, 'email' => $recordModel->get($fieldname), 'name' => trim($name), 'users' => $users])->execute();

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

            }

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

    public $executeImmediately = false;

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

     */

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

                $users .= ',' . $userId;

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

        $moduleModel = Vtiger_Module_Model::getInstance($moduleName);

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

            $fieldname = $field->getName();

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

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

    public function getFieldNames()

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

        }

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

        $fields = $moduleModel->getFieldsByType('email');

There are no issues that match your filters.

Category
Status