YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/Log/actions/LogsOwasp.php

Summary

Maintainability
B
4 hrs
Test Coverage
F
0%

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

    public function process(App\Request $request)
    {
        $type = $request->getByType('type', 1);
        $range = $request->getByType('range', 'DateRangeUserFormat');
        if (!isset(App\Log::$owaspColumnMapping[$type])) {
Severity: Minor
Found in modules/Settings/Log/actions/LogsOwasp.php - About 2 hrs 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

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

    public function process(App\Request $request)
    {
        $type = $request->getByType('type', 1);
        $range = $request->getByType('range', 'DateRangeUserFormat');
        if (!isset(App\Log::$owaspColumnMapping[$type])) {
Severity: Major
Found in modules/Settings/Log/actions/LogsOwasp.php - About 2 hrs to fix

    The method process() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10.
    Open

        public function process(App\Request $request)
        {
            $type = $request->getByType('type', 1);
            $range = $request->getByType('range', 'DateRangeUserFormat');
            if (!isset(App\Log::$owaspColumnMapping[$type])) {

    CyclomaticComplexity

    Since: 0.1

    Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

    Example

    // Cyclomatic Complexity = 11
    class Foo {
    1   public function example() {
    2       if ($a == $b) {
    3           if ($a1 == $b1) {
                    fiddle();
    4           } elseif ($a2 == $b2) {
                    fiddle();
                } else {
                    fiddle();
                }
    5       } elseif ($c == $d) {
    6           while ($c == $d) {
                    fiddle();
                }
    7        } elseif ($e == $f) {
    8           for ($n = 0; $n < $h; $n++) {
                    fiddle();
                }
            } else {
                switch ($z) {
    9               case 1:
                        fiddle();
                        break;
    10              case 2:
                        fiddle();
                        break;
    11              case 3:
                        fiddle();
                        break;
                    default:
                        fiddle();
                        break;
                }
            }
        }
    }

    Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

    Refactor this function to reduce its Cognitive Complexity from 26 to the 15 allowed.
    Open

        public function process(App\Request $request)

    Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

    See

    Avoid using undefined variables such as '$owaspColumnMapping' which will lead to PHP notices.
    Open

            if (!isset(App\Log::$owaspColumnMapping[$type])) {

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

    Source https://phpmd.org/rules/cleancode.html#undefinedvariable

    Avoid using undefined variables such as '$owaspColumnMapping' which will lead to PHP notices.
    Open

                foreach (\App\Log::$owaspColumnMapping[$type] as $column) {

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

    Source https://phpmd.org/rules/cleancode.html#undefinedvariable

    Avoid using undefined variables such as '$owaspColumnMapping' which will lead to PHP notices.
    Open

            foreach (\App\Log::$owaspColumnMapping[$type] as $column) {

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

    Source https://phpmd.org/rules/cleancode.html#undefinedvariable

    Avoid using undefined variables such as '$owaspColumnMapping' which will lead to PHP notices.
    Open

                $column = \App\Log::$owaspColumnMapping[$type][$order['0']['column']];

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

    Source https://phpmd.org/rules/cleancode.html#undefinedvariable

    Missing class import via use statement (line '22', column '17').
    Open

            $query = (new \App\Db\Query())->from('o_#__' . $type);

    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 '64', column '19').
    Open

            $response = new Vtiger_Response();

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

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

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

                throw new \App\Exceptions\NoPermittedForAdmin('ERR_ILLEGAL_VALUE');

    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 assigning values to variables in if clauses and the like (line '46', column '31').
    Open

        public function process(App\Request $request)
        {
            $type = $request->getByType('type', 1);
            $range = $request->getByType('range', 'DateRangeUserFormat');
            if (!isset(App\Log::$owaspColumnMapping[$type])) {

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

                        $log[$column] = \App\Purifier::encodeHtml($log[$column]);

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

                            $requestArray .= \App\Purifier::encodeHtml("$key => $val") . PHP_EOL;

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

            $response->setResult(\App\Json::encode([
                'data' => $data,
                'draw' => $request->getInteger('draw', 1),
                'recordsFiltered' => $logsCount,
                'recordsTotal' => $logsCountAll,

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

                        $log[$column] = \App\Layout::truncateText($requestArray, 70, 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

                $columns[$column] = \App\Language::translate('LBL_' . strtoupper($column), $request->getModule(false));

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

                        foreach (\App\Json::decode($log[$column]) as $key => $val) {

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

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

            } else {
                $query->orderBy(['id' => \SORT_DESC]);
            }

    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

    Define a constant instead of duplicating this literal "column" 3 times.
    Open

                    'column' => 'Integer',

    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.

    Reference to static property owaspColumnMapping from undeclared class \App\Log
    Open

                $column = \App\Log::$owaspColumnMapping[$type][$order['0']['column']];
    Severity: Critical
    Found in modules/Settings/Log/actions/LogsOwasp.php by phan

    Reference to static property owaspColumnMapping from undeclared class \App\Log
    Open

            foreach (\App\Log::$owaspColumnMapping[$type] as $column) {
    Severity: Critical
    Found in modules/Settings/Log/actions/LogsOwasp.php by phan

    Reference to static property owaspColumnMapping from undeclared class \App\Log
    Open

            if (!isset(App\Log::$owaspColumnMapping[$type])) {
    Severity: Critical
    Found in modules/Settings/Log/actions/LogsOwasp.php by phan

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

            $query = (new \App\Db\Query())->from('o_#__' . $type);
    Severity: Critical
    Found in modules/Settings/Log/actions/LogsOwasp.php by phan

    Reference to static property owaspColumnMapping from undeclared class \App\Log
    Open

                foreach (\App\Log::$owaspColumnMapping[$type] as $column) {
    Severity: Critical
    Found in modules/Settings/Log/actions/LogsOwasp.php by phan

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

    class Settings_Log_LogsOwasp_Action extends Settings_Vtiger_Basic_Action

    The class Settings_Log_LogsOwasp_Action is not named in CamelCase.
    Open

    class Settings_Log_LogsOwasp_Action extends Settings_Vtiger_Basic_Action
    {
        /** {@inheritdoc} */
        public function process(App\Request $request)
        {

    CamelCaseClassName

    Since: 0.2

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

    Example

    class class_name {
    }

    Source

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

            $query = (new \App\Db\Query())->from('o_#__' . $type);

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

                $column = \App\Log::$owaspColumnMapping[$type][$order['0']['column']];

    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

            $data = [];

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

            foreach (\App\Log::$owaspColumnMapping[$type] as $column) {

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

            ]);

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

            $response->setResult(\App\Json::encode([

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

                    if ('url' === $column && ($urlParams = explode('?', $log['url'])) && isset($urlParams[1])) {

    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

                'recordsFiltered' => $logsCount,

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

            ]));

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

        public function process(App\Request $request)

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

            $range = $request->getByType('range', 'DateRangeUserFormat');

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

                $dir = ('asc' === $order['0']['dir']) ? \SORT_ASC : \SORT_DESC;

    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(App\Log::$owaspColumnMapping[$type])) {

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

            $query->limit($request->getInteger('limit', 10));

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

                    } elseif ('request' === $column) {

    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 ($query->all() as $log) {

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

                'draw' => $request->getInteger('draw', 1),

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

            $response->emit();

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

            $logsCountAll = $logsCount = (int) $query->count('*');

    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

            $response = new Vtiger_Response();

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

                'recordsTotal' => $logsCountAll,

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

            $type = $request->getByType('type', 1);

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

            $response->setEmitType(Vtiger_Response::$EMIT_JSONTEXT);

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

        /** {@inheritdoc} */

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

        {

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

            }

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

            $query->offset($request->getInteger('start', 0));

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

                $query->orderBy(['id' => \SORT_DESC]);

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

                    if (\in_array($column, ['url', 'agent', 'referer'])) {

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

                        $log[$column] = $urlParams[1];

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

                $columns[$column] = \App\Language::translate('LBL_' . strtoupper($column), $request->getModule(false));

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

                        foreach (\App\Json::decode($log[$column]) as $key => $val) {

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

                'columns' => $columns

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

            $query->where(['between', 'date', $range[0] . ' 00:00:00', $range[1] . ' 23:59:59']);

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

                    'column' => 'Integer',

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

                    'dir' => 'Standard'

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

                        $requestArray = '';

    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

                        $log[$column] = \App\Purifier::encodeHtml($log[$column]);

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

                            $val = (\is_array($val)) ? var_export($val, true) : $val;

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

                            $requestArray .= \App\Purifier::encodeHtml("$key => $val") . PHP_EOL;

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

                        $log[$column] = \App\Layout::truncateText($requestArray, 70, true);

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

                'data' => $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

            $order = $request->getMultiDimensionArray('order', [

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

                $query->orderBy([$column => $dir]);

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

                foreach (\App\Log::$owaspColumnMapping[$type] as $column) {

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

                throw new \App\Exceptions\NoPermittedForAdmin('ERR_ILLEGAL_VALUE');

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

            if (isset($order['0']['column'])) {

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

                $data[] = $log;

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

            $columns = [];

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

    class Settings_Log_LogsOwasp_Action extends Settings_Vtiger_Basic_Action

    There are no issues that match your filters.

    Category
    Status