YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
2 hrs
Test Coverage
F
0%

Function getValidator has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function getValidator()
    {
        $validator = [];
        $fieldName = $this->getName();

Severity: Minor
Found in modules/Reservations/models/Field.php - About 25 mins 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

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/Reservations/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

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

                return DateTimeField::convertToUserFormat(date('Y-m-d'));
Severity: Minor
Found in modules/Reservations/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/Reservations/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" 6 times.
Open

            if ('due_date' === $fieldName) {
Severity: Critical
Found in modules/Reservations/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 "time_end" 5 times.
Open

                'params' => ['date_start', 'time_start', 'due_date', 'time_end'], ];
Severity: Critical
Found in modules/Reservations/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

            if ('date_start' === $fieldName) {
Severity: Critical
Found in modules/Reservations/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 "params" 4 times.
Open

                'params' => ['date_start', 'time_start', 'due_date', 'time_end'], ];
Severity: Critical
Found in modules/Reservations/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 "time_start" 5 times.
Open

                'params' => ['date_start', 'time_start', 'due_date', 'time_end'], ];
Severity: Critical
Found in modules/Reservations/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 "dateAndTimeGreaterThanDependentField" 4 times.
Open

            case 'due_date': $funcName = ['name' => 'dateAndTimeGreaterThanDependentField',
Severity: Critical
Found in modules/Reservations/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.

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

     * @return <Array>

Saw possibly unextractable annotation for a fragment of comment '* @param string Data base value': after string, did not see an element name (will guess based on comment order)
Open

     * @param string Data base value

This case's code block is the same as the block for the case on line 51.
Open

            case 'time_end': $funcName = ['name' => 'dateAndTimeGreaterThanDependentField',
                'params' => ['date_start', 'time_start', 'due_date', 'time_end'], ];
                $validator[] = $funcName;
                break;

Having two cases in a switch statement or two branches in an if chain with the same implementation is at best duplicate code, and at worst a coding error. If the same logic is truly needed for both instances, then in an if chain they should be combined, or for a switch, one should fall through to the other.

Noncompliant Code Example

switch ($i) {
  case 1:
    doSomething();
    break;
  case 2:
    doSomethingDifferent();
    break;
  case 3:  // Noncompliant; duplicates case 1's implementation
    doSomething();
    break;
  default:
    doTheRest();
}

if ($a >= 0 && $a < 10) {
  doTheThing();
else if ($a >= 10 && $a < 20) {
  doTheOtherThing();
}
else if ($a >= 20 && $a < 50) {
  doTheThing();  // Noncompliant; duplicates first condition
}
else {
  doTheRest();
}

if ($b == 0) {
  doOneMoreThing();
}
else {
  doOneMoreThing(); // Noncompliant; duplicates then-branch
}

var b = a ? 12 > 4 : 4;  // Noncompliant; always results in the same value

Compliant Solution

switch ($i) {
  case 1:
  case 3:
    doSomething();
    break;
  case 2:
    doSomethingDifferent();
    break;
  default:
    doTheRest();
}

if (($a >= 0 && $a < 10) || ($a >= 20 && $a < 50)) {
  doTheThing();
else if ($a >= 10 && $a < 20) {
  doTheOtherThing();
}
else {
  doTheRest();
}

doOneMoreThing();

b = 4;

or

switch ($i) {
  case 1:
    doSomething();
    break;
  case 2:
    doSomethingDifferent();
    break;
  case 3:
    doThirdThing();
    break;
  default:
    doTheRest();
}

if ($a >= 0 && $a < 10) {
  doTheThing();
else if ($a >= 10 && $a < 20) {
  doTheOtherThing();
}
else if ($a >= 20 && $a < 50) {
  doTheThirdThing();
}
else {
  doTheRest();
}

if ($b == 0) {
  doOneMoreThing();
}
else {
  doTheRest();
}

int b = a ? 12 > 4 : 8;

Exceptions

Blocks in an if chain that contain a single line of code are ignored, as are blocks in a switch statement that contain a single line of code with or without a following break.

This case's code block is the same as the block for the case on line 51.
Open

            case 'time_start': $funcName = ['name' => 'dateAndTimeGreaterThanDependentField',
                'params' => ['date_start', 'time_start', 'due_date', 'time_end'], ];
                $validator[] = $funcName;
                break;

Having two cases in a switch statement or two branches in an if chain with the same implementation is at best duplicate code, and at worst a coding error. If the same logic is truly needed for both instances, then in an if chain they should be combined, or for a switch, one should fall through to the other.

Noncompliant Code Example

switch ($i) {
  case 1:
    doSomething();
    break;
  case 2:
    doSomethingDifferent();
    break;
  case 3:  // Noncompliant; duplicates case 1's implementation
    doSomething();
    break;
  default:
    doTheRest();
}

if ($a >= 0 && $a < 10) {
  doTheThing();
else if ($a >= 10 && $a < 20) {
  doTheOtherThing();
}
else if ($a >= 20 && $a < 50) {
  doTheThing();  // Noncompliant; duplicates first condition
}
else {
  doTheRest();
}

if ($b == 0) {
  doOneMoreThing();
}
else {
  doOneMoreThing(); // Noncompliant; duplicates then-branch
}

var b = a ? 12 > 4 : 4;  // Noncompliant; always results in the same value

Compliant Solution

switch ($i) {
  case 1:
  case 3:
    doSomething();
    break;
  case 2:
    doSomethingDifferent();
    break;
  default:
    doTheRest();
}

if (($a >= 0 && $a < 10) || ($a >= 20 && $a < 50)) {
  doTheThing();
else if ($a >= 10 && $a < 20) {
  doTheOtherThing();
}
else {
  doTheRest();
}

doOneMoreThing();

b = 4;

or

switch ($i) {
  case 1:
    doSomething();
    break;
  case 2:
    doSomethingDifferent();
    break;
  case 3:
    doThirdThing();
    break;
  default:
    doTheRest();
}

if ($a >= 0 && $a < 10) {
  doTheThing();
else if ($a >= 10 && $a < 20) {
  doTheOtherThing();
}
else if ($a >= 20 && $a < 50) {
  doTheThirdThing();
}
else {
  doTheRest();
}

if ($b == 0) {
  doOneMoreThing();
}
else {
  doTheRest();
}

int b = a ? 12 > 4 : 8;

Exceptions

Blocks in an if chain that contain a single line of code are ignored, as are blocks in a switch statement that contain a single line of code with or without a following break.

This case's code block is the same as the block for the case on line 51.
Open

            case 'date_start': $funcName = ['name' => 'dateAndTimeGreaterThanDependentField',
                'params' => ['date_start', 'time_start', 'due_date', 'time_end'], ];
                $validator[] = $funcName;
                break;

Having two cases in a switch statement or two branches in an if chain with the same implementation is at best duplicate code, and at worst a coding error. If the same logic is truly needed for both instances, then in an if chain they should be combined, or for a switch, one should fall through to the other.

Noncompliant Code Example

switch ($i) {
  case 1:
    doSomething();
    break;
  case 2:
    doSomethingDifferent();
    break;
  case 3:  // Noncompliant; duplicates case 1's implementation
    doSomething();
    break;
  default:
    doTheRest();
}

if ($a >= 0 && $a < 10) {
  doTheThing();
else if ($a >= 10 && $a < 20) {
  doTheOtherThing();
}
else if ($a >= 20 && $a < 50) {
  doTheThing();  // Noncompliant; duplicates first condition
}
else {
  doTheRest();
}

if ($b == 0) {
  doOneMoreThing();
}
else {
  doOneMoreThing(); // Noncompliant; duplicates then-branch
}

var b = a ? 12 > 4 : 4;  // Noncompliant; always results in the same value

Compliant Solution

switch ($i) {
  case 1:
  case 3:
    doSomething();
    break;
  case 2:
    doSomethingDifferent();
    break;
  default:
    doTheRest();
}

if (($a >= 0 && $a < 10) || ($a >= 20 && $a < 50)) {
  doTheThing();
else if ($a >= 10 && $a < 20) {
  doTheOtherThing();
}
else {
  doTheRest();
}

doOneMoreThing();

b = 4;

or

switch ($i) {
  case 1:
    doSomething();
    break;
  case 2:
    doSomethingDifferent();
    break;
  case 3:
    doThirdThing();
    break;
  default:
    doTheRest();
}

if ($a >= 0 && $a < 10) {
  doTheThing();
else if ($a >= 10 && $a < 20) {
  doTheOtherThing();
}
else if ($a >= 20 && $a < 50) {
  doTheThirdThing();
}
else {
  doTheRest();
}

if ($b == 0) {
  doOneMoreThing();
}
else {
  doTheRest();
}

int b = a ? 12 > 4 : 8;

Exceptions

Blocks in an if chain that contain a single line of code are ignored, as are blocks in a switch statement that contain a single line of code with or without a following break.

Identical blocks of code found in 2 locations. Consider refactoring.
Open

    public function getEditViewDisplayValue($value, $recordModel = false)
    {
        $fieldName = $this->getName();

        //Set the start date and end date
Severity: Major
Found in modules/Reservations/models/Field.php and 1 other location - About 1 hr to fix
modules/OSSTimeControl/models/Field.php on lines 14..28

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 120.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Each class must be in a namespace of at least one level (a top-level vendor name)
Open

class Reservations_Field_Model extends Vtiger_Field_Model

The class Reservations_Field_Model is not named in CamelCase.
Open

class Reservations_Field_Model extends Vtiger_Field_Model
{
    /**
     * Function to get Edit view display value.
     *
Severity: Minor
Found in modules/Reservations/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

The CASE body must start on the line following the statement
Open

            case 'time_start': $funcName = ['name' => 'dateAndTimeGreaterThanDependentField',

The CASE body must start on the line following the statement
Open

            case 'date_start': $funcName = ['name' => 'dateAndTimeGreaterThanDependentField',

The CASE body must start on the line following the statement
Open

            case 'due_date': $funcName = ['name' => 'dateAndTimeGreaterThanDependentField',

The DEFAULT body must start on the line following the statement
Open

            default: $validator = parent::getValidator();

The CASE body must start on the line following the statement
Open

            case 'time_end': $funcName = ['name' => 'dateAndTimeGreaterThanDependentField',

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::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

            }

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

     */

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

        switch ($fieldName) {

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

            case 'date_start': $funcName = ['name' => 'dateAndTimeGreaterThanDependentField',

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

                break;

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

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

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

    }

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

            case 'time_start': $funcName = ['name' => 'dateAndTimeGreaterThanDependentField',

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

     * @return string value

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

                break;

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 getValidator()

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

                'params' => ['date_start', 'time_start', 'due_date', 'time_end'], ];

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

                break;

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

                $validator[] = $funcName;

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

        //Set the start date and end date

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

     * @param mixed $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

                $minutes = 15;

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

     * @param mixed $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

            case 'due_date': $funcName = ['name' => 'dateAndTimeGreaterThanDependentField',

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

                'params' => ['date_start', 'time_start', 'due_date', 'time_end'], ];

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 returns special validator for fields.

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

                break;

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

                'params' => ['date_start', 'time_start', 'due_date', 'time_end'], ];

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

            default: $validator = parent::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

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

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

     * Function to get Edit view display value.

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

     * @return <Array>

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

                break;

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

                'params' => ['date_start', 'time_start', 'due_date', 'time_end'], ];

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

        }

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

     * @param string Data base 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

            case 'time_end': $funcName = ['name' => 'dateAndTimeGreaterThanDependentField',

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

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

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

class Reservations_Field_Model extends Vtiger_Field_Model

There are no issues that match your filters.

Category
Status