Function getFieldInfo
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function getFieldInfo(): array
{
$this->loadFieldInfo();
//Change the default search operator
if ('date_start' == $this->get('name')) {
- 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 getDisplayValue
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function getDisplayValue($value, $record = false, $recordModel = false, $rawText = false, $length = false)
The method getDisplayValue has a boolean flag argument $length, which is a certain sign of a Single Responsibility Principle violation. Open
public function getDisplayValue($value, $record = false, $recordModel = false, $rawText = false, $length = 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
The method getDisplayValue has a boolean flag argument $rawText, which is a certain sign of a Single Responsibility Principle violation. Open
public function getDisplayValue($value, $record = false, $recordModel = false, $rawText = false, $length = 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
The method getEditViewDisplayValue has a boolean flag argument $recordModel, which is a certain sign of a Single Responsibility Principle violation. Open
public function getEditViewDisplayValue($value, $recordModel = 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
The method getDisplayValue has a boolean flag argument $record, which is a certain sign of a Single Responsibility Principle violation. Open
public function getDisplayValue($value, $record = false, $recordModel = false, $rawText = false, $length = 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
The method getDisplayValue has a boolean flag argument $recordModel, which is a certain sign of a Single Responsibility Principle violation. Open
public function getDisplayValue($value, $record = false, $recordModel = false, $rawText = false, $length = 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
The method getValidator uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$validator = parent::getValidator();
}
- 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 '\App\Json' in method 'getEditViewDisplayValue'. Open
$typeByDuration = \App\Json::decode($userModel->getDetail('othereventduration'));
- 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 '\App\Request' in method 'getFieldInfo'. Open
$searchParams = App\Condition::validSearchParams('Calendar', \App\Request::_getArray('search_params'));
- 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 'DateTimeField' in method 'getEditViewDisplayValue'. Open
return DateTimeField::convertToUserFormat(date('Y-m-d', strtotime("+$minutes minutes")));
- 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 '\App\User' in method 'getEditViewDisplayValue'. Open
$userModel = \App\User::getCurrentUserModel();
- 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 'DateTimeField' in method 'getEditViewDisplayValue'. Open
return DateTimeField::convertToUserFormat(date('Y-m-d'));
- 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 'App\Condition' in method 'getFieldInfo'. Open
$searchParams = App\Condition::validSearchParams('Calendar', \App\Request::_getArray('search_params'));
- 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 "due_date" 4 times. Open
if ('due_date' === $this->getName()) {
- 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" 6 times. Open
'params' => ['date_start'], ];
- 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 method getCurrentUserModel
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
$userModel = \App\User::getCurrentUserModel();
- Exclude checks
Saw unextractable annotation for comment '* @return <array>'</array>
Open
* @return <Array>
- Exclude checks
Call to deprecated function \Calendar_Field_Model::getFieldName()
defined at /code/modules/Vtiger/models/Field.php:203
Open
if ('visibility' == $this->getFieldName()) {
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Calendar_Field_Model extends Vtiger_Field_Model
- Exclude checks
The class Calendar_Field_Model is not named in CamelCase. Open
class Calendar_Field_Model extends Vtiger_Field_Model
{
/** {@inheritdoc} */
public function getValidator()
{
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getDisplayValue($value, $record = false, $recordModel = false, $rawText = false, $length = false)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($value)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return 'reminder';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('date_start' === $fieldName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return DateTimeField::convertToUserFormat(date('Y-m-d', strtotime("+$minutes minutes")));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return parent::getEditViewDisplayValue($value, $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
if ('visibility' == $this->getFieldName()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('date_start' == $value[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
return 'datetime';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (30 === $this->getUIType()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$minutes = $typeByDuration[$defaultType] ?? 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $filterOpsByFieldType;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function which will check if empty piclist option should be given.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return false;
- 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 true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getValidator()
- 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
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $value . ' ' . $recordModel->get('time_start');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$userModel = \App\User::getCurrentUserModel();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$typeByDuration = \App\Json::decode($userModel->getDetail('othereventduration'));
- 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 ('date_start' == $this->get('name')) {
- 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
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getFieldDataType()
- 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
if (!empty($searchParams)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$validator = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$validator = parent::getValidator();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getAdvancedFilterOpsByFieldType()
- 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
* Function to get the advanced filter option names by Field type.
- 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 isEmptyPicklistOptionAllowed()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$funcName = ['name' => 'greaterThanDependentField',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$validator[] = $funcName;
- 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 parent::getDisplayValue($value, $record, $recordModel, $rawText, $length);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getEditViewDisplayValue($value, $recordModel = false)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$filterOpsByFieldType = parent::getAdvancedFilterOpsByFieldType();
- 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 getFieldInfo(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->fieldInfo['searchOperator'] = $value[1];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('due_date' === $this->getName()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($recordModel) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('date_start' === $this->getName()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$searchParams = App\Condition::validSearchParams('Calendar', \App\Request::_getArray('search_params'));
- 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 parent::getFieldDataType();
- 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
$defaultType = $userModel->getDetail('defaultactivitytype');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $validator;
- 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 DateTimeField::convertToUserFormat(date('Y-m-d'));
- 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
$fieldName = $this->getName();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
//Change the default search operator
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'params' => ['date_start'], ];
- 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
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ('due_date' === $this->getName()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $value . ' ' . $recordModel->get('time_end');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('due_date' === $fieldName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->loadFieldInfo();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->fieldInfo;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('date_start' == $this->getName() || 'due_date' == $this->getName()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$typeByDuration = array_column($typeByDuration, 'duration', 'activitytype');
- 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
$filterOpsByFieldType['O'] = ['e', 'n'];
- 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 ($searchParams[0] as $value) {
- 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
Class name "Calendar_Field_Model" is not in camel caps format Open
class Calendar_Field_Model extends Vtiger_Field_Model
- Exclude checks