YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/actions/MergeRecords.php

Summary

Maintainability
A
2 hrs
Test Coverage
F
0%

Method process has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process(App\Request $request)
    {
        $moduleModel = Vtiger_Module_Model::getInstance($request->getModule());
        $primaryRecord = $request->getInteger('record');
        $migrate = [];
Severity: Minor
Found in modules/Vtiger/actions/MergeRecords.php - About 1 hr to fix

    Function process has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        public function process(App\Request $request)
        {
            $moduleModel = Vtiger_Module_Model::getInstance($request->getModule());
            $primaryRecord = $request->getInteger('record');
            $migrate = [];
    Severity: Minor
    Found in modules/Vtiger/actions/MergeRecords.php - About 55 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 '53', column '19').
    Open

            $response = new Vtiger_Response();

    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

    Missing class import via use statement (line '21', column '14').
    Open

                throw new \App\Exceptions\NoPermitted('ERR_NOT_ACCESSIBLE', 406);

    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\RecordTransfer' in method 'process'.
    Open

                \App\RecordTransfer::transfer($primaryRecord, $migrate);

    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\Privilege' in method 'checkPermission'.
    Open

            if (!\App\Privilege::isPermitted($request->getModule(), 'Merge')) {

    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 'process'.
    Open

            $moduleModel = Vtiger_Module_Model::getInstance($request->getModule());

    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\Log' in method 'process'.
    Open

                \App\Log::error($ex->__toString());

    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_Record_Model' in method 'process'.
    Open

                    $recordModel = \Vtiger_Record_Model::getInstanceById($recordId);

    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 method error from undeclared class \App\Log
    Open

                \App\Log::error($ex->__toString());
    Severity: Critical
    Found in modules/Vtiger/actions/MergeRecords.php by phan

    Argument 1 (state) is 'Trash' but \Vtiger_Record_Model::changeState() takes \type defined at /code/modules/Vtiger/models/Record.php:1784
    Open

                    $recordModel->changeState('Trash');

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

    class Vtiger_MergeRecords_Action extends Vtiger_Mass_Action

    The class Vtiger_MergeRecords_Action is not named in CamelCase.
    Open

    class Vtiger_MergeRecords_Action extends Vtiger_Mass_Action
    {
        /** {@inheritdoc} */
        public function checkPermission(App\Request $request)
        {

    CamelCaseClassName

    Since: 0.2

    It is considered best practice to use the CamelCase notation to name classes.

    Example

    class class_name {
    }

    Source

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

        public function checkPermission(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

                    $recordModel->ext['modificationType'] = ModTracker_Record_Model::TRANSFER_DELETE;

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

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

                if ($request->has($field->getName()) && $request->getInteger($field->getName()) !== $primaryRecord && $field->isEditable()) {

    Line exceeds 120 characters; contains 137 characters
    Open

                if ($request->has($field->getName()) && $request->getInteger($field->getName()) !== $primaryRecord && $field->isEditable()) {

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

                \App\Log::error($ex->__toString());

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

            $response = new Vtiger_Response();

    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

                }

    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 (!\App\Privilege::isPermitted($request->getModule(), 'Merge')) {

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

                foreach (array_keys($migrate) as $recordId) {

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

            $primaryRecord = $request->getInteger('record');

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

                    $recordModel->changeState('Trash');

    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 ($record !== $primaryRecord) {

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

        {

    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

            $response->setResult($result);

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

                throw new \App\Exceptions\NoPermitted('ERR_NOT_ACCESSIBLE', 406);

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

            $moduleModel = Vtiger_Module_Model::getInstance($request->getModule());

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

            } catch (\Throwable $ex) {

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

            $response->emit();

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

            foreach ($request->getArray('records', 'Integer') as $record) {

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

                    $migrate[$record] = [];

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

            try {

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

            }

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

                    $recordModel = \Vtiger_Record_Model::getInstanceById($recordId);

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

                $result = 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

                \App\RecordTransfer::transfer($primaryRecord, $migrate);

    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 function process(App\Request $request)

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

            $migrate = [];

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

            $result = 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

                    $migrate[$request->getInteger($field->getName())][$field->getName()] = $field->getName();

    Class name "Vtiger_MergeRecords_Action" is not in camel caps format
    Open

    class Vtiger_MergeRecords_Action extends Vtiger_Mass_Action

    There are no issues that match your filters.

    Category
    Status