Function validate_single
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
protected function validate_single( $value = null ) {
if ( empty( $value ) ) {
return array();
}
- 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 __construct
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function __construct( $manager, $id, $args = array() ) {
$fields = array();
if ( isset( $args['fields'] ) ) {
$fields = $args['fields'];
unset( $args['fields'] );
- 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 enqueue
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function enqueue() {
$deps = array();
$data = array();
foreach ( $this->fields as $id => $field_instance ) {
- 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 validate_single
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function validate_single( $value = null ) {
if ( empty( $value ) ) {
return array();
}
Method __construct
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function __construct( $manager, $id, $args = array() ) {
$fields = array();
if ( isset( $args['fields'] ) ) {
$fields = $args['fields'];
unset( $args['fields'] );
Function is_value_empty
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
protected function is_value_empty( $value ) {
foreach ( $this->fields as $id => $field ) {
$partial_value = is_array( $value ) && isset( $value[ $id ] ) ? $value[ $id ] : $field->default;
if ( is_string( $partial_value ) ) {
- 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 using static access to class 'Leaves_And_Love\Plugin_Lib\Fields\Field_Manager' in method '__construct'. Open
if ( 'group' === $type || ! Field_Manager::is_field_type_registered( $type ) ) {
- 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 'Leaves_And_Love\Plugin_Lib\Fields\Field_Manager' in method '__construct'. Open
$class_name = Field_Manager::get_registered_field_type( $type );
- 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 unused local variables such as '$id'. Open
foreach ( $this->fields as $id => $field_instance ) {
- 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 '$index'. Open
public function make_id( $id, $index = null ) {
- 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 '$index'. Open
public function make_name( $id, $index = null ) {
- 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
}
}