YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/BruteForce/models/Module.php

Summary

Maintainability
A
1 hr
Test Coverage
F
39%

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

    public function updateBlockedIp()
    {
        \App\Log::trace('Start ' . __METHOD__);
        $db = \App\Db::getInstance('admin');
        $time = $this->get('timelock');
Severity: Minor
Found in modules/Settings/BruteForce/models/Module.php - About 1 hr to fix

    Missing class import via use statement (line '52', column '15').
    Open

            $row = (new App\Db\Query())->from('a_#__bruteforce')->one();

    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 '119', column '27').
    Open

            $this->blockedId = (new \App\Db\Query())

    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 '69', column '17').
    Open

            $query = (new \App\Db\Query())

    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 '88', column '17').
    Open

            $query = (new \App\Db\Query())

    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 '156', column '18').
    Open

            $bfData = (new \App\Db\Query())

    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 '116', column '20').
    Open

            $blockDate = new DateTime();

    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 '152', column '15').
    Open

            $date = new DateTime();

    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 '273', column '15').
    Open

            return (new \App\Db\Query())->from('a_#__bruteforce_users')->createCommand()->queryColumn();

    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 '89', column '33').
    Open

                ->select(['usersName' => new \yii\db\Expression('DISTINCT user_name'), 'browser' => new \yii\db\Expression('browser')])

    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 '89', column '92').
    Open

                ->select(['usersName' => new \yii\db\Expression('DISTINCT user_name'), 'browser' => new \yii\db\Expression('browser')])

    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 '138', column '24').
    Open

                        'attempts' => new \yii\db\Expression('attempts + 1'),

    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 '66', column '20').
    Open

            $blockDate = new DateTime();

    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 '299', column '20').
    Open

                    'time' => (new DateTime())->modify("-{$configBruteForce['timelock']} minutes")->format('Y-m-d H:i:s'),

    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

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

            } else {
                $attempts = ++$bfData['attempts'];
                $blocked = $attempts >= $this->get('attempsnumber') ? self::BLOCKED : self::UNBLOCKED;
                $db->createCommand()
                    ->update('a_#__bruteforce_blocked', [

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

            App\Cache::save('BruteForce', 'Settings', $row, App\Cache::LONG);

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

                    $recordModel = Vtiger_Record_Model::getInstanceById($id, '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\Db' in method 'updateConfig'.
    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 'getBruteForceSettings'.
    Open

            if (App\Cache::has('BruteForce', 'Settings')) {

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

            \App\Log::trace('Start ' . __METHOD__);

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

                return App\Cache::get('BruteForce', 'Settings');

    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\Mailer' in method 'sendNotificationEmail'.
    Open

                \App\Mailer::sendFromTemplate([
                    'template' => 'BruteForceSecurityRiskHasBeenDetected',
                    'moduleName' => 'Users',
                    'to' => $emails,
                    'ip' => \App\RequestUtil::getRemoteIP(true),

    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\RequestUtil' in method 'isBlockedIp'.
    Open

            $ip = \App\RequestUtil::getRemoteIP(true);

    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\User' in method 'unBlock'.
    Open

                    'userid' => \App\User::getCurrentUserRealId(),

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

            \App\Log::trace('End ' . __METHOD__);

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

            \App\Log::trace('End ' . __METHOD__);

    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 'clearBlockedByIp'.
    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\RequestUtil' in method 'sendNotificationEmail'.
    Open

                    'ip' => \App\RequestUtil::getRemoteIP(true),

    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\RequestUtil' in method 'updateBlockedIp'.
    Open

            $ip = \App\RequestUtil::getRemoteIP(true);

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

                    \App\Log::trace('End ' . __METHOD__ . ' - No brute force users found to send email');

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

            \App\Log::trace('Start ' . __METHOD__);

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

            App\Cache::delete('BruteForce', 'Settings');

    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 "selectedUsers" 4 times.
    Open

            if (!empty($data['selectedUsers'])) {

    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 "attempts" 7 times.
    Open

                ->select(['id', 'attempts', 'ip', 'time'])

    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 "a_#__bruteforce_blocked" 8 times.
    Open

                ->from('a_#__bruteforce_blocked')

    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 "a_#__bruteforce_users" 3 times.
    Open

            $db->createCommand()->delete('a_#__bruteforce_users')->execute();

    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 "active" 3 times.
    Open

            return (bool) $this->get('active');

    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 "Settings" 4 times.
    Open

            if (App\Cache::has('BruteForce', 'Settings')) {

    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 "Y-m-d H:i:s" 5 times.
    Open

                ->andWhere(['>=', 'time', $blockDate->format('Y-m-d H:i:s')])

    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 "blocked" 7 times.
    Open

                ->andWhere(['blocked' => self::BLOCKED])

    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 "attempsnumber" 4 times.
    Open

                ->andWhere(['>=', 'attempts', $this->get('attempsnumber')]);

    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 "timelock" 6 times.
    Open

            $time = $this->get('timelock');

    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 "admin" 6 times.
    Open

                \App\Db::getInstance('admin')->createCommand()

    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 "BruteForce" 4 times.
    Open

            if (App\Cache::has('BruteForce', 'Settings')) {

    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\Query::select
    Open

            $bfData = (new \App\Db\Query())

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

            return \App\Fields\Owner::getInstance()->getUsers(false, 'Active', false, false, true);

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

            $db->createCommand()->delete('a_#__bruteforce_users')->execute();

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

            $this->blockedId = (new \App\Db\Query())

    Call to method __construct from undeclared class \yii\db\Expression
    Open

                        'attempts' => new \yii\db\Expression('attempts + 1'),

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

            $db->createCommand()->delete('a_#__bruteforce_blocked', [

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

                \App\Db::getInstance('admin')->createCommand()

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

                $db->createCommand()

    Call to method trace from undeclared class \App\Log
    Open

            \App\Log::trace('End ' . __METHOD__);

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

            $db->createCommand()->insert('a_#__bruteforce_blocked', [

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

            return (new \App\Db\Query())->from('a_#__bruteforce_users')->createCommand()->queryColumn();

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

            $row = (new App\Db\Query())->from('a_#__bruteforce')->one();

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

            return \App\Db::getInstance('admin')->createCommand()

    Call to method trace from undeclared class \App\Log
    Open

                    \App\Log::trace('End ' . __METHOD__ . ' - No brute force users found to send email');

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

            $db->createCommand()

    Call to method trace from undeclared class \App\Log
    Open

            \App\Log::trace('Start ' . __METHOD__);

    Call to method __construct from undeclared class \yii\db\Expression
    Open

                ->select(['usersName' => new \yii\db\Expression('DISTINCT user_name'), 'browser' => new \yii\db\Expression('browser')])

    Call to method trace from undeclared class \App\Log
    Open

            \App\Log::trace('End ' . __METHOD__);

    Call to method trace from undeclared class \App\Log
    Open

            \App\Log::trace('Start ' . __METHOD__);

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

            $query = (new \App\Db\Query())

    Returning type string but setBlockedIp() is declared to return int
    Open

            return $this->blockedId = $db->getLastInsertID('a_#__bruteforce_blocked_id_seq');

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

                    $db->createCommand()->insert('a_#__bruteforce_users', ['id' => $userId])->execute();

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

            $query = (new \App\Db\Query())

    Call to method getCurrentUserRealId from undeclared class \App\User (Did you mean class \Tests\App\User)
    Open

                    'userid' => \App\User::getCurrentUserRealId(),

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

    class Settings_BruteForce_Module_Model extends Settings_Vtiger_Module_Model

    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

    The class Settings_BruteForce_Module_Model is not named in CamelCase.
    Open

    class Settings_BruteForce_Module_Model extends Settings_Vtiger_Module_Model
    {
        const UNBLOCKED = 0;
        const BLOCKED = 1;
        const UNBLOCKED_BY_USER = 2;

    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

    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

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

            $ip = \App\RequestUtil::getRemoteIP(true);

    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

    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

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

        private function clearBlockedByIp($ip, $data)

    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

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

        private function setBlockedIp($ip)

    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

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

            $ip = \App\RequestUtil::getRemoteIP(true);

    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

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

        public static function unBlock($id)

    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 to indent lines; tabs are not allowed
    Open

        const UNBLOCKED = 0;

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

        public function getBlockedIp()

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

                ->andWhere(['>=', 'attempts', $this->get('attempsnumber')]);

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

            $query = (new \App\Db\Query())

    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 Settings_BruteForce_Module_Model

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

         * Functions gets data from login history.

    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

         * @return array

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

         */

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

            $query = (new \App\Db\Query())

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

         * Function verifies if module is active.

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

                ->from('a_#__bruteforce_blocked')

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

        private $blockedId;

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

         * @return array

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

            $blockDate->modify("-$time minutes");

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

         * @param array $data

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

        public function getLoginHistoryData($data)

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

        {

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

                ->select(['usersName' => new \yii\db\Expression('DISTINCT user_name'), 'browser' => new \yii\db\Expression('browser')])

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

        private $isBlocked;

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

        /**

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

            $instance = new self();

    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 array

    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

         */

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

        /**

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

                ->andWhere(['>=', 'time', $blockDate->format('Y-m-d H:i:s')])

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

            return $instance;

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

        public function isActive()

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

            return (bool) $this->get('active');

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

            App\Cache::save('BruteForce', 'Settings', $row, App\Cache::LONG);

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

         * Function gets unsuccessful login attempts data of blocked users.

    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

        }

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

         */

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

        const UNBLOCKED_BY_USER = 2;

    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

         * Function returns module configuration.

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

        {

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

            $blockDate = new DateTime();

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

         *

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

        const BLOCKED = 1;

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

        public static function getCleanInstance()

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

            $instance->setData(self::getBruteForceSettings());

    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

            return $row;

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

                ->select(['id', 'attempts', 'ip', 'time'])

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

                ->andWhere(['blocked' => self::BLOCKED])

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

        /**

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

         * Function includes class instances.

    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 static function getBruteForceSettings()

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

            if (App\Cache::has('BruteForce', 'Settings')) {

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

                return App\Cache::get('BruteForce', 'Settings');

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

            $row = (new App\Db\Query())->from('a_#__bruteforce')->one();

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

            return $query->createCommand()->queryAll();

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

        {

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

            $time = $this->get('timelock');

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

            $users = array_keys($historyData);

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

            $data['browsers'] = implode(', ', array_unique($browsers));

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

         * Function verifies if user is blocked.

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

                ->andWhere(['ip' => $ip])

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

        }

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

                    ->update('a_#__bruteforce_blocked', [

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

            \App\Log::trace('Start ' . __METHOD__);

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

                ->select(['id', 'attempts'])

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

                $blocked = $attempts >= $this->get('attempsnumber') ? self::BLOCKED : self::UNBLOCKED;

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

            \App\Log::trace('End ' . __METHOD__);

    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 \App\Db::getInstance('admin')->createCommand()

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

                    'blocked' => self::UNBLOCKED_BY_USER,

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

         * @param array $data - Configuration data

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

            $ip = \App\RequestUtil::getRemoteIP(true);

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

                ->scalar();

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

            $checkData = $date->modify("-$time minutes")->format('Y-m-d H:i:s');

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

        {

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

            $db->createCommand()->insert('a_#__bruteforce_blocked', [

    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

         * @return array - List of users

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

         * Function updates module configuration.

    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 $data;

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

                ->andWhere(['blocked' => self::UNBLOCKED])

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

            } else {

    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

                ], ['id' => $id])

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

         *

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

                $browsers = array_merge($browsers, $browsersUserName);

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

         * Function increases the number of unsuccessful login attempts.

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

            if (!$bfData) {

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

        /**

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

                'time' => date('Y-m-d H:i:s'),

    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 bool

    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

                ->andWhere(['blocked' => self::BLOCKED])

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

         *

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

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

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

            $browsers = [];

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

            $blockDate = new DateTime();

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

                    ], ['id' => $this->blockedId])

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

                $attempts = ++$bfData['attempts'];

    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 string $data - Cut-off date of users block condition

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

                'and', ['<', 'time', $data],

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

        public static function updateConfig($data)

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

                ->where(['>', 'time', $blockDate->format('Y-m-d H:i:s')])

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

                        'attempts' => new \yii\db\Expression('attempts + 1'),

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

                'attempts' => 1,

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

         * Function removes redundant entries from database.

    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 static function unBlock($id)

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

        {

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

                ->from('vtiger_loginhistory')

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

                ->where(['status' => ['Failed login', 'Blocked IP', 'ForgotPasswordNoUserFound'], 'user_ip' => $data['ip']])

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

            $this->blockedId = (new \App\Db\Query())

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

                ->select(['id'])

    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

                \App\Db::getInstance('admin')->createCommand()

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

        {

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

            $date = new DateTime();

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

                    ->execute();

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

                'blocked' => self::UNBLOCKED,

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

                ['ip' => $ip], ])->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

            $db->createCommand()

    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 isBlockedIp()

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

            $bfData = (new \App\Db\Query())

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

                ->from('a_#__bruteforce_blocked')

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

                $this->setBlockedIp($ip);

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

         * @return int - Created records ID

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

         * @param string $ip   - User IP

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

            $db->createCommand()->delete('a_#__bruteforce_blocked', [

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

         * Function unblocks user.

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

        {

    Line exceeds 120 characters; contains 131 characters
    Open

                ->select(['usersName' => new \yii\db\Expression('DISTINCT user_name'), 'browser' => new \yii\db\Expression('browser')])

    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

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

                ->where(['>=', 'time', $checkData])

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

                        'blocked' => $blocked,

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

            $this->clearBlockedByIp($ip, $checkData);

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

         * Function adds unsuccessful login attempt to database.

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

         */

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

            ])->execute();

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

            return $this->blockedId = $db->getLastInsertID('a_#__bruteforce_blocked_id_seq');

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

        private function clearBlockedByIp($ip, $data)

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

                ->update('a_#__bruteforce_blocked', [

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

                    'userid' => \App\User::getCurrentUserRealId(),

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

         * Function returns a list of users who are administrators.

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

        }

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

            $time = $this->get('timelock');

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

            $time = $this->get('timelock');

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

                        'attempts' => $attempts,

    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

                ->andWhere(['>=', 'login_time', $data['time']]);

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

            $data['usersName'] = implode(', ', $users);

    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 (isset($this->isBlocked)) {

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

        public function updateBlockedIp()

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

         * @param string $ip - User IP

    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

                    'timelock' => $data['timelock'],

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

            if (!empty($this->get('sent'))) {

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

                if (0 === \count($usersId)) {

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

                $emails = [];

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

                    $emails[] = $recordModel->get('email1');

    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 ($usersId as $id) {

    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\Log::trace('End ' . __METHOD__ . ' - No brute force users found to send email');

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

                    'moduleName' => 'Users',

    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

            \App\Log::trace('Start ' . __METHOD__);

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

                }

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

                    'to' => $emails,

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

            $db->createCommand()->delete('a_#__bruteforce_users')->execute();

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

            App\Cache::delete('BruteForce', 'Settings');

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

         *

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

         * Function sends notifications.

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

                $usersId = self::getUsersForNotifications();

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

                    $recordModel = Vtiger_Record_Model::getInstanceById($id, 'Users');

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

                }

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

                $configBruteForce = self::getBruteForceSettings();

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

                \App\Mailer::sendFromTemplate([

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

                    'ip' => \App\RequestUtil::getRemoteIP(true),

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

            $historyData = $query->createCommand()->queryAllByGroup(2);

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

        public static function getUsersForNotifications()

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

            $blockDate->modify("-$time minutes");

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

            }

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

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

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

         * @param int $id - Record ID

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

                    return 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

                foreach ($users as $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

                    'time' => (new DateTime())->modify("-{$configBruteForce['timelock']} minutes")->format('Y-m-d H:i:s'),

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

                ])->execute();

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

         * Function returns table of users selected for notifications.

    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 ($historyData as $browsersUserName) {

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

                return $this->isBlocked;

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

        public function incAttempts()

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

        }

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

            $ip = \App\RequestUtil::getRemoteIP(true);

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

                ->andWhere(['ip' => $ip])->one();

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

                $this->isBlocked = self::BLOCKED === $blocked;

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

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

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

                'ip' => $ip,

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

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

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

                ->execute();

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

                ->update('a_#__bruteforce', [

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

                    'sent' => $data['sent'],

    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

                    'template' => 'BruteForceSecurityRiskHasBeenDetected',

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

                    'active' => $data['active'],

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

                $users = !\is_array($data['selectedUsers']) ? [$data['selectedUsers']] : $data['selectedUsers'];

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

            return (new \App\Db\Query())->from('a_#__bruteforce_users')->createCommand()->queryColumn();

    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

                    $db->createCommand()->insert('a_#__bruteforce_users', ['id' => $userId])->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 function sendNotificationEmail()

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

            \App\Log::trace('End ' . __METHOD__);

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

            if (!empty($this->blockedId)) {

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

         * Function updates unsuccessful login attempts.

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

                $db->createCommand()

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

                    ], ['id' => $bfData['id']])

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

                $this->blockedId = $bfData['id'];

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

            }

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

        private function setBlockedIp($ip)

    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

        public static function getAdminUsers()

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

            return \App\Fields\Owner::getInstance()->getUsers(false, 'Active', false, false, 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

         * @return array - ID list of users

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

        {

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

                ->from('a_#__bruteforce_blocked')

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

            return $this->isBlocked = (!empty($this->blockedId));

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

         */

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

                    ->update('a_#__bruteforce_blocked', [

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

            $this->isBlocked = false;

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

                ['blocked' => self::UNBLOCKED],

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

         */

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

                    'attempsnumber' => $data['attempsnumber'],

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

            if (!empty($data['selectedUsers'])) {

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

    class Settings_BruteForce_Module_Model extends Settings_Vtiger_Module_Model

    There are no issues that match your filters.

    Category
    Status