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')) {
- Read upRead up
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);
- Read upRead up
- Exclude checks
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'))) {
- Read upRead up
- Exclude checks
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();
- Exclude checks
@throws type of saveRecord
has undeclared type \yii\db\Exception
(Did you mean class \Exception) Open
public function saveRecord(App\Request $request)
- Exclude checks
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
- Exclude checks
The class Calendar_Save_Action is not named in CamelCase. Open
class Calendar_Save_Action extends Vtiger_Save_Action
{
/**
* Function to save record.
*
- Read upRead up
- Exclude checks
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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function saveRecord(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data['followup'] = $this->record->getId();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected function getRecordModelFromRequest(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
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')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \App\Request $request Values of the record
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($request->getBoolean('reapeat')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif (empty($data['followup'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
parent::getRecordModelFromRequest($request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recurringEvents = Calendar_RecuringEvents_Model::getInstanceFromRequest($request);
- Exclude checks
Line exceeds 120 characters; contains 138 characters Open
if (!$request->isEmpty('typeSaving') && Calendar_RecuringEvents_Model::UPDATE_THIS_EVENT === $request->getInteger('typeSaving')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recurringEvents->setChanges($this->record->getPreviousValue());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return Vtiger_Record_Model or Module specific Record Model instance
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->record;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
parent::saveRecord($request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recurringEvents->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get the record model based on the request parameters.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Line exceeds 120 characters; contains 175 characters Open
App\Db::getInstance()->createCommand()->update('vtiger_activity', ['followup' => $this->record->getId()], ['activityid' => $this->record->getId()])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data['followup'] = $this->record->getId();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recurringEvents->setData($data);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data = $this->record->getData();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->record->set('recurrence', $this->record->getPreviousValue('recurrence'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to save record.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @throws \yii\db\Exception
- Exclude checks
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();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($request->isEmpty('record') || (!$this->record->isNew() && $this->record->isEmpty('followup'))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \App\Request $request
- Exclude checks
Class name "Calendar_Save_Action" is not in camel caps format Open
class Calendar_Save_Action extends Vtiger_Save_Action
- Exclude checks