Function get_data_by_condition_numeric_comparison_helper
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
protected function get_data_by_condition_numeric_comparison_helper( $prop, $field_values, $args, $reverse = false ) {
$operator = ( isset( $args['operator'] ) && strtoupper( $args['operator'] ) === 'OR' ) ? 'OR' : 'AND';
if ( $reverse ) {
$result_false = isset( $args['result_true'] ) ? $args['result_true'] : true;
- 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
The class Dependency_Resolver has an overall complexity of 105 which is very high. The configured complexity threshold is 50. Open
class Dependency_Resolver {
/**
* Dependencies definition.
*
* @since 1.0.0
- Exclude checks
Function merge_into_result
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
protected function merge_into_result( $result, $value, $operator ) {
if ( is_array( $result ) && isset( $result[0] ) && is_array( $value ) && isset( $value[0] ) ) {
if ( 'OR' === $operator ) {
$result = array_unique( array_merge( $result, $value ) );
} else {
- 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
File dependency-resolver.php
has 279 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Dependency_Resolver class
*
* @package Leaves_And_Love\Plugin_Lib
Function get_data_by_named_map
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
protected function get_data_by_named_map( $prop, $field_values, $args ) {
$default = isset( $args['default'] ) ? $args['default'] : null;
if ( empty( $args['named_map'] ) ) {
return $default;
- 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
Function get_data_by_condition_bool_helper
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
protected function get_data_by_condition_bool_helper( $prop, $field_values, $args, $reverse = false ) {
$operator = ( isset( $args['operator'] ) && strtoupper( $args['operator'] ) === 'OR' ) ? 'OR' : 'AND';
if ( $reverse ) {
$result_false = isset( $args['result_true'] ) ? $args['result_true'] : true;
- 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
Function resolve_dependencies
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
public function resolve_dependencies() {
$results = array();
$callbacks = $this->get_callbacks();
$instance_id = $this->field_manager->get_instance_id();
- 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
Function get_data_by_map
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
protected function get_data_by_map( $prop, $field_values, $args ) {
$default = isset( $args['default'] ) ? $args['default'] : null;
if ( empty( $args['map'] ) ) {
return $default;
- 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
Function parse_dependency
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
protected function parse_dependency( $dependency ) {
if ( ! is_array( $dependency ) ) {
return false;
}
- 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 get_data_by_condition_numeric_comparison_helper
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function get_data_by_condition_numeric_comparison_helper( $prop, $field_values, $args, $reverse = false ) {
$operator = ( isset( $args['operator'] ) && strtoupper( $args['operator'] ) === 'OR' ) ? 'OR' : 'AND';
if ( $reverse ) {
$result_false = isset( $args['result_true'] ) ? $args['result_true'] : true;
Method get_data_by_named_map
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function get_data_by_named_map( $prop, $field_values, $args ) {
$default = isset( $args['default'] ) ? $args['default'] : null;
if ( empty( $args['named_map'] ) ) {
return $default;
Function get_dependency_field_identifiers
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function get_dependency_field_identifiers( $props = array() ) {
$field_identifiers = array();
$props = (array) $props;
- 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
The method get_data_by_condition_bool_helper() has an NPath complexity of 288. The configured NPath complexity threshold is 200. Open
protected function get_data_by_condition_bool_helper( $prop, $field_values, $args, $reverse = false ) {
$operator = ( isset( $args['operator'] ) && strtoupper( $args['operator'] ) === 'OR' ) ? 'OR' : 'AND';
if ( $reverse ) {
$result_false = isset( $args['result_true'] ) ? $args['result_true'] : true;
- 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 get_data_by_named_map() has an NPath complexity of 624. The configured NPath complexity threshold is 200. Open
protected function get_data_by_named_map( $prop, $field_values, $args ) {
$default = isset( $args['default'] ) ? $args['default'] : null;
if ( empty( $args['named_map'] ) ) {
return $default;
- 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 get_data_by_condition_numeric_comparison_helper() has an NPath complexity of 14400. The configured NPath complexity threshold is 200. Open
protected function get_data_by_condition_numeric_comparison_helper( $prop, $field_values, $args, $reverse = false ) {
$operator = ( isset( $args['operator'] ) && strtoupper( $args['operator'] ) === 'OR' ) ? 'OR' : 'AND';
if ( $reverse ) {
$result_false = isset( $args['result_true'] ) ? $args['result_true'] : true;
- 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 get_data_by_map() has an NPath complexity of 336. The configured NPath complexity threshold is 200. Open
protected function get_data_by_map( $prop, $field_values, $args ) {
$default = isset( $args['default'] ) ? $args['default'] : null;
if ( empty( $args['map'] ) ) {
return $default;
- 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 get_data_by_condition_numeric_comparison_helper() has a Cyclomatic Complexity of 23. The configured cyclomatic complexity threshold is 10. Open
protected function get_data_by_condition_numeric_comparison_helper( $prop, $field_values, $args, $reverse = false ) {
$operator = ( isset( $args['operator'] ) && strtoupper( $args['operator'] ) === 'OR' ) ? 'OR' : 'AND';
if ( $reverse ) {
$result_false = isset( $args['result_true'] ) ? $args['result_true'] : true;
- 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
The method get_data_by_condition_bool_helper() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. Open
protected function get_data_by_condition_bool_helper( $prop, $field_values, $args, $reverse = false ) {
$operator = ( isset( $args['operator'] ) && strtoupper( $args['operator'] ) === 'OR' ) ? 'OR' : 'AND';
if ( $reverse ) {
$result_false = isset( $args['result_true'] ) ? $args['result_true'] : true;
- 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
The method get_data_by_map() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
protected function get_data_by_map( $prop, $field_values, $args ) {
$default = isset( $args['default'] ) ? $args['default'] : null;
if ( empty( $args['map'] ) ) {
return $default;
- 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
The method get_data_by_named_map() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
protected function get_data_by_named_map( $prop, $field_values, $args ) {
$default = isset( $args['default'] ) ? $args['default'] : null;
if ( empty( $args['named_map'] ) ) {
return $default;
- 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
The method merge_into_result() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Open
protected function merge_into_result( $result, $value, $operator ) {
if ( is_array( $result ) && isset( $result[0] ) && is_array( $value ) && isset( $value[0] ) ) {
if ( 'OR' === $operator ) {
$result = array_unique( array_merge( $result, $value ) );
} else {
- 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
Avoid unused parameters such as '$prop'. Open
protected function get_data_by_condition_numeric_comparison_helper( $prop, $field_values, $args, $reverse = false ) {
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused local variables such as '$identifier'. Open
foreach ( $field_values as $identifier => $value ) {
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid unused parameters such as '$prop'. Open
protected function get_data_by_named_map( $prop, $field_values, $args ) {
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused parameters such as '$prop'. Open
protected function get_data_by_map( $prop, $field_values, $args ) {
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused parameters such as '$prop'. Open
protected function get_data_by_condition_bool_helper( $prop, $field_values, $args, $reverse = false ) {
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused local variables such as '$instance_id'. Open
$instance_id = $this->field_manager->get_instance_id();
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Identical blocks of code found in 2 locations. Consider refactoring. Open
if ( $reverse ) {
$result_false = isset( $args['result_true'] ) ? $args['result_true'] : true;
$result_true = isset( $args['result_false'] ) ? $args['result_false'] : false;
} else {
$result_false = isset( $args['result_false'] ) ? $args['result_false'] : false;
- Read upRead up
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 112.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if ( $reverse ) {
$result_false = isset( $args['result_true'] ) ? $args['result_true'] : true;
$result_true = isset( $args['result_false'] ) ? $args['result_false'] : false;
} else {
$result_false = isset( $args['result_false'] ) ? $args['result_false'] : false;
- Read upRead up
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 112.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Avoid excessively long variable names like $dependency_prop_whitelist. Keep variable name length under 20. Open
$dependency_prop_whitelist = $this->get_dependency_prop_whitelist();
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}