YetiForceCompany/YetiForceCRM

View on GitHub
modules/Calendar/actions/Save.php

Summary

Maintainability
A
25 mins
Test Coverage
F
0%

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

    public function saveRecord(App\Request $request)
    {
        parent::saveRecord($request);
        $data = $this->record->getData();
        if ($request->getBoolean('reapeat')) {
Severity: Minor
Found in modules/Calendar/actions/Save.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

Avoid using static access to class 'Calendar_RecuringEvents_Model' in method 'saveRecord'.
Open

            $recurringEvents = Calendar_RecuringEvents_Model::getInstanceFromRequest($request);
Severity: Minor
Found in modules/Calendar/actions/Save.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

Define a constant instead of duplicating this literal "followup" 5 times.
Open

            if ($request->isEmpty('record') || (!$this->record->isNew() && $this->record->isEmpty('followup'))) {
Severity: Critical
Found in modules/Calendar/actions/Save.php by sonar-php

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 undeclared method \App\Db::createCommand
Open

                App\Db::getInstance()->createCommand()->update('vtiger_activity', ['followup' => $this->record->getId()], ['activityid' => $this->record->getId()])->execute();
Severity: Critical
Found in modules/Calendar/actions/Save.php by phan

@throws type of saveRecord has undeclared type \yii\db\Exception (Did you mean class \Exception)
Open

    public function saveRecord(App\Request $request)
Severity: Minor
Found in modules/Calendar/actions/Save.php by phan

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

class Calendar_Save_Action extends Vtiger_Save_Action

The class Calendar_Save_Action is not named in CamelCase.
Open

class Calendar_Save_Action extends Vtiger_Save_Action
{
    /**
     * Function to save record.
     *
Severity: Minor
Found in modules/Calendar/actions/Save.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

            }

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 saveRecord(App\Request $request)

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

                $data['followup'] = $this->record->getId();

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

     */

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

    protected function getRecordModelFromRequest(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

        if (!$request->isEmpty('typeSaving') && Calendar_RecuringEvents_Model::UPDATE_THIS_EVENT === $request->getInteger('typeSaving')) {

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

     * @param \App\Request $request Values of the record

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

        if ($request->getBoolean('reapeat')) {

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

            } elseif (empty($data['followup'])) {

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::getRecordModelFromRequest($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

            $recurringEvents = Calendar_RecuringEvents_Model::getInstanceFromRequest($request);

Line exceeds 120 characters; contains 138 characters
Open

        if (!$request->isEmpty('typeSaving') && Calendar_RecuringEvents_Model::UPDATE_THIS_EVENT === $request->getInteger('typeSaving')) {

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

            $recurringEvents->setChanges($this->record->getPreviousValue());

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

     * @return Vtiger_Record_Model or Module specific Record Model instance

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

        return $this->record;

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

        parent::saveRecord($request);

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

            $recurringEvents->save();

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

     * Function to get the record model based on the request parameters.

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 175 characters
Open

                App\Db::getInstance()->createCommand()->update('vtiger_activity', ['followup' => $this->record->getId()], ['activityid' => $this->record->getId()])->execute();

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

        }

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

                $data['followup'] = $this->record->getId();

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

            $recurringEvents->setData($data);

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

        $data = $this->record->getData();

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->record->set('recurrence', $this->record->getPreviousValue('recurrence'));

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

     * Function to save record.

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

     * @throws \yii\db\Exception

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

                App\Db::getInstance()->createCommand()->update('vtiger_activity', ['followup' => $this->record->getId()], ['activityid' => $this->record->getId()])->execute();

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

            if ($request->isEmpty('record') || (!$this->record->isNew() && $this->record->isEmpty('followup'))) {

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

     * @param \App\Request $request

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

class Calendar_Save_Action extends Vtiger_Save_Action

There are no issues that match your filters.

Category
Status