YetiForceCompany/YetiForceCRM

View on GitHub
modules/OSSSoldServices/models/Record.php

Summary

Maintainability
B
5 hrs
Test Coverage
F
0%

Function getRenewalValue has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    public function getRenewalValue()
    {
        if ($this->isEmpty('serviceid') || !\App\Record::isExists($this->get('serviceid'), 'Services')) {
            return 'PLL_NOT_APPLICABLE_VERIFICATION';
        }
Severity: Minor
Found in modules/OSSSoldServices/models/Record.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 getRenewalValue has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getRenewalValue()
    {
        if ($this->isEmpty('serviceid') || !\App\Record::isExists($this->get('serviceid'), 'Services')) {
            return 'PLL_NOT_APPLICABLE_VERIFICATION';
        }
Severity: Minor
Found in modules/OSSSoldServices/models/Record.php - About 1 hr to fix

    Avoid too many return statements within this method.
    Open

                return 'PLL_PLANNED';
    Severity: Major
    Found in modules/OSSSoldServices/models/Record.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

              return 'PLL_WAITING_FOR_RENEWAL';
      Severity: Major
      Found in modules/OSSSoldServices/models/Record.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                    return 'PLL_NOT_RENEWED_VERIFICATION';
        Severity: Major
        Found in modules/OSSSoldServices/models/Record.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                          return \call_user_func_array("{$classFunction['class']}::{$classFunction['method']}", [$this, 'PLL_NOT_RENEWED_VERIFICATION']);
          Severity: Major
          Found in modules/OSSSoldServices/models/Record.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return \call_user_func_array("{$classFunction['class']}::{$classFunction['method']}", [$this, 'PLL_WAITING_FOR_RENEWAL']);
            Severity: Major
            Found in modules/OSSSoldServices/models/Record.php - About 30 mins to fix

              The method getRenewalValue() has an NPath complexity of 864. The configured NPath complexity threshold is 200.
              Open

                  public function getRenewalValue()
                  {
                      if ($this->isEmpty('serviceid') || !\App\Record::isExists($this->get('serviceid'), 'Services')) {
                          return 'PLL_NOT_APPLICABLE_VERIFICATION';
                      }

              NPathComplexity

              Since: 0.1

              The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

              Example

              class Foo {
                  function bar() {
                      // lots of complicated code
                  }
              }

              Source https://phpmd.org/rules/codesize.html#npathcomplexity

              The method getRenewalValue() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
              Open

                  public function getRenewalValue()
                  {
                      if ($this->isEmpty('serviceid') || !\App\Record::isExists($this->get('serviceid'), 'Services')) {
                          return 'PLL_NOT_APPLICABLE_VERIFICATION';
                      }

              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

              Reduce the number of returns of this function 9, down to the maximum allowed 3.
              Open

                  public function getRenewalValue()

              Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

              Noncompliant Code Example

              With the default threshold of 3:

              function myFunction(){ // Noncompliant as there are 4 return statements
                if (condition1) {
                  return true;
                } else {
                  if (condition2) {
                    return false;
                  } else {
                    return true;
                  }
                }
                return false;
              }
              

              Avoid using static access to class '\App\Record' in method 'getRenewalValue'.
              Open

                      if ($this->isEmpty('serviceid') || !\App\Record::isExists($this->get('serviceid'), 'Services')) {

              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\Config' in method 'getRenewalValue'.
              Open

                      $classFunction = App\Config::module('Assets', 'RENEWAL_CUSTOMER_FUNCTION');

              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 'getRenewalValue'.
              Open

                      $productsRecordModel = Vtiger_Record_Model::getInstanceById($this->get('serviceid'), 'Services');

              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\Config' in method 'getRenewalValue'.
              Open

                      $renewalTime = App\Config::module('OSSSoldServices', 'RENEWAL_TIME');

              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 "class" 5 times.
              Open

                      if ($classFunction && class_exists($classFunction['class']) && method_exists($classFunction['class'], $classFunction['method'])) {

              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 "method" 4 times.
              Open

                      if ($classFunction && class_exists($classFunction['class']) && method_exists($classFunction['class'], $classFunction['method'])) {

              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 "serviceid" 3 times.
              Open

                      if ($this->isEmpty('serviceid') || !\App\Record::isExists($this->get('serviceid'), 'Services')) {

              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.

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

              class OSSSoldServices_Record_Model extends Vtiger_Record_Model

              The class OSSSoldServices_Record_Model is not named in CamelCase.
              Open

              class OSSSoldServices_Record_Model extends Vtiger_Record_Model
              {
                  public function updateRenewal()
                  {
                      $value = $this->getRenewalValue();

              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

                      $dateRenewable = strtotime('-' . $renewalTime, $dateInService);

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

                      $classFunction = App\Config::module('Assets', 'RENEWAL_CUSTOMER_FUNCTION');

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

                      $methodExist = false;

              Line exceeds 120 characters; contains 138 characters
              Open

                      if ($classFunction && class_exists($classFunction['class']) && method_exists($classFunction['class'], $classFunction['method'])) {

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

                      if ($methodExist) {

              Line exceeds 120 characters; contains 126 characters
              Open

                              return \call_user_func_array("{$classFunction['class']}::{$classFunction['method']}", [$this, 'PLL_PLANNED']);

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

                              return \call_user_func_array("{$classFunction['class']}::{$classFunction['method']}", [$this, 'PLL_NOT_RENEWED_VERIFICATION']);

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

                          $this->save();

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

                      $dateInService = strtotime($this->get('dateinservice'));

              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 'PLL_WAITING_FOR_RENEWAL';

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

                  public function updateRenewal()

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

                      $value = $this->getRenewalValue();

              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

                          return 'PLL_NOT_APPLICABLE_VERIFICATION';

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

                      $productsRecordModel = Vtiger_Record_Model::getInstanceById($this->get('serviceid'), 'Services');

              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 ($value && $this->get('osssoldservices_renew') != $value) {

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

                              return \call_user_func_array("{$classFunction['class']}::{$classFunction['method']}", [$this, 'PLL_PLANNED']);

              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 (!$this->isEmpty('renewalinvoice')) {

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

                          $methodExist = true;

              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

                          return 'PLL_NOT_APPLICABLE_VERIFICATION';

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

                          if ($methodExist) {

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

                          if ($methodExist) {

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

                          return 'PLL_RENEWED_VERIFICATION';

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

                          return 'PLL_PLANNED';

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

                          return 'PLL_NOT_RENEWED_VERIFICATION';

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

                          return \call_user_func_array("{$classFunction['class']}::{$classFunction['method']}", [$this, 'PLL_WAITING_FOR_RENEWAL']);

              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 ($this->isEmpty('serviceid') || !\App\Record::isExists($this->get('serviceid'), 'Services')) {

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

                      if ($classFunction && class_exists($classFunction['class']) && method_exists($classFunction['class'], $classFunction['method'])) {

              Line exceeds 120 characters; contains 134 characters
              Open

                          return \call_user_func_array("{$classFunction['class']}::{$classFunction['method']}", [$this, 'PLL_WAITING_FOR_RENEWAL']);

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

                  public function getRenewalValue()

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

                      if (!$renewable) {

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

                      $renewalTime = App\Config::module('OSSSoldServices', 'RENEWAL_TIME');

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

                      if ($dateRenewable > time()) {

              Line exceeds 120 characters; contains 143 characters
              Open

                              return \call_user_func_array("{$classFunction['class']}::{$classFunction['method']}", [$this, 'PLL_NOT_RENEWED_VERIFICATION']);

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

                      $renewable = $productsRecordModel->get('renewable');

              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 (strtotime('+' . $renewalTime, $dateInService) < time()) {

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

                      }

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

                          $this->set('osssoldservices_renew', $value);

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

                      }

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

              class OSSSoldServices_Record_Model extends Vtiger_Record_Model

              There are no issues that match your filters.

              Category
              Status