Function doTask
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function doTask($recordModel)
{
$entityId = $recordModel->getId();
$delta = $recordModel->getPreviousValue();
- 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
Method doTask
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function doTask($recordModel)
{
$entityId = $recordModel->getId();
$delta = $recordModel->getPreviousValue();
Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed. Open
public function doTask($recordModel)
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Missing class import via use statement (line '45', column '16'). Open
$task = new \ArrayObject(unserialize($row['task']));
- Read upRead up
- Exclude checks
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 '42', column '17'). Open
$query = (new \App\Db\Query())->from('vtiger_activity_update_dates')->innerJoin('com_vtiger_workflowtasks', 'com_vtiger_workflowtasks.task_id = vtiger_activity_update_dates.task_id')->where(['vtiger_activity_update_dates.parent' => $entityId]);
- Read upRead up
- Exclude checks
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
The method doTask uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$baseDateEnd = $recordModel->get($task['datefield_end']);
if ('' === $baseDateEnd) {
$baseDateEnd = date('Y-m-d');
}
- Read upRead up
- Exclude checks
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_Record_Model' in method 'doTask'. Open
$rowRecordModel = Vtiger_Record_Model::getInstanceById($row['activityid'], 'Calendar');
- 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
The method doTask uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$baseDateStart = $recordModel->get($task['datefield_start']);
if ('' === $baseDateStart) {
$baseDateStart = date('Y-m-d');
}
- Read upRead up
- Exclude checks
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 \App\Db\Query::from
Open
$query = (new \App\Db\Query())->from('vtiger_activity_update_dates')->innerJoin('com_vtiger_workflowtasks', 'com_vtiger_workflowtasks.task_id = vtiger_activity_update_dates.task_id')->where(['vtiger_activity_update_dates.parent' => $entityId]);
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class VTUpdateCalendarDates extends VTTask
- Exclude checks
Line exceeds 120 characters; contains 162 characters Open
$date_start = strftime('%Y-%m-%d', $baseDateStart + $task['days_start'] * 24 * 60 * 60 * ('before' == strtolower($task['direction_start']) ? -1 : 1));
- 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
$baseDateEnd = date('Y-m-d H:i:s');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Execute task.
- 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
* @var bool
- 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
while ($row = $dataReader->read()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('' === $baseDateEnd) {
- 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
$date_start = strftime('%Y-%m-%d', $baseDateStart + $task['days_start'] * 24 * 60 * 60 * ('before' == strtolower($task['direction_start']) ? -1 : 1));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entityId = $recordModel->getId();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = $query->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$baseDateStart = date('Y-m-d H:i:s');
- 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
$baseDateStart = date('Y-m-d');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('wfRunTime' === $task['datefield_end']) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$baseDateEnd = $recordModel->get($task['datefield_end']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$baseDateStart = $recordModel->get($task['datefield_start']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$baseDateEnd = strtotime($match[0]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$delta = $recordModel->getPreviousValue();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$baseDateStart = strtotime($match[0]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$rowRecordModel->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$baseDateEnd = date('Y-m-d');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$due_date = strftime('%Y-%m-%d', $baseDateEnd + $task['days_end'] * 24 * 60 * 60 * ('before' == strtolower($task['direction_start']) ? -1 : 1));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$rowRecordModel->set('due_date', $due_date);
- 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 array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function doTask($recordModel)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('' === $baseDateStart) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$rowRecordModel->set('date_start', $date_start);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Execute immediately.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $executeImmediately = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Line exceeds 120 characters; contains 252 characters Open
$query = (new \App\Db\Query())->from('vtiger_activity_update_dates')->innerJoin('com_vtiger_workflowtasks', 'com_vtiger_workflowtasks.task_id = vtiger_activity_update_dates.task_id')->where(['vtiger_activity_update_dates.parent' => $entityId]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$task = new \ArrayObject(unserialize($row['task']));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get field names.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Vtiger_Record_Model $recordModel
- 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;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$rowRecordModel = Vtiger_Record_Model::getInstanceById($row['activityid'], 'Calendar');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getFieldNames()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- 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
preg_match('/\d\d\d\d-\d\d-\d\d/', $baseDateEnd, $match);
- 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
preg_match('/\d\d\d\d-\d\d-\d\d/', $baseDateStart, $match);
- 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
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$delta) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$query = (new \App\Db\Query())->from('vtiger_activity_update_dates')->innerJoin('com_vtiger_workflowtasks', 'com_vtiger_workflowtasks.task_id = vtiger_activity_update_dates.task_id')->where(['vtiger_activity_update_dates.parent' => $entityId]);
- 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
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('wfRunTime' === $task['datefield_start']) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 156 characters Open
$due_date = strftime('%Y-%m-%d', $baseDateEnd + $task['days_end'] * 24 * 60 * 60 * ('before' == strtolower($task['direction_start']) ? -1 : 1));
- Exclude checks
The variable $date_start is not named in camelCase. Open
public function doTask($recordModel)
{
$entityId = $recordModel->getId();
$delta = $recordModel->getPreviousValue();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $due_date is not named in camelCase. Open
public function doTask($recordModel)
{
$entityId = $recordModel->getId();
$delta = $recordModel->getPreviousValue();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $date_start is not named in camelCase. Open
public function doTask($recordModel)
{
$entityId = $recordModel->getId();
$delta = $recordModel->getPreviousValue();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $due_date is not named in camelCase. Open
public function doTask($recordModel)
{
$entityId = $recordModel->getId();
$delta = $recordModel->getPreviousValue();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}