YetiForceCompany/YetiForceCRM

View on GitHub
modules/Calendar/views/Import.php

Summary

Maintainability
A
25 mins
Test Coverage
F
0%

Function undoImport has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function undoImport(App\Request $request)
    {
        if ($request->has('type') && 'ics' === $request->getByType('type', 'Text')) {
            $currentUserModel = Users_Record_Model::getCurrentUserModel();
            $moduleName = $request->getModule();
Severity: Minor
Found in modules/Calendar/views/Import.php - About 25 mins 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 '79', column '22').
Open

            $lastImport = new ICalLastImport();
Severity: Minor
Found in modules/Calendar/views/Import.php by phpmd

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 'Import_Utils_Helper' in method 'importResult'.
Open

        if (Import_Utils_Helper::validateFileUpload($request)) {
Severity: Minor
Found in modules/Calendar/views/Import.php by phpmd

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 'Import_Utils_Helper' in method 'importResult'.
Open

            $result = $moduleModel->importICS(Import_Utils_Helper::getImportFilePath(\App\User::getCurrentUserModel()));
Severity: Minor
Found in modules/Calendar/views/Import.php by phpmd

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\User' in method 'importResult'.
Open

            $result = $moduleModel->importICS(Import_Utils_Helper::getImportFilePath(\App\User::getCurrentUserModel()));
Severity: Minor
Found in modules/Calendar/views/Import.php by phpmd

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

        } else {
            $viewer->assign('ERROR_MESSAGE', $request->getByType('error_message', 'Text'));
        }
Severity: Minor
Found in modules/Calendar/views/Import.php by phpmd

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 'Vtiger_Module_Model' in method 'importResult'.
Open

        $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
Severity: Minor
Found in modules/Calendar/views/Import.php by phpmd

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

        } else {
            parent::uploadAndParse($request);
        }
Severity: Minor
Found in modules/Calendar/views/Import.php by phpmd

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

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

        } else {
            parent::undoImport($request);
        }
Severity: Minor
Found in modules/Calendar/views/Import.php by phpmd

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 'Users_Record_Model' in method 'undoImport'.
Open

            $currentUserModel = Users_Record_Model::getCurrentUserModel();
Severity: Minor
Found in modules/Calendar/views/Import.php by phpmd

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

            } else {
                $undoStatus = false;
            }
Severity: Minor
Found in modules/Calendar/views/Import.php by phpmd

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

Call to undeclared method \Vtiger_Viewer::assign
Open

            $viewer->assign('VIEW', 'List');
Severity: Critical
Found in modules/Calendar/views/Import.php by phan

Call to undeclared method \Vtiger_Viewer::assign
Open

            $viewer->assign('UNDO_STATUS', $undoStatus);
Severity: Critical
Found in modules/Calendar/views/Import.php by phan

Call to undeclared method \Vtiger_Viewer::assign
Open

            $viewer->assign('SUCCESS_EVENTS', $result['events']);
Severity: Critical
Found in modules/Calendar/views/Import.php by phan

Call to undeclared method \Vtiger_Viewer::assign
Open

            $viewer->assign('SUCCESS_TASKS', $result['task']);
Severity: Critical
Found in modules/Calendar/views/Import.php by phan

Call to undeclared method \Vtiger_Viewer::assign
Open

            $viewer->assign('MODULE_NAME', $moduleName);
Severity: Critical
Found in modules/Calendar/views/Import.php by phan

Call to undeclared method \Vtiger_Module_Model::importICS
Open

            $result = $moduleModel->importICS(Import_Utils_Helper::getImportFilePath(\App\User::getCurrentUserModel()));
Severity: Critical
Found in modules/Calendar/views/Import.php by phan

Call to undeclared method \Vtiger_Viewer::assign
Open

            $viewer->assign('ERROR_MESSAGE', $request->getByType('error_message', 'Text'));
Severity: Critical
Found in modules/Calendar/views/Import.php by phan

