YetiForceCompany/YetiForceCRM

View on GitHub
modules/Calendar/models/Field.php

Summary

Maintainability
A
1 hr
Test Coverage
F
36%

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')) {
Severity: Minor
Found in modules/Calendar/models/Field.php - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method getDisplayValue has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function getDisplayValue($value, $record = false, $recordModel = false, $rawText = false, $length = false)
Severity: Minor
Found in modules/Calendar/models/Field.php - About 35 mins to fix

    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)
    Severity: Minor
    Found in modules/Calendar/models/Field.php by phpmd

    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)
    Severity: Minor
    Found in modules/Calendar/models/Field.php by phpmd

    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)
    Severity: Minor
    Found in modules/Calendar/models/Field.php by phpmd

    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)
    Severity: Minor
    Found in modules/Calendar/models/Field.php by phpmd

    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)
    Severity: Minor
    Found in modules/Calendar/models/Field.php by phpmd

    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();
            }
    Severity: Minor
    Found in modules/Calendar/models/Field.php by phpmd

    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'));
    Severity: Minor
    Found in modules/Calendar/models/Field.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid using static access to class '\App\Request' in method 'getFieldInfo'.
    Open

                $searchParams = App\Condition::validSearchParams('Calendar', \App\Request::_getArray('search_params'));
    Severity: Minor
    Found in modules/Calendar/models/Field.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid using static access to class 'DateTimeField' in method 'getEditViewDisplayValue'.
    Open

                    return DateTimeField::convertToUserFormat(date('Y-m-d', strtotime("+$minutes minutes")));
    Severity: Minor
    Found in modules/Calendar/models/Field.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid using static access to class '\App\User' in method 'getEditViewDisplayValue'.
    Open

                    $userModel = \App\User::getCurrentUserModel();
    Severity: Minor
    Found in modules/Calendar/models/Field.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid using static access to class 'DateTimeField' in method 'getEditViewDisplayValue'.
    Open

                    return DateTimeField::convertToUserFormat(date('Y-m-d'));
    Severity: Minor
    Found in modules/Calendar/models/Field.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid using static access to class 'App\Condition' in method 'getFieldInfo'.
    Open

                $searchParams = App\Condition::validSearchParams('Calendar', \App\Request::_getArray('search_params'));
    Severity: Minor
    Found in modules/Calendar/models/Field.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Define a constant instead of duplicating this literal "due_date" 4 times.
    Open

            if ('due_date' === $this->getName()) {
    Severity: Critical
    Found in modules/Calendar/models/Field.php by sonar-php

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Define a constant instead of duplicating this literal "date_start" 6 times.
    Open

                    'params' => ['date_start'], ];
    Severity: Critical
    Found in modules/Calendar/models/Field.php by sonar-php

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Call to method getCurrentUserModel from undeclared class \App\User (Did you mean class \Tests\App\User)
    Open

                    $userModel = \App\User::getCurrentUserModel();
    Severity: Critical
    Found in modules/Calendar/models/Field.php by phan

    Saw unextractable annotation for comment '* @return <array>'</array>
    Open

         * @return <Array>
    Severity: Info
    Found in modules/Calendar/models/Field.php by phan

    Call to deprecated function \Calendar_Field_Model::getFieldName() defined at /code/modules/Vtiger/models/Field.php:203
    Open

            if ('visibility' == $this->getFieldName()) {
    Severity: Minor
    Found in modules/Calendar/models/Field.php by phan

    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

    The class Calendar_Field_Model is not named in CamelCase.
    Open

    class Calendar_Field_Model extends Vtiger_Field_Model
    {
        /** {@inheritdoc} */
        public function getValidator()
        {
    Severity: Minor
    Found in modules/Calendar/models/Field.php by phpmd

    CamelCaseClassName

    Since: 0.2

    It is considered best practice to use the CamelCase notation to name classes.

    Example

    class class_name {
    }

    Source

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

            }

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

            }

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

            }

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

        public function getDisplayValue($value, $record = false, $recordModel = false, $rawText = false, $length = false)

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

            if (empty($value)) {

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

                return 'reminder';

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

        /** {@inheritdoc} */

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

                if ('date_start' === $fieldName) {

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

                    return DateTimeField::convertToUserFormat(date('Y-m-d', strtotime("+$minutes minutes")));

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

            return parent::getEditViewDisplayValue($value, $recordModel);

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

         *

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

            if ('visibility' == $this->getFieldName()) {

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

                        if ('date_start' == $value[0]) {

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

        }

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

                return 'datetime';

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

            if (30 === $this->getUIType()) {

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

                    $minutes = $typeByDuration[$defaultType] ?? 0;

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

            return $filterOpsByFieldType;

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

         * Function which will check if empty piclist option should be given.

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

                return false;

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

            }

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

            return true;

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

        public function getValidator()

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

        }

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

        /** {@inheritdoc} */

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

                    $value = $value . ' ' . $recordModel->get('time_start');

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

                    $userModel = \App\User::getCurrentUserModel();

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

                    $typeByDuration = \App\Json::decode($userModel->getDetail('othereventduration'));

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

        /**

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

         */

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

            if ('date_start' == $this->get('name')) {

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

            }

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

        /** {@inheritdoc} */

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

        public function getFieldDataType()

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

        }

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

                }

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

            }

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

        }

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

                if (!empty($searchParams)) {

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

            $validator = [];

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

                $validator = parent::getValidator();

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

        public static function getAdvancedFilterOpsByFieldType()

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

        }

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

                }

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

        /**

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

         * Function to get the advanced filter option names by Field type.

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

         * @return <Array>

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

        public function isEmptyPicklistOptionAllowed()

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

                $funcName = ['name' => 'greaterThanDependentField',

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

                $validator[] = $funcName;

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

            }

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

            return parent::getDisplayValue($value, $record, $recordModel, $rawText, $length);

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

        public function getEditViewDisplayValue($value, $recordModel = false)

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

            $filterOpsByFieldType = parent::getAdvancedFilterOpsByFieldType();

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

        {

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

         */

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

        public function getFieldInfo(): array

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

                            $this->fieldInfo['searchOperator'] = $value[1];

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

            if ('due_date' === $this->getName()) {

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

            if ($recordModel) {

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

                if ('date_start' === $this->getName()) {

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

                $searchParams = App\Condition::validSearchParams('Calendar', \App\Request::_getArray('search_params'));

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

        {

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

            return parent::getFieldDataType();

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

                }

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

                    $defaultType = $userModel->getDetail('defaultactivitytype');

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

            return $validator;

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

        {

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

                    return DateTimeField::convertToUserFormat(date('Y-m-d'));

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

        {

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

                }

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

                $fieldName = $this->getName();

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

        /** {@inheritdoc} */

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

            //Change the default search operator

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

                    'params' => ['date_start'], ];

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

            } else {

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

        }

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

        {

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

                } elseif ('due_date' === $this->getName()) {

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

                    $value = $value . ' ' . $recordModel->get('time_end');

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

                if ('due_date' === $fieldName) {

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

            $this->loadFieldInfo();

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

            return $this->fieldInfo;

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

            if ('date_start' == $this->getName() || 'due_date' == $this->getName()) {

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

        /** {@inheritdoc} */

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

                    $typeByDuration = array_column($typeByDuration, 'duration', 'activitytype');

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

        }

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

        {

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

            $filterOpsByFieldType['O'] = ['e', 'n'];

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

        {

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

                    foreach ($searchParams[0] as $value) {

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

                        }

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

                    }

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

    class Calendar_Field_Model extends Vtiger_Field_Model

    There are no issues that match your filters.

    Category
    Status