Method getRenewalValue
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getRenewalValue()
{
if ($this->isEmpty('product') || !\App\Record::isExists($this->get('product'), 'Products')) {
return 'PLL_NOT_APPLICABLE_VERIFICATION';
}
Function getRenewalValue
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function getRenewalValue()
{
if ($this->isEmpty('product') || !\App\Record::isExists($this->get('product'), 'Products')) {
return 'PLL_NOT_APPLICABLE_VERIFICATION';
}
- 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
Avoid too many return
statements within this method. Open
return \call_user_func_array("{$classFunction['class']}::{$classFunction['method']}", [$this, 'PLL_NOT_RENEWED_VERIFICATION']);
Avoid too many return
statements within this method. Open
return 'PLL_WAITING_FOR_RENEWAL';
Avoid too many return
statements within this method. Open
return 'PLL_NOT_RENEWED_VERIFICATION';
Avoid too many return
statements within this method. Open
return \call_user_func_array("{$classFunction['class']}::{$classFunction['method']}", [$this, 'PLL_WAITING_FOR_RENEWAL', $renewalTime]);
The method getRenewalValue() has an NPath complexity of 576. The configured NPath complexity threshold is 200. Open
public function getRenewalValue()
{
if ($this->isEmpty('product') || !\App\Record::isExists($this->get('product'), 'Products')) {
return 'PLL_NOT_APPLICABLE_VERIFICATION';
}
- Read upRead up
- Exclude checks
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 12. The configured cyclomatic complexity threshold is 10. Open
public function getRenewalValue()
{
if ($this->isEmpty('product') || !\App\Record::isExists($this->get('product'), 'Products')) {
return 'PLL_NOT_APPLICABLE_VERIFICATION';
}
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Reduce the number of returns of this function 8, down to the maximum allowed 3. Open
public function getRenewalValue()
- Read upRead up
- Exclude checks
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 'Vtiger_Record_Model' in method 'getRenewalValue'. Open
$productsRecordModel = Vtiger_Record_Model::getInstanceById($this->get('product'), 'Products');
- 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\Config' in method 'getRenewalValue'. Open
$classFunction = App\Config::module('Assets', 'RENEWAL_CUSTOMER_FUNCTION');
- 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\Config' in method 'getRenewalValue'. Open
$renewalTime = App\Config::module('Assets', 'RENEWAL_TIME');
- 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\Record' in method 'getRenewalValue'. Open
if ($this->isEmpty('product') || !\App\Record::isExists($this->get('product'), 'Products')) {
- 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 "method" 3 times. Open
if ($classFunction && class_exists($classFunction['class']) && method_exists($classFunction['class'], $classFunction['method'])) {
- 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 "product" 3 times. Open
if ($this->isEmpty('product') || !\App\Record::isExists($this->get('product'), 'Products')) {
- 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 "class" 4 times. Open
if ($classFunction && class_exists($classFunction['class']) && method_exists($classFunction['class'], $classFunction['method'])) {
- 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.
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Assets_Record_Model extends Vtiger_Record_Model
- Exclude checks
The class Assets_Record_Model is not named in CamelCase. Open
class Assets_Record_Model extends Vtiger_Record_Model
{
public function updateRenewal()
{
$value = $this->getRenewalValue();
- 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
return 'PLL_NOT_APPLICABLE_VERIFICATION';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($this->isEmpty('product') || !\App\Record::isExists($this->get('product'), 'Products')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$renewalTime = App\Config::module('Assets', 'RENEWAL_TIME');
- Exclude checks
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']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function updateRenewal()
- 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
$dateInService = strtotime($this->get('dateinservice'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$methodExist = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $this->getRenewalValue();
- 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
$dateRenewable = strtotime('-' . $renewalTime, $dateInService);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$classFunction = App\Config::module('Assets', 'RENEWAL_CUSTOMER_FUNCTION');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$methodExist = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($methodExist) {
- 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
$productsRecordModel = Vtiger_Record_Model::getInstanceById($this->get('product'), 'Products');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 143 characters Open
return \call_user_func_array("{$classFunction['class']}::{$classFunction['method']}", [$this, 'PLL_NOT_RENEWED_VERIFICATION']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($methodExist) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($value && $this->get('assets_renew') != $value) {
- Exclude checks
Line exceeds 120 characters; contains 138 characters Open
if ($classFunction && class_exists($classFunction['class']) && method_exists($classFunction['class'], $classFunction['method'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($dateRenewable > time()) {
- 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
$renewable = $productsRecordModel->get('renewable');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return 'PLL_NOT_APPLICABLE_VERIFICATION';
- Exclude checks
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', $renewalTime]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$renewable) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->set('assets_renew', $value);
- Exclude checks
Line exceeds 120 characters; contains 148 characters Open
return \call_user_func_array("{$classFunction['class']}::{$classFunction['method']}", [$this, 'PLL_WAITING_FOR_RENEWAL', $renewalTime]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return 'PLL_PLANNED';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$this->isEmpty('renewalinvoice')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return 'PLL_RENEWED_VERIFICATION';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($classFunction && class_exists($classFunction['class']) && method_exists($classFunction['class'], $classFunction['method'])) {
- 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 getRenewalValue()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (strtotime('+' . $renewalTime, $dateInService) < time()) {
- 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 'PLL_WAITING_FOR_RENEWAL';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return 'PLL_NOT_RENEWED_VERIFICATION';
- Exclude checks
Class name "Assets_Record_Model" is not in camel caps format Open
class Assets_Record_Model extends Vtiger_Record_Model
- Exclude checks