YetiForceCompany/YetiForceCRM

View on GitHub
app/SystemWarnings/Security/CheckServerIpInBlackList.php

Summary

Maintainability
A
1 hr
Test Coverage
F
37%

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

    public function process(): void
    {
        $this->status = 1;
        if (($ip = \App\RequestUtil::getRemoteIP(true)) && ($blackList = \App\Mail\Rbl::findIp($ip, true))) {
            foreach ($blackList as $row) {
Severity: Minor
Found in app/SystemWarnings/Security/CheckServerIpInBlackList.php - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Avoid assigning values to variables in if clauses and the like (line '34', column '8').
Open

    public function process(): void
    {
        $this->status = 1;
        if (($ip = \App\RequestUtil::getRemoteIP(true)) && ($blackList = \App\Mail\Rbl::findIp($ip, true))) {
            foreach ($blackList as $row) {

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

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

        if (($ip = \App\RequestUtil::getRemoteIP(true)) && ($blackList = \App\Mail\Rbl::findIp($ip, 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 assigning values to variables in if clauses and the like (line '34', column '55').
Open

    public function process(): void
    {
        $this->status = 1;
        if (($ip = \App\RequestUtil::getRemoteIP(true)) && ($blackList = \App\Mail\Rbl::findIp($ip, true))) {
            foreach ($blackList as $row) {

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

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

        if (($ip = \App\RequestUtil::getRemoteIP(true)) && ($blackList = \App\Mail\Rbl::findIp($ip, 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\Language' in method 'process'.
Open

                $this->description = \App\Language::translate('LBL_BLACK_LIST_ALERT', 'OSSMail');

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 variables with short names like $ip. Configured minimum length is 3.
Open

        if (($ip = \App\RequestUtil::getRemoteIP(true)) && ($blackList = \App\Mail\Rbl::findIp($ip, 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

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 void

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

                if ((\App\Mail\Rbl::LIST_TYPE_BLACK_LIST === (int) $row['type']) || (\App\Mail\Rbl::LIST_TYPE_PUBLIC_BLACK_LIST === (int) $row['type'])) {

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

        if (($ip = \App\RequestUtil::getRemoteIP(true)) && ($blackList = \App\Mail\Rbl::findIp($ip, 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

        $this->status = 1;

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

                    break;

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

            if (!$this->status) {

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

    }

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

    protected $title = 'LBL_CHECK_SERVER_BLACK_LIST_IP';

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

    /** {@inheritdoc} */

Line exceeds 120 characters; contains 154 characters
Open

                if ((\App\Mail\Rbl::LIST_TYPE_BLACK_LIST === (int) $row['type']) || (\App\Mail\Rbl::LIST_TYPE_PUBLIC_BLACK_LIST === (int) $row['type'])) {

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

            }

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

    {

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

            foreach ($blackList as $row) {

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 function process(): void

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

    /** {@inheritdoc} */

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

    protected $priority = 9;

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

     * checks if a given ip address is on the blacklist.

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

                    $this->status = 0;

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

            }

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

                $this->description = \App\Language::translate('LBL_BLACK_LIST_ALERT', 'OSSMail');

There are no issues that match your filters.

Category
Status