Function save
has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring. Open
public function save()
{
if (!$this->isNew) {
switch ($this->typeSaving) {
case self::UPDATE_ALL_EVENTS:
- 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
The class Calendar_RecuringEvents_Model has an overall complexity of 55 which is very high. The configured complexity threshold is 50. Open
class Calendar_RecuringEvents_Model extends \App\Base
{
public $recordModel;
public $typeSaving;
public $isNew;
- Exclude checks
Function delete
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
public function delete()
{
switch ($this->typeSaving) {
case self::UPDATE_ALL_EVENTS:
$records = $this->getRecords($this->recordModel->get('followup'));
- 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 save
has 73 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function save()
{
if (!$this->isNew) {
switch ($this->typeSaving) {
case self::UPDATE_ALL_EVENTS:
File RecuringEvents.php
has 253 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Recurring Events Class.
*
Method delete
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function delete()
{
switch ($this->typeSaving) {
case self::UPDATE_ALL_EVENTS:
$records = $this->getRecords($this->recordModel->get('followup'));
Function getDates
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getDates($startDateTime, $endDateTime, $recurrenceRule = false)
{
if (!$recurrenceRule) {
$recurrenceRule = $this->recordModel->get('recurrence');
}
- 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
The method delete() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. Open
public function delete()
{
switch ($this->typeSaving) {
case self::UPDATE_ALL_EVENTS:
$records = $this->getRecords($this->recordModel->get('followup'));
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method save() has a Cyclomatic Complexity of 17. The configured cyclomatic complexity threshold is 10. Open
public function save()
{
if (!$this->isNew) {
switch ($this->typeSaving) {
case self::UPDATE_ALL_EVENTS:
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Refactor this function to reduce its Cognitive Complexity from 50 to the 15 allowed. Open
public function save()
- 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
Refactor this function to reduce its Cognitive Complexity from 24 to the 15 allowed. Open
public function delete()
- 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 '307', column '15'). Open
$rule = new \Recurr\Rule($recurrenceRule, new \DateTime($startDateTime), new \DateTime($endDateTime));
- 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 '349', column '15'). Open
return (new App\Db\Query())->from('vtiger_activity')
- 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 '124', column '16'). Open
$rule = new \Recurr\Rule($record->get('recurrence'));
- 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 '307', column '80'). Open
$rule = new \Recurr\Rule($recurrenceRule, new \DateTime($startDateTime), new \DateTime($endDateTime));
- 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 '308', column '16'). Open
$data = (new \Recurr\Transformer\ArrayTransformer())->transform($rule);
- 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 '125', column '24'). Open
$rule->setUntil(new \DateTime($dateStart));
- 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 getDates has a boolean flag argument $recurrenceRule, which is a certain sign of a Single Responsibility Principle violation. Open
public function getDates($startDateTime, $endDateTime, $recurrenceRule = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Missing class import via use statement (line '333', column '15'). Open
return (new App\Db\Query())->from('vtiger_activity')
- 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 '307', column '49'). Open
$rule = new \Recurr\Rule($recurrenceRule, new \DateTime($startDateTime), new \DateTime($endDateTime));
- 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
Avoid using static access to class 'Vtiger_Record_Model' in method 'updateNeverEndingEvents'. Open
$record = Vtiger_Record_Model::getInstanceById($recordId);
- 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
Avoid using static access to class 'Vtiger_Record_Model' in method 'updateOmmitedRecords'. Open
$record = Vtiger_Record_Model::getInstanceById($recordId);
- 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
Avoid using static access to class 'Vtiger_Record_Model' in method 'getInstanceFromRequest'. Open
$instance->recordModel = Vtiger_Record_Model::getCleanInstance($moduleName);
- 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
Avoid using static access to class 'Vtiger_Record_Model' in method 'updateRecord'. Open
$record = Vtiger_Record_Model::getInstanceById($recordId);
- 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
Avoid using static access to class 'Vtiger_Record_Model' in method 'updateNeverEndingEvents'. Open
$cleanInstance = Vtiger_Record_Model::getCleanInstance($record->getModuleName());
- 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 save uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$dates = $this->getDates($this->recordModel->get('date_start') . ' ' . $this->recordModel->get('time_start'), $this->recordModel->get('due_date') . ' ' . $this->recordModel->get('time_end'));
unset($dates[0]);
if ($dates) {
$this->createRecords($dates);
- 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
The method save uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
Vtiger_Record_Model::getInstanceById($recordId)->delete();
}
- 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
The method save uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
Vtiger_Record_Model::getInstanceById($recordId)->delete();
}
- 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
Define a constant instead of duplicating this literal "due_date" 7 times. Open
$dates = $this->getDates($records['date_start'] . ' ' . $records['time_start'], $records['due_date'] . ' ' . $records['time_end']);
- 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.
Define a constant instead of duplicating this literal "endDate" 3 times. Open
$record->set('due_date', $date['endDate']);
- 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.
Define a constant instead of duplicating this literal "time_start" 7 times. Open
$dates = $this->getDates($records['date_start'] . ' ' . $records['time_start'], $records['due_date'] . ' ' . $records['time_end']);
- 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.
Define a constant instead of duplicating this literal "time_end" 7 times. Open
$dates = $this->getDates($records['date_start'] . ' ' . $records['time_start'], $records['due_date'] . ' ' . $records['time_end']);
- 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.
Define a constant instead of duplicating this literal "startTime" 3 times. Open
$record->set('time_start', $date['startTime']);
- 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.
Define a constant instead of duplicating this literal "startDate" 4 times. Open
if ($endingDate > $date['startDate']) {
- 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.
Define a constant instead of duplicating this literal "date_start" 17 times. Open
$dates = $this->getDates($records['date_start'] . ' ' . $records['time_start'], $records['due_date'] . ' ' . $records['time_end']);
- 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.
Define a constant instead of duplicating this literal "recurrence" 6 times. Open
$rule = new \Recurr\Rule($record->get('recurrence'));
- 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.
Define a constant instead of duplicating this literal "Y-m-d" 7 times. Open
$endingDate = date('Y-m-d', strtotime(date('Y-m-d') . ' +1 year'));
- 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.
Define a constant instead of duplicating this literal "vtiger_activity" 3 times. Open
App\Db::getInstance()->createCommand()->update('vtiger_activity', ['followup' => $recordId, 'reapeat' => 1], ['followup' => $this->templateRecordId])->execute();
- 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.
Define a constant instead of duplicating this literal "followup" 12 times. Open
$recordsIds = $this->getRecords($this->recordModel->get('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.
Define a constant instead of duplicating this literal "endTime" 3 times. Open
$record->set('time_end', $date['endTime']);
- 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.
Define a constant instead of duplicating this literal "reapeat" 3 times. Open
App\Db::getInstance()->createCommand()->update('vtiger_activity', ['followup' => $recordId, 'reapeat' => 1], ['followup' => $this->templateRecordId])->execute();
- 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.
Avoid unused local variables such as '$value'. Open
foreach ($this->changes as $fieldName => $value) {
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Method \Calendar_RecuringEvents_Model::setData
is declared to return \App\Base|\Calendar_RecuringEvents_Model|static
but has no return value Open
public function setData($values)
- Exclude checks
Parameter $records
has undeclared type \type
Open
public function updateOmmitedRecords($records, $dateStart)
- Exclude checks
Suspicious array access to \type
Open
$this->changes['followup'] = $recordId;
- Exclude checks
Parameter $dateStart
has undeclared type \type
Open
public function updateOmmitedRecords($records, $dateStart)
- Exclude checks
Argument 1 (state)
is 'Trash'
but \Vtiger_Record_Model::changeState()
takes \type
defined at /code/modules/Vtiger/models/Record.php:1784
Open
Vtiger_Record_Model::getInstanceById($recordId)->changeState('Trash');
- Exclude checks
Argument 1 (state)
is 'Trash'
but \Vtiger_Record_Model::changeState()
takes \type
defined at /code/modules/Vtiger/models/Record.php:1784
Open
Vtiger_Record_Model::getInstanceById($recordId)->changeState('Trash');
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
return (new App\Db\Query())->from('vtiger_activity')
- Exclude checks
Parameter $values
has undeclared type \type
Open
public function setChanges($values)
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
App\Db::getInstance()->createCommand()->update('vtiger_activity', ['followup' => $recordId, 'reapeat' => 1], ['followup' => $this->templateRecordId])->execute();
- Exclude checks
Argument 1 (time)
is \type
but \DateTime::__construct()
takes ?string
Open
$rule->setUntil(new \DateTime($dateStart));
- Exclude checks
Call to method setUntil
from undeclared class \Recurr\Rule
Open
$rule->setUntil(new \DateTime($dateStart));
- Exclude checks
Argument 1 (haystack)
is \type
but \strpos()
takes string
Open
return false === strpos($recurrenceRule, 'COUNT') && false === strpos($recurrenceRule, 'UNTIL');
- Exclude checks
Call to method __construct
from undeclared class \Recurr\Rule
Open
$rule = new \Recurr\Rule($recurrenceRule, new \DateTime($startDateTime), new \DateTime($endDateTime));
- Exclude checks
Call to method __construct
from undeclared class \Recurr\Rule
Open
$rule = new \Recurr\Rule($record->get('recurrence'));
- Exclude checks
Default value for string
$recurrenceRule
can't be false
Open
public function getDates($startDateTime, $endDateTime, $recurrenceRule = false)
- Exclude checks
Call to method getString
from undeclared class \Recurr\Rule
Open
$record->set('recurrence', $rule->getString());
- Exclude checks
Returning type bool
but isNeverEndingRule()
is declared to return \type
Open
return false === strpos($recurrenceRule, 'COUNT') && false === strpos($recurrenceRule, 'UNTIL');
- Exclude checks
Call to method __construct
from undeclared class \Recurr\Transformer\ArrayTransformer
Open
$data = (new \Recurr\Transformer\ArrayTransformer())->transform($rule);
- Exclude checks
Parameter $recurrenceRule
has undeclared type \type
Open
public function isNeverEndingRule($recurrenceRule)
- Exclude checks
Argument 1 (records)
is array{}
but \Calendar_RecuringEvents_Model::updateOmmitedRecords()
takes \type
defined at /code/modules/Calendar/models/RecuringEvents.php:120
Open
$this->updateOmmitedRecords($omittedRecords, $data['date_start']);
- Exclude checks
Return type of isNeverEndingRule()
is undeclared type \type
Open
public function isNeverEndingRule($recurrenceRule)
- Exclude checks
Argument 1 (records)
is array{}
but \Calendar_RecuringEvents_Model::updateOmmitedRecords()
takes \type
defined at /code/modules/Calendar/models/RecuringEvents.php:120
Open
$this->updateOmmitedRecords($omittedRecords, $data['date_start']);
- Exclude checks
Call to method transform
from undeclared class \Recurr\Transformer\ArrayTransformer
Open
$data = (new \Recurr\Transformer\ArrayTransformer())->transform($rule);
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
return (new App\Db\Query())->from('vtiger_activity')
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Calendar_RecuringEvents_Model extends \App\Base
- Exclude checks
Avoid variables with short names like $id. Configured minimum length is 3. Open
public function getRecords($id)
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $id. Configured minimum length is 3. Open
public function getLastRecord($id)
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The class Calendar_RecuringEvents_Model is not named in CamelCase. Open
class Calendar_RecuringEvents_Model extends \App\Base
{
public $recordModel;
public $typeSaving;
public $isNew;
- 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 static function getInstance()
- 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
$record = Vtiger_Record_Model::getInstanceById($recordId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dates = $this->getDates($records['date_start'] . ' ' . $records['time_start'], $records['due_date'] . ' ' . $records['time_end']);
- 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
/**
- 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
public $isNew;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$cleanInstance = Vtiger_Record_Model::getCleanInstance($record->getModuleName());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getInstanceFromRequest(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$instance->isNew) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instance->typeSaving = self::UPDATE_THIS_EVENT;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to set data to record model.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $typeSaving;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $templateRecordId;
- 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
return $instance;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
const UPDATE_FUTURE_EVENTS = 3;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to create new records in never ending events. Function uses only by cron.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$cleanInstance->setData($record->getData());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instance->recordModel = Vtiger_Record_Model::getCleanInstance($moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return new self();
- 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
foreach ($dates as $date) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($endingDate > $date['startDate']) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get instance of class.
- 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 $changes;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Line exceeds 120 characters; contains 139 characters Open
$dates = $this->getDates($records['date_start'] . ' ' . $records['time_start'], $records['due_date'] . ' ' . $records['time_end']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->createRecords([$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
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instance = new self();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instance->typeSaving = $request->getInteger('typeSaving');
- 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 (!$this->isNew) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$itemNumber = 0;
- Exclude checks
Line exceeds 120 characters; contains 130 characters Open
if (!($this->recordModel->getPreviousValue('recurrence') === $this->recordModel->get('recurrence'))) {
- Exclude checks
Line exceeds 120 characters; contains 203 characters Open
$dates = $this->getDates($this->recordModel->get('date_start') . ' ' . $this->recordModel->get('time_start'), $this->recordModel->get('due_date') . ' ' . $this->recordModel->get('time_end'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $recordModel;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
const UPDATE_THIS_EVENT = 2;
- 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
unset($dates[0]);
- 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 setChanges($values)
- 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 updateRecord($recordId, $dates)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dates = [];
- 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
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$omittedRecords = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($skip && $data['date_start'] >= $this->recordModel->get('date_start')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$itemNumber = 0;
- 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
unset($dates[0]);
- 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
$record->set('time_start', $dates['startTime']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('due_date', $dates['endDate']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset($dates[$itemNumber])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Vtiger_Record_Model::getInstanceById($recordId)->delete();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case self::UPDATE_FUTURE_EVENTS:
- 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
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($recordsIds as $recordId => $data) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get dates.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $endDateTime
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$rule = new \Recurr\Rule($recurrenceRule, new \DateTime($startDateTime), new \DateTime($endDateTime));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->orderBy(['date_start' => SORT_DESC])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get empty instance.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$endingDate = date('Y-m-d', strtotime(date('Y-m-d') . ' +1 year'));
- 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
$moduleName = $request->getModule();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instance->templateRecordId = $request->getInteger('record');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($instance->typeSaving)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('date_start', $date['startDate']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('time_start', $date['startTime']);
- 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
* @param type $dateStart
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordsIds = $this->getRecords($this->recordModel->get('followup'));
- Exclude checks
Line exceeds 120 characters; contains 147 characters Open
$dates = $this->getDates($data['date_start'] . ' ' . $data['time_start'], $data['due_date'] . ' ' . $data['time_end']);
- 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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordsIds = $this->getRecords($this->recordModel->get('followup'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$skip = true;
- 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 ($this->templateRecordId === $this->recordModel->get('followup')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Check if recurrence rule is never ending.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param type $recurrenceRule
- 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 false === strpos($recurrenceRule, 'COUNT') && false === strpos($recurrenceRule, 'UNTIL');
- 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 array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getLastRecord($id)
- 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 (new App\Db\Query())->from('vtiger_activity')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['followup' => $id, 'deleted' => 0, 'reapeat' => 1])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
const UPDATE_ALL_EVENTS = 1;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function updateNeverEndingEvents($recordId)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->recordModel = $cleanInstance;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$records = $this->getLastRecord($recordId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \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
$instance->isNew = $request->isEmpty('record');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('time_end', $date['endTime']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param type $records
- 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
$record = Vtiger_Record_Model::getInstanceById($recordId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($dates) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$omittedRecords = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$skip = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 189 characters Open
App\Db::getInstance()->createCommand()->update('vtiger_activity', ['followup' => $recordId, 'reapeat' => 1], ['followup' => $this->templateRecordId])->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
if ($isNeverEnding) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->all();
- 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
* @param int $recordId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return Calendar_RecuringEvents_Model
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->recordModel->setData($values);
- 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
$rule->setUntil(new \DateTime($dateStart));
- 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
++$itemNumber;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->updateRecord($recordId, $dates[$itemNumber]);
- Exclude checks
Line exceeds 120 characters; contains 151 characters Open
$dates = $this->getDates($data['date_start'] . ' ' . $data['time_start'], $data['due_date'] . ' ' . $data['time_end']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($dates[$itemNumber]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->createRecords($dates);
- 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
* Function to remove records.
- 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
$records = $this->getRecords($this->recordModel->get('followup'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function isNeverEndingRule($recurrenceRule)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$recurrenceRule) {
- 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
* Function to create new records.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record = Vtiger_Record_Model::getInstanceById($recordId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dates = reset($recordsIds);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->updateRecord($recordId, $dates[$itemNumber]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($dates[$itemNumber]);
- 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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($recordsIds as $recordId => $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
break;
- 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 getDates($startDateTime, $endDateTime, $recurrenceRule = false)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'endDate' => $date->getEnd()->format('Y-m-d'),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $values
- 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
* Function to set changes which user modified.
- 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
* Function to edit record.
- 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
$record->set($fieldName, $this->recordModel->get($fieldName));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->save();
- 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
$skip = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Vtiger_Record_Model::getInstanceById($recordId)->changeState('Trash');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- 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
->limit(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
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->changes = $values;
- 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
foreach ($this->changes as $fieldName => $value) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('date_start', $dates['startDate']);
- 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
* Save records.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function save()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($recordsIds as $recordId => $data) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (0 === $itemNumber) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($recordId === $this->templateRecordId) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($dates[$itemNumber]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($dates[$itemNumber]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
++$itemNumber;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$itemNumber = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->recordModel->set('followup', $recordId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- 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
$data = (new \Recurr\Transformer\ArrayTransformer())->transform($rule);
- 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
* @param int $id
- 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
* Function to get the last record in series.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function createRecords($dates)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($dates as $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
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!($this->recordModel->getPreviousValue('recurrence') === $this->recordModel->get('recurrence'))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->changes['followup'] = $recordId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset($dates[$itemNumber])) {
- 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 delete()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case self::UPDATE_ALL_EVENTS:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($records as $recordId => $data) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case self::UPDATE_FUTURE_EVENTS:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordsIds = $this->getRecords($this->recordModel->get('followup'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case self::UPDATE_THIS_EVENT:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
App\Db::getInstance()->createCommand()->update('vtiger_activity', ['followup' => $recordId, 'reapeat' => 1], ['followup' => $this->templateRecordId])->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
break;
- 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
->orderBy(['date_start' => SORT_ASC])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->indexBy('activityid')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return Calendar_RecuringEvents_Model
- 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
$dates = $this->getDates($this->recordModel->get('date_start') . ' ' . $this->recordModel->get('time_start'), $this->recordModel->get('due_date') . ' ' . $this->recordModel->get('time_end'));
- 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
->one();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setData($values)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param type $values
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$rule = new \Recurr\Rule($record->get('recurrence'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $recordId
- 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->createRecords($dates);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dates = $this->getDates($data['date_start'] . ' ' . $data['time_start'], $data['due_date'] . ' ' . $data['time_end']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($skip) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
++$itemNumber;
- 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->createRecords($dates);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
default:
- 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
$recordsIds = $this->getRecords($this->recordModel->get('followup'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dates = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'startDate' => $date->getStart()->format('Y-m-d'),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'startTime' => $date->getStart()->format('H:i:s'),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get related records.
- 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 getRecords($id)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('due_date', $date['endDate']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record = clone $this->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
* @param array $dates
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('time_end', $dates['endTime']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Update ommited records, change recuring rule for each records.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch ($this->typeSaving) {
- 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
case self::UPDATE_ALL_EVENTS:
- 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
continue;
- 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
Vtiger_Record_Model::getInstanceById($recordId)->delete();
- Exclude checks
Line exceeds 120 characters; contains 165 characters Open
$dates = $this->getDates($dates['date_start'] . ' ' . $dates['time_start'], $dates['due_date'] . ' ' . $dates['time_end'], $dates['recurrence']);
- 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->updateOmmitedRecords($omittedRecords, $data['date_start']);
- 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 ($skip && $data['date_start'] >= $this->recordModel->get('date_start')) {
- 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
$omittedRecords[] = $recordId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
default:
- 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
$skip = true;
- 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 type
- 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 array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$isNeverEnding = $this->isNeverEndingRule($recurrenceRule);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'endTime' => $date->getEnd()->format('H:i:s'),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$endingDate = date('Y-m-d', strtotime(date('Y-m-d', strtotime($startDateTime)) . ' +1 year'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($isNeverEnding && $date->getStart()->format('Y-m-d') > $endingDate) {
- 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
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $id
- 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
* @param array $dates
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($records as $recordId) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->set('recurrence', $rule->getString());
- 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
$dates = $this->getDates($data['date_start'] . ' ' . $data['time_start'], $data['due_date'] . ' ' . $data['time_end']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($recordsIds as $recordId => $data) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->updateOmmitedRecords($omittedRecords, $data['date_start']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
++$itemNumber;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($dates) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($dates) {
- 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 ($recordId !== $this->templateRecordId) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($data['date_start'] >= $this->recordModel->get('date_start')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($data as $date) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $dates;
- 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
*/
- 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 updateOmmitedRecords($records, $dateStart)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dates = $this->getDates($dates['date_start'] . ' ' . $dates['time_start'], $dates['due_date'] . ' ' . $dates['time_end'], $dates['recurrence']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$omittedRecords[] = $recordId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch ($this->typeSaving) {
- 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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $startDateTime
- 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 (new App\Db\Query())->from('vtiger_activity')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dates[] = [
- 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
->where(['followup' => $id, 'deleted' => 0, 'reapeat' => 1])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->indexBy('activityid')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Vtiger_Record_Model::getInstanceById($recordId)->changeState('Trash');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$skip = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($skip) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $recurrenceRule
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recurrenceRule = $this->recordModel->get('recurrence');
- Exclude checks
Class name "Calendar_RecuringEvents_Model" is not in camel caps format Open
class Calendar_RecuringEvents_Model extends \App\Base
- Exclude checks