YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/Workflows/actions/ExportWorkflow.php

Summary

Maintainability
B
4 hrs
Test Coverage
F
0%

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

    public function process(App\Request $request)
    {
        $recordId = $request->getInteger('id');
        $workflowModel = Settings_Workflows_Record_Model::getInstance($recordId);
        $workflowObject = $workflowModel->getWorkflowObject();
Severity: Major
Found in modules/Settings/Workflows/actions/ExportWorkflow.php - About 2 hrs to fix

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

        public function process(App\Request $request)
        {
            $recordId = $request->getInteger('id');
            $workflowModel = Settings_Workflows_Record_Model::getInstance($recordId);
            $workflowObject = $workflowModel->getWorkflowObject();
    Severity: Minor
    Found in modules/Settings/Workflows/actions/ExportWorkflow.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

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

            $xml = new DOMDocument('1.0', 'utf-8');

    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 process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                    } else {
                        $value = $workflowModel->get($field);
                        $xmlColumn = $xml->createElement($field, html_entity_decode($value, ENT_COMPAT, 'UTF-8'));
                    }

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

            $workflowModel = Settings_Workflows_Record_Model::getInstance($recordId);

    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

                    $method = Settings_Workflows_Module_Model::exportTaskMethod($taskObject->methodName);

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

                        $xmlColumn = $xml->createElement($field, html_entity_decode($value, ENT_COMPAT, 'UTF-8'));

    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.

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

    class Settings_Workflows_ExportWorkflow_Action extends Settings_Vtiger_Index_Action

    The class Settings_Workflows_ExportWorkflow_Action is not named in CamelCase.
    Open

    class Settings_Workflows_ExportWorkflow_Action extends Settings_Vtiger_Index_Action
    {
        public function process(App\Request $request)
        {
            $recordId = $request->getInteger('id');

    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

            $workflowObject = $workflowModel->getWorkflowObject();

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

            $xmlFields = $xml->createElement('fields');

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

                } elseif (isset($workflowObject->{$field})) {

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

                }

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

                $xmlTask = $xml->createElement('workflow_task');

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

                    $method = Settings_Workflows_Module_Model::exportTaskMethod($taskObject->methodName);

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

                    if (!\array_key_exists($method['workflowtasks_entitymethod_id'], $method)) {

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

            foreach ($workflowMethods as $method) {

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

            header('content-type: application/xml; charset=utf-8');

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

                        $name->appendChild($xml->createCDATASection(json_encode($workflowModel->get($field))));

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

                    }

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

            $xmlFields->appendChild($xmlField);

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

            $xmlTemplate->appendChild($xmlFields);

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

                $xmlTemplate->appendChild($xmlTasks);

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

            echo $xml->saveXML();

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

        public function validateRequest(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

            $xmlTemplate = $xml->createElement('workflow');

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

                        $name = $xmlField->appendChild($xml->createElement($field));

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

                    require_once 'modules/com_vtiger_workflow/tasks/VTEntityMethodTask.php';

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

                if ($workflowModel->has($field)) {

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

            }

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

                $xmlField->appendChild($xmlColumn);

    Line exceeds 120 characters; contains 141 characters
    Open

                $xmlMethod->appendChild($xml->createElement('function_path', html_entity_decode($method['function_path'], ENT_COMPAT, 'UTF-8')));

    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

            header('cache-control: private');

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

            header('content-disposition: attachment; filename="' . $recordId . '_workflow.xml"');

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

            $cDataColumns = ['conditions'];

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

                        $value = $workflowModel->get($field);

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

                        $xmlColumn = $xml->createElement($field, html_entity_decode($value, ENT_COMPAT, 'UTF-8'));

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

                $xmlColumn = $xml->createElement('summary', html_entity_decode($task['summary'], ENT_COMPAT, 'UTF-8'));

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

                if (false !== strpos($task['task'], 'VTEntityMethodTask')) {

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

                $script->appendChild($xml->createCDATASection(html_entity_decode($method['script_content'])));

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

                $xmlTemplate->appendChild($xmlMethods);

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

            $xml->appendChild($xmlTemplate);

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

                    $value = $workflowObject->{$field};

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

            $xmlTasks = $xml->createElement('workflow_tasks');

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

                $xmlTask->appendChild($xmlColumn);

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

                    $taskObject = unserialize(html_entity_decode($task['task']));

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

                $xmlMethod->appendChild($xml->createElement('function_path', html_entity_decode($method['function_path'], ENT_COMPAT, 'UTF-8')));

    Line exceeds 120 characters; contains 141 characters
    Open

                $xmlMethod->appendChild($xml->createElement('function_name', html_entity_decode($method['function_name'], ENT_COMPAT, 'UTF-8')));

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

            $workflowModel = Settings_Workflows_Record_Model::getInstance($recordId);

    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

            $xml = new DOMDocument('1.0', 'utf-8');

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

            $xmlField = $xml->createElement('field');

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

            foreach (Settings_Workflows_Module_Model::$allFields as $field) {

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

            foreach ($workflowModel->getTasksForExport() as $task) {

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

                        $workflowMethods[$method['workflowtasks_entitymethod_id']] = $method;

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

            $xmlMethods = $xml->createElement('workflow_methods');

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

                $xmlMethod = $xml->createElement('workflow_method');

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

            $workflowMethods = [];

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

            header('pragma: public');

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

                    }

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

                $script = $xmlMethod->appendChild($xml->createElement('script_content'));

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

        {

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

            $xml->formatOutput = true;

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

                    if (\in_array($field, $cDataColumns)) {

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

                $name->appendChild($xml->createCDATASection(base64_encode($task['task'])));

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

                $xmlMethod->appendChild($xml->createElement('method_name', html_entity_decode($method['method_name'], ENT_COMPAT, 'UTF-8')));

    Line exceeds 120 characters; contains 137 characters
    Open

                $xmlMethod->appendChild($xml->createElement('method_name', html_entity_decode($method['method_name'], ENT_COMPAT, 'UTF-8')));

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

                $xmlMethod->appendChild($xml->createElement('function_name', html_entity_decode($method['function_name'], ENT_COMPAT, 'UTF-8')));

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

                $xmlMethods->appendChild($xmlMethod);

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

            $xml->preserveWhiteSpace = false;

    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

            $request->validateReadAccess();

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

            $recordId = $request->getInteger('id');

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

            header('content-description: PHP Generated Data');

    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

                    $xmlColumn = $xml->createElement($field, html_entity_decode($value, ENT_COMPAT, 'UTF-8'));

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

            }

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

                $name = $xmlTask->appendChild($xml->createElement('task'));

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

                $xmlTasks->appendChild($xmlTask);

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

                $xmlMethod->appendChild($xml->createElement('module_name', html_entity_decode($method['module_name'], ENT_COMPAT, 'UTF-8')));

    Line exceeds 120 characters; contains 137 characters
    Open

                $xmlMethod->appendChild($xml->createElement('module_name', html_entity_decode($method['module_name'], ENT_COMPAT, 'UTF-8')));

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

    class Settings_Workflows_ExportWorkflow_Action extends Settings_Vtiger_Index_Action

    There are no issues that match your filters.

    Category
    Status