YetiForceCompany/YetiForceCRM

View on GitHub
modules/Calendar/handlers/CalendarHandler.php

Summary

Maintainability
A
55 mins
Test Coverage
C
72%

Function entityAfterSave has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    public function entityAfterSave(App\EventHandler $eventHandler)
    {
        $ids = [];
        $recordModel = $eventHandler->getRecordModel();
        foreach ($recordModel->getModule()->getFieldsByReference() as $fieldModel) {
Severity: Minor
Found in modules/Calendar/handlers/CalendarHandler.php - About 55 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 '34', column '9').
Open

            (new \App\BatchMethod(['method' => 'Calendar_Record_Model::setCrmActivity', 'params' => [$ids]]))->save();

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 'Calendar_Record_Model' in method 'entityAfterUnLink'.
Open

        Calendar_Record_Model::setCrmActivity([$params['sourceRecordId'] => $fieldName]);

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

    public function entityBeforeSave(App\EventHandler $eventHandler)
    {
        $recordModel = $eventHandler->getRecordModel();
        if ($recordModel->get('allday') && ($recordModel->isNew() || false !== $recordModel->getPreviousValue('allday'))) {
            $userModel = \App\User::getUserModel($recordModel->get('assigned_user_id'));

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

            $userModel = \App\User::getUserModel($recordModel->get('assigned_user_id'));

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 'vtlib\Cron' in method 'entityBeforeSave'.
Open

        if (!vtlib\Cron::isCronAction() && ($state = Calendar_Module_Model::getCalendarState($recordModel->getData()))) {

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\DateTime' in method 'entityBeforeSave'.
Open

        $minutes = \App\Fields\DateTime::getDiff($recordModel->get('date_start') . ' ' . $recordModel->get('time_start'), $recordModel->get('due_date') . ' ' . $recordModel->get('time_end'), 'minutes');

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\ModuleHierarchy' in method 'entityAfterUnLink'.
Open

        $fieldName = \App\ModuleHierarchy::getMappingRelatedField($params['sourceModule']);

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_Module_Model' in method 'entityBeforeSave'.
Open

        if (!vtlib\Cron::isCronAction() && ($state = Calendar_Module_Model::getCalendarState($recordModel->getData()))) {

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 method getUserModel from undeclared class \App\User (Did you mean class \Tests\App\User)
Open

            $userModel = \App\User::getUserModel($recordModel->get('assigned_user_id'));

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

class Calendar_CalendarHandler_Handler

The class Calendar_CalendarHandler_Handler is not named in CamelCase.
Open

class Calendar_CalendarHandler_Handler
{
    /**
     * EntityAfterSave function.
     *

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

     * @param App\EventHandler $eventHandler

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

            if (!$fieldModel->isActiveField()) {

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

                $ids[$recordModel->get($fieldModel->getName())] = $fieldModel->getName();

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

            (new \App\BatchMethod(['method' => 'Calendar_Record_Model::setCrmActivity', 'params' => [$ids]]))->save();

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

        foreach ($recordModel->getModule()->getFieldsByReference() as $fieldModel) {

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

                $ids[$recordModel->getPreviousValue($fieldModel->getName())] = $fieldModel->getName();

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

     * @param App\EventHandler $eventHandler

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

    public function entityAfterUnLink(App\EventHandler $eventHandler)

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

    {

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

        $ids = [];

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

    public function entityChangeState(App\EventHandler $eventHandler)

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

    {

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

            $recordModel->set('time_end', $userModel->getDetail('end_hour') . ':00');

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

        $hours = floor($minutes / 60);

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

        if ($ids) {

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

    }

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

     * @param App\EventHandler $eventHandler

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

     * EntityAfterUnLink handler function.

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

     *

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

     * @param App\EventHandler $eventHandler

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

        if (!vtlib\Cron::isCronAction() && ($state = Calendar_Module_Model::getCalendarState($recordModel->getData()))) {

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

        $recordModel = $eventHandler->getRecordModel();

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

     * EntityBeforeSave handler function.

Line exceeds 120 characters; contains 121 characters
Open

        if (!vtlib\Cron::isCronAction() && ($state = Calendar_Module_Model::getCalendarState($recordModel->getData()))) {

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

    public function entityAfterSave(App\EventHandler $eventHandler)

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

            if (!$recordModel->isEmpty($fieldModel->getName())) {

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

    public function entityBeforeSave(App\EventHandler $eventHandler)

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

            $userModel = \App\User::getUserModel($recordModel->get('assigned_user_id'));

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

        $this->entityAfterSave($eventHandler);

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

            $recordModel->set('time_start', $userModel->getDetail('start_hour') . ':00');

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

            }

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

            }

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

     * EntityChangeState handler function.

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

            $recordModel->set('activitystatus', $state);

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

     */

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

    /**

Line exceeds 120 characters; contains 123 characters
Open

        if ($recordModel->get('allday') && ($recordModel->isNew() || false !== $recordModel->getPreviousValue('allday'))) {

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

        $minutes = \App\Fields\DateTime::getDiff($recordModel->get('date_start') . ' ' . $recordModel->get('time_start'), $recordModel->get('due_date') . ' ' . $recordModel->get('time_end'), 'minutes');

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

        $recordModel->set('duration_minutes', $minutes - ($hours * 60));

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

     * EntityAfterSave function.

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

                continue;

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

        $params = $eventHandler->getParams();

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

        $fieldName = \App\ModuleHierarchy::getMappingRelatedField($params['sourceModule']);

Line exceeds 120 characters; contains 202 characters
Open

        $minutes = \App\Fields\DateTime::getDiff($recordModel->get('date_start') . ' ' . $recordModel->get('time_start'), $recordModel->get('due_date') . ' ' . $recordModel->get('time_end'), 'minutes');

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

     *

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 ($recordModel->get('allday') && ($recordModel->isNew() || false !== $recordModel->getPreviousValue('allday'))) {

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 ($recordModel->getPreviousValue($fieldModel->getName())) {

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

        Calendar_Record_Model::setCrmActivity([$params['sourceRecordId'] => $fieldName]);

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

        $recordModel->set('duration_hours', $hours);

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

    }

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

        $recordModel = $eventHandler->getRecordModel();

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

class Calendar_CalendarHandler_Handler

There are no issues that match your filters.

Category
Status