YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
2 hrs
Test Coverage
F
0%

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

    public function process(App\Request $request)
    {
        $dates = [];
        $moduleName = $request->getModule();
        $currentDate = DateTimeField::convertToDBFormat($request->getByType('currentDate', 'DateInUserFormat'));
Severity: Minor
Found in modules/Calendar/views/QuickCreateEvents.php - About 1 hr to fix

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

        public function process(App\Request $request)
        {
            $dates = [];
            $moduleName = $request->getModule();
            $currentDate = DateTimeField::convertToDBFormat($request->getByType('currentDate', 'DateInUserFormat'));
    Severity: Minor
    Found in modules/Calendar/views/QuickCreateEvents.php - About 35 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 '31', column '27').
    Open

                $dateInstance->sub(new DateInterval('P1D'));

    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 '28', column '30').
    Open

            $currentDateInstance = new DateTime($currentDate);

    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 '40', column '27').
    Open

                $dateInstance->add(new DateInterval('P1D'));

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

            $currentDate = DateTimeField::convertToDBFormat($request->getByType('currentDate', 'DateInUserFormat'));

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

            $hideDays = App\Config::module($moduleName, 'HIDDEN_DAYS_IN_CALENDAR_VIEW');

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

            $record = Calendar_Calendar_Model::getCleanInstance();

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

            $record->set('start', \App\Fields\Date::formatToDisplay(reset($dates)) . ' 00:00:00');

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

            $viewer->assign('SHOW_COMPANIES', App\Config::module($moduleName, 'SHOW_COMPANIES_IN_QUICKCREATE'));

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

            $record->set('end', \App\Fields\Date::formatToDisplay(end($dates)) . ' 23:59:59');

    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

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('DATES', $dates);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('SHOW_COMPANIES', App\Config::module($moduleName, 'SHOW_COMPANIES_IN_QUICKCREATE'));

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('EVENTS', $records);

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

    class Calendar_QuickCreateEvents_View extends Vtiger_IndexAjax_View

    The class Calendar_QuickCreateEvents_View is not named in CamelCase.
    Open

    class Calendar_QuickCreateEvents_View extends Vtiger_IndexAjax_View
    {
        /**
         * Main process.
         *

    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

         *

    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('EVENTS', $records);

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

                    --$numberDaysToDisplay;

    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

            $record->set('user', $request->getInteger('user'));

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

            $records = [];

    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

            $dates = [];

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

            $currentDate = DateTimeField::convertToDBFormat($request->getByType('currentDate', 'DateInUserFormat'));

    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

            $hideDays = App\Config::module($moduleName, 'HIDDEN_DAYS_IN_CALENDAR_VIEW');

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

            $dates[$numberDaysToDisplay] = $currentDate;

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

            $dateInstance = clone $currentDateInstance;

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

                if (!\in_array($dateInstance->format('w'), $hideDays)) {

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

            $record->set('start', \App\Fields\Date::formatToDisplay(reset($dates)) . ' 00:00:00');

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

            $events = $record->getEntity();

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

            $record = Calendar_Calendar_Model::getCleanInstance();

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

            $viewer->assign('DATES', $dates);

    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

            $currentDateInstance = new DateTime($currentDate);

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

            while ($numberDaysToDisplay) {

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

                $dateInstance->sub(new DateInterval('P1D'));

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

                if (!\in_array($dateInstance->format('w'), $hideDays)) {

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

            $record->set('time', 'current');

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

            while (6 !== $numberDaysToDisplay) {

    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

        /**

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

         * Main process.

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

            $numberDaysToDisplay = 3;

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

                $dateInstance->add(new DateInterval('P1D'));

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

            }

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

            $record->set('end', \App\Fields\Date::formatToDisplay(end($dates)) . ' 23:59:59');

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

            $viewer->assign('SHOW_COMPANIES', App\Config::module($moduleName, 'SHOW_COMPANIES_IN_QUICKCREATE'));

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

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

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

                    ++$numberDaysToDisplay;

    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 ($events as $event) {

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

                    $dates[$numberDaysToDisplay] = $dateInstance->format('Y-m-d');

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

            ksort($dates);

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

                $records[$event['start_date']][] = $event;

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

            }

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

            $numberDaysToDisplay = 3;

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

            $dateInstance = clone $currentDateInstance;

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

                    $dates[$numberDaysToDisplay] = $dateInstance->format('Y-m-d');

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

    class Calendar_QuickCreateEvents_View extends Vtiger_IndexAjax_View

    There are no issues that match your filters.

    Category
    Status