Call to undeclared method \Vtiger_Viewer::assign
Open

            $viewer->assign('SKIPPED_EVENTS', $result['skipped_events']);
Severity: Critical
Found in modules/Calendar/views/Import.php by phan

Call to undeclared method \Vtiger_Viewer::assign
Open

        $viewer->assign('MODULE_MODEL', $moduleModel);
Severity: Critical
Found in modules/Calendar/views/Import.php by phan

Call to undeclared method \Vtiger_Viewer::assign
Open

            $viewer->assign('SKIPPED_TASKS', $result['skipped_task']);
Severity: Critical
Found in modules/Calendar/views/Import.php by phan

Call to method getCurrentUserModel from undeclared class \App\User (Did you mean class \Tests\App\User)
Open

            $result = $moduleModel->importICS(Import_Utils_Helper::getImportFilePath(\App\User::getCurrentUserModel()));
Severity: Critical
Found in modules/Calendar/views/Import.php by phan

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

class Calendar_Import_View extends Vtiger_Import_View

A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 15 and the first side effect is on line 13.
Open

<?php

The class Calendar_Import_View is not named in CamelCase.
Open

class Calendar_Import_View extends Vtiger_Import_View
{
    use \App\Controller\ExposeMethod;

    /**
Severity: Minor
Found in modules/Calendar/views/Import.php by phpmd

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

    use \App\Controller\ExposeMethod;

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

            $this->importResult($request);

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

        if (Import_Utils_Helper::validateFileUpload($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

        parent::process($request);

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

     * Calendar_Import_View constructor.

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

        $moduleName = $request->getModule();

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

            if (!empty($returnValue)) {

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

        }

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

            $viewer->assign('SUCCESS_TASKS', $result['task']);

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

        $viewer->view('ImportResult.tpl', $moduleName);

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

            $lastImport = new ICalLastImport();

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

                $undoStatus = true;

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

            $viewer->view('ImportFinalResult.tpl', $moduleName);

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

        } else {

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

            $viewer->assign('ERROR_MESSAGE', $request->getByType('error_message', 'Text'));

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->exposeMethod('importResult');

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

            $viewer->assign('SUCCESS_EVENTS', $result['events']);

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

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

    {

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

            $viewer->assign('SKIPPED_EVENTS', $result['skipped_events']);

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

        if ($request->has('type') && 'ics' === $request->getByType('type', 'Text')) {

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

            $viewer->assign('VIEW', 'List');

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

    public function __construct()

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

        if ('ics' === $type || 'ical' === $type) {

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

     * @throws \Exception

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

        $moduleModel = Vtiger_Module_Model::getInstance($moduleName);

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

        $viewer->assign('MODULE_MODEL', $moduleModel);

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 = $this->getViewer($request);

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

     * Function to show result of import.

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

     * @param \App\Request $request

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

            parent::undoImport($request);

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

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

            }

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->set('type', 'ics');

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

     */

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

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

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

            $currentUserModel = Users_Record_Model::getCurrentUserModel();

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

                $undoStatus = false;

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

        $this->exposeMethod('undoImport');

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

            parent::uploadAndParse($request);

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

    public function importResult(App\Request $request)

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

            $viewer->assign('SKIPPED_TASKS', $result['skipped_task']);

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

            } else {

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

            $viewer->assign('UNDO_STATUS', $undoStatus);

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

        $this->exposeMethod('import');

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

     *

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

            $result = $moduleModel->importICS(Import_Utils_Helper::getImportFilePath(\App\User::getCurrentUserModel()));

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

            $moduleName = $request->getModule();

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

            $viewer->assign('MODULE_NAME', $moduleName);

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

        }

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

        parent::__construct();

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

    {

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

            $returnValue = $lastImport->undo($moduleName, $currentUserModel->getId());

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

    }

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

class Calendar_Import_View extends Vtiger_Import_View

There are no issues that match your filters.

Category
Status