YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/MailRbl/actions/DeleteAjax.php

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

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

    public function process(App\Request $request)
    {
        $db = \App\Db::getInstance('admin');
        $dbCommand = $db->createCommand();
        if (\in_array($request->getMode(), ['forVerification', 'toSend', 'request'])) {
Severity: Minor
Found in modules/Settings/MailRbl/actions/DeleteAjax.php - About 1 hr to fix

    Missing class import via use statement (line '46', 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 '27', column '16').
    Open

                $row = (new \App\Db\Query())->from('s_#__mail_rbl_list')->where(['request' => $request->getInteger('record')])->one($db);

    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 '36', column '16').
    Open

                $row = (new \App\Db\Query())->from('s_#__mail_rbl_list')->where(['id' => $request->getInteger('record')])->one($db);

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

                    \App\Cache::delete('MailRblIpColor', $row['ip']);

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

            $db = \App\Db::getInstance('admin');

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

                    \App\Cache::delete('MailRblList', $row['ip']);

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

                \App\Cache::delete('MailRblIpColor', $row['ip']);

    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

    The method process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $row = (new \App\Db\Query())->from('s_#__mail_rbl_list')->where(['id' => $request->getInteger('record')])->one($db);
                $status = $dbCommand->delete('s_#__mail_rbl_list', [
                    'id' => $request->getInteger('record')
                ])->execute();

    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

    Avoid using static access to class '\App\Cache' in method 'process'.
    Open

                \App\Cache::delete('MailRblList', $row['ip']);

    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

    Define a constant instead of duplicating this literal "record" 5 times.
    Open

                    'id' => $request->getInteger('record')

    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.

    Define a constant instead of duplicating this literal "request" 4 times.
    Open

            if (\in_array($request->getMode(), ['forVerification', 'toSend', 'request'])) {

    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.

    Define a constant instead of duplicating this literal "s_#__mail_rbl_list" 4 times.
    Open

                $row = (new \App\Db\Query())->from('s_#__mail_rbl_list')->where(['request' => $request->getInteger('record')])->one($db);

    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.

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

            $dbCommand = $db->createCommand();

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

                $row = (new \App\Db\Query())->from('s_#__mail_rbl_list')->where(['request' => $request->getInteger('record')])->one($db);

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

                $row = (new \App\Db\Query())->from('s_#__mail_rbl_list')->where(['id' => $request->getInteger('record')])->one($db);

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

    class Settings_MailRbl_DeleteAjax_Action extends Settings_Vtiger_Delete_Action

    The class Settings_MailRbl_DeleteAjax_Action is not named in CamelCase.
    Open

    class Settings_MailRbl_DeleteAjax_Action extends Settings_Vtiger_Delete_Action
    {
        /** {@inheritdoc} */
        public function process(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

    Avoid variables with short names like $db. Configured minimum length is 3.
    Open

            $db = \App\Db::getInstance('admin');

    ShortVariable

    Since: 0.2

    Detects when a field, local, or parameter has a very short name.

    Example

    class Something {
        private $q = 15; // VIOLATION - Field
        public static function main( array $as ) { // VIOLATION - Formal
            $r = 20 + $this->q; // VIOLATION - Local
            for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                $r += $this->q;
            }
        }
    }

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

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

            $dbCommand = $db->createCommand();

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

            if (\in_array($request->getMode(), ['forVerification', 'toSend', 'request'])) {

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

                    ])->execute();

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

                    \App\Cache::delete('MailRblIpColor', $row['ip']);

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

                $row = (new \App\Db\Query())->from('s_#__mail_rbl_list')->where(['request' => $request->getInteger('record')])->one($db);

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

                    'id' => $request->getInteger('record')

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

            $response = new Vtiger_Response();

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

        /** {@inheritdoc} */

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

                $status = $dbCommand->delete('s_#__mail_rbl_list', [

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

            }

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

                ])->execute();

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

                $row = (new \App\Db\Query())->from('s_#__mail_rbl_list')->where(['id' => $request->getInteger('record')])->one($db);

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

     * @license        YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com)

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

                if ($row) {

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

                    $dbCommand->delete('s_#__mail_rbl_list', [

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

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

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

            $response->emit();

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

        {

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

                \App\Cache::delete('MailRblList', $row['ip']);

    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

            } else {

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

                $dbCommand->update('s_#__mail_rbl_request', [

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

            $response->setResult($status);

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

                ])->execute();

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

                ], ['id' => $row['request']])->execute();

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

                \App\Cache::delete('MailRblIpColor', $row['ip']);

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

        public function process(App\Request $request)

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

            $db = \App\Db::getInstance('admin');

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

                $status = $dbCommand->delete('s_#__mail_rbl_request', [

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

                    \App\Cache::delete('MailRblList', $row['ip']);

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

                    'status' => 3,

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

                    'id' => $request->getInteger('record')

    Line exceeds 120 characters; contains 133 characters
    Open

                $row = (new \App\Db\Query())->from('s_#__mail_rbl_list')->where(['request' => $request->getInteger('record')])->one($db);

    Line exceeds 120 characters; contains 128 characters
    Open

                $row = (new \App\Db\Query())->from('s_#__mail_rbl_list')->where(['id' => $request->getInteger('record')])->one($db);

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

    class Settings_MailRbl_DeleteAjax_Action extends Settings_Vtiger_Delete_Action

    There are no issues that match your filters.

    Category
    Status