YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/Workflows/views/Import.php

Summary

Maintainability
C
7 hrs
Test Coverage
F
0%

process accesses the super-global variable $_FILES.
Open

    public function process(App\Request $request)
    {
        \App\Log::trace('Start ' . __METHOD__);
        $qualifiedModule = $request->getModule(false);
        $viewer = $this->getViewer($request);

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

process accesses the super-global variable $_FILES.
Open

    public function process(App\Request $request)
    {
        \App\Log::trace('Start ' . __METHOD__);
        $qualifiedModule = $request->getModule(false);
        $viewer = $this->getViewer($request);

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

process accesses the super-global variable $_FILES.
Open

    public function process(App\Request $request)
    {
        \App\Log::trace('Start ' . __METHOD__);
        $qualifiedModule = $request->getModule(false);
        $viewer = $this->getViewer($request);

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

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

    public function process(App\Request $request)
    {
        \App\Log::trace('Start ' . __METHOD__);
        $qualifiedModule = $request->getModule(false);
        $viewer = $this->getViewer($request);
Severity: Minor
Found in modules/Settings/Workflows/views/Import.php - About 5 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 52 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process(App\Request $request)
    {
        \App\Log::trace('Start ' . __METHOD__);
        $qualifiedModule = $request->getModule(false);
        $viewer = $this->getViewer($request);
Severity: Major
Found in modules/Settings/Workflows/views/Import.php - About 2 hrs to fix

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

        public function process(App\Request $request)
        {
            \App\Log::trace('Start ' . __METHOD__);
            $qualifiedModule = $request->getModule(false);
            $viewer = $this->getViewer($request);

    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 38 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 static access to class '\App\Log' in method 'process'.
    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 'Settings_Workflows_Module_Model' in method 'process'.
    Open

                    $workflowModel = Settings_Workflows_Module_Model::getInstance('Settings:Workflows');

    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 {
                    $viewer->assign('UPLOAD_ERROR', \App\Language::translate('LBL_UPLOAD_ERROR', $qualifiedModule));
                    $viewer->assign('UPLOAD', false);
                }

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

                    $viewer->assign('UPLOAD_ERROR', \App\Language::translate('LBL_UPLOAD_ERROR', $qualifiedModule));

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

                $xmlName = $_FILES['imported_xml']['name'];

    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 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 \Vtiger_Viewer::assign
    Open

                    $viewer->assign('MESSAGES', $messages);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

                    $viewer->assign('UPLOAD_ERROR', \App\Language::translate('LBL_UPLOAD_ERROR', $qualifiedModule));

    Call to undeclared method \Vtiger_Viewer::assign
    Open

                    $viewer->assign('RECORDID', $messages['id']);

    Suspicious array access to int
    Open

                    $viewer->assign('RECORDID', $messages['id']);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

                    $viewer->assign('UPLOAD', true);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('QUALIFIED_MODULE', $qualifiedModule);

    Return type of getHeaderCss() is undeclared type \App\Controller\View\Vtiger_CssScript_Model[]
    Open

        public function getHeaderCss(App\Request $request)

    Call to undeclared method \Vtiger_Viewer::assign
    Open

                    $viewer->assign('UPLOAD', false);

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

    class Settings_Workflows_Import_View extends Settings_Vtiger_Index_View

    The class Settings_Workflows_Import_View is not named in CamelCase.
    Open

    class Settings_Workflows_Import_View extends Settings_Vtiger_Index_View
    {
        public function process(App\Request $request)
        {
            \App\Log::trace('Start ' . __METHOD__);

    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

        public function process(App\Request $request)

    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

            $viewer = $this->getViewer($request);

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

                        foreach ($fieldsValue as $fieldKey => $fieldValue) {

    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 ('workflow_task' === $fieldKey) {

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

                    $viewer->assign('UPLOAD', 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

            $viewer->assign('QUALIFIED_MODULE', $qualifiedModule);

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

            if ($request->has('upload') && 'true' == $request->get('upload')) {

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

                    $xml = simplexml_load_file($uploadedXml);

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

                    }

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

                    $viewer->assign('UPLOAD', 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_merge($cssInstances, $headerCssInstances);

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

                $xmlError = $_FILES['imported_xml']['error'];

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

                    $taskIndex = $methodIndex = 0;

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

                                    $columnKey = 'test';

    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

            $cssInstances = $this->checkAndConvertCssStyles($cssFileNames);

    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

            $qualifiedModule = $request->getModule(false);

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

                                switch ($fieldKey) {

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

                                        $params[$fieldsKey][$taskIndex][$columnKey] = (string) $columnValue;

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

                        }

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

                    $viewer->assign('RECORDID', $messages['id']);

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

        public function getHeaderCss(App\Request $request)

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

                            }

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

                $uploadedXml = $_FILES['imported_xml']['tmp_name'];

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

                    $viewer->assign('UPLOAD_ERROR', \App\Language::translate('LBL_UPLOAD_ERROR', $qualifiedModule));

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

                $xmlName = $_FILES['imported_xml']['name'];

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

                $extension = end($explodeXmlName);

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

                    $params = [];

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

                    $workflowModel = Settings_Workflows_Module_Model::getInstance('Settings:Workflows');

    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

                $explodeXmlName = explode('.', $xmlName);

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

                                } elseif ('type' == $columnKey && empty($columnValue)) {

    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 (UPLOAD_ERR_OK == $xmlError && 'xml' === $extension) {

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

                                if ('conditions' === $columnKey) {

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

                                    case 'workflow_method':

    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

                                        $params[$fieldsKey][$columnKey] = (string) $columnValue;

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

                            }

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

                                ++$taskIndex;

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

                    $viewer->assign('MESSAGES', $messages);

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

                                    $columnValue = 'basic';

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

                                    case 'workflow_task':

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

                                    default:

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

                    foreach ($xml as $fieldsKey => $fieldsValue) {

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

                                        $params[$fieldsKey][$methodIndex][$columnKey] = (string) $columnValue;

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

                            } elseif ('workflow_method' === $fieldKey) {

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

                                ++$methodIndex;

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

            $viewer->view('Import.tpl', $qualifiedModule);

    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

            $headerCssInstances = parent::getHeaderCss($request);

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

            $moduleName = $request->getModule();

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

                            foreach ($fieldValue as $columnKey => $columnValue) {

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

                                }

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

                    $messages = $workflowModel->importWorkflow($params);

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

            $cssFileNames = [

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

                "modules.Settings.$moduleName.Import",

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

    class Settings_Workflows_Import_View extends Settings_Vtiger_Index_View

    There are no issues that match your filters.

    Category
    Status