YetiForceCompany/YetiForceCRM

View on GitHub
modules/Users/textparsers/Bruteforce.php

Summary

Maintainability
A
0 mins
Test Coverage
F
0%

Missing class import via use statement (line '30', column '25').
Open

        $attemptsLogin = (new \App\Db\Query())->from('vtiger_loginhistory')

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

            $time = \App\Fields\DateTime::formatToDisplay($data['login_time']);

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

        $html .= '<hr><table border="1" cellspacing="0" style="width:100%"><tr style="font-weight: bold;"><td>' . \App\Language::translate('SINGLE_Users', 'Users') . '</td><td>' . \App\Language::translate('LBL_DATE') . '</td><td>' . \App\Language::translate('LBL_STATUS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_BROWSERS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_USER_AGENT', 'Settings:BruteForce') . '</td></tr>';

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

            $status = \App\Language::translate($data['status'], '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\Language' in method 'process'.
Open

        $html .= '<hr><table border="1" cellspacing="0" style="width:100%"><tr style="font-weight: bold;"><td>' . \App\Language::translate('SINGLE_Users', 'Users') . '</td><td>' . \App\Language::translate('LBL_DATE') . '</td><td>' . \App\Language::translate('LBL_STATUS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_BROWSERS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_USER_AGENT', 'Settings:BruteForce') . '</td></tr>';

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

        $html .= '<hr><table border="1" cellspacing="0" style="width:100%"><tr style="font-weight: bold;"><td>' . \App\Language::translate('SINGLE_Users', 'Users') . '</td><td>' . \App\Language::translate('LBL_DATE') . '</td><td>' . \App\Language::translate('LBL_STATUS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_BROWSERS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_USER_AGENT', 'Settings:BruteForce') . '</td></tr>';

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

        $html .= '<hr><table border="1" cellspacing="0" style="width:100%"><tr style="font-weight: bold;"><td>' . \App\Language::translate('SINGLE_Users', 'Users') . '</td><td>' . \App\Language::translate('LBL_DATE') . '</td><td>' . \App\Language::translate('LBL_STATUS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_BROWSERS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_USER_AGENT', 'Settings:BruteForce') . '</td></tr>';

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

        $html .= '<hr><table border="1" cellspacing="0" style="width:100%"><tr style="font-weight: bold;"><td>' . \App\Language::translate('SINGLE_Users', 'Users') . '</td><td>' . \App\Language::translate('LBL_DATE') . '</td><td>' . \App\Language::translate('LBL_STATUS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_BROWSERS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_USER_AGENT', 'Settings:BruteForce') . '</td></tr>';

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

        $html = \App\Language::translate('LBL_BLOCKED_IP', 'Settings::BruteForce') . ': ' . $this->displayIpAddress($this->textParser->getParam('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 "<td>" 4 times.</td>
Open

        $html .= '<hr><table border="1" cellspacing="0" style="width:100%"><tr style="font-weight: bold;"><td>' . \App\Language::translate('SINGLE_Users', 'Users') . '</td><td>' . \App\Language::translate('LBL_DATE') . '</td><td>' . \App\Language::translate('LBL_STATUS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_BROWSERS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_USER_AGENT', 'Settings:BruteForce') . '</td></tr>';

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

                ['>=', 'login_time', $this->textParser->getParam('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 "Settings:BruteForce" 3 times.
Open

        $html .= '<hr><table border="1" cellspacing="0" style="width:100%"><tr style="font-weight: bold;"><td>' . \App\Language::translate('SINGLE_Users', 'Users') . '</td><td>' . \App\Language::translate('LBL_DATE') . '</td><td>' . \App\Language::translate('LBL_STATUS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_BROWSERS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_USER_AGENT', 'Settings:BruteForce') . '</td></tr>';

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::from
Open

        $attemptsLogin = (new \App\Db\Query())->from('vtiger_loginhistory')
Severity: Critical
Found in modules/Users/textparsers/Bruteforce.php by phan

Call to method getParam from undeclared class \App\TextParser (Did you mean class \Tests\App\TextParser)
Open

                ['user_ip' => $this->textParser->getParam('ip')],
Severity: Critical
Found in modules/Users/textparsers/Bruteforce.php by phan

Call to method getParam from undeclared class \App\TextParser (Did you mean class \Tests\App\TextParser)
Open

        $html = \App\Language::translate('LBL_BLOCKED_IP', 'Settings::BruteForce') . ': ' . $this->displayIpAddress($this->textParser->getParam('ip'));
Severity: Critical
Found in modules/Users/textparsers/Bruteforce.php by phan

Call to method getParam from undeclared class \App\TextParser (Did you mean class \Tests\App\TextParser)
Open

                ['>=', 'login_time', $this->textParser->getParam('time')],
Severity: Critical
Found in modules/Users/textparsers/Bruteforce.php by phan

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

class Users_Bruteforce_Textparser extends \App\TextParser\Base

The class Users_Bruteforce_Textparser is not named in CamelCase.
Open

class Users_Bruteforce_Textparser extends \App\TextParser\Base
{
    /** @var string Class name */
    public $name = 'LBL_BRUTAL_FORCE';

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 $ip. Configured minimum length is 3.
Open

    private function displayIpAddress($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

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

                'and',

Line exceeds 120 characters; contains 148 characters
Open

            $html .= "<tr><td>{$data['user_name']}</td><td>{$time}</td><td>{$status}</td><td>{$data['browser']}</td><td>{$data['agent']}</td></tr>";

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

            ])->orderBy(['login_time' => SORT_DESC])->all();

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

        $ipAddress = explode('.', $ip);

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

        $attemptsLogin = (new \App\Db\Query())->from('vtiger_loginhistory')

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

            $status = \App\Language::translate($data['status'], 'Users');

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

            $html .= "<tr><td>{$data['user_name']}</td><td>{$time}</td><td>{$status}</td><td>{$data['browser']}</td><td>{$data['agent']}</td></tr>";

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 string

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

        return $html . '</table>';

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 $type = 'mail';

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

    /** @var string Class name */

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 = \App\Fields\DateTime::formatToDisplay($data['login_time']);

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

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

            ->where([

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

        }

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

    /** @var mixed Parser type */

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

        $html = \App\Language::translate('LBL_BLOCKED_IP', 'Settings::BruteForce') . ': ' . $this->displayIpAddress($this->textParser->getParam('ip'));

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

        $html .= '<hr><table border="1" cellspacing="0" style="width:100%"><tr style="font-weight: bold;"><td>' . \App\Language::translate('SINGLE_Users', 'Users') . '</td><td>' . \App\Language::translate('LBL_DATE') . '</td><td>' . \App\Language::translate('LBL_STATUS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_BROWSERS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_USER_AGENT', 'Settings:BruteForce') . '</td></tr>';

Line exceeds 120 characters; contains 472 characters
Open

        $html .= '<hr><table border="1" cellspacing="0" style="width:100%"><tr style="font-weight: bold;"><td>' . \App\Language::translate('SINGLE_Users', 'Users') . '</td><td>' . \App\Language::translate('LBL_DATE') . '</td><td>' . \App\Language::translate('LBL_STATUS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_BROWSERS', 'Settings:BruteForce') . '</td><td>' . \App\Language::translate('LBL_USER_AGENT', 'Settings:BruteForce') . '</td></tr>';

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

                ['>=', 'login_time', $this->textParser->getParam('time')],

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

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

    }

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

        unset($ipAddress[\count($ipAddress) - 1]);

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

     * Function to display ip address.

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

Line exceeds 120 characters; contains 151 characters
Open

        $html = \App\Language::translate('LBL_BLOCKED_IP', 'Settings::BruteForce') . ': ' . $this->displayIpAddress($this->textParser->getParam('ip'));

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

        return implode('.', $ipAddress) . '.xxx';

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 $name = 'LBL_BRUTAL_FORCE';

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

     * Process.

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

                ['user_ip' => $this->textParser->getParam('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

    private function displayIpAddress($ip)

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

class Users_Bruteforce_Textparser extends \App\TextParser\Base

There are no issues that match your filters.

Category
Status