File field-manager.php
has 533 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Field_Manager class
*
* @package Leaves_And_Love\Plugin_Lib
Field_Manager
has 39 functions (exceeds 20 allowed). Consider refactoring. Open
class Field_Manager extends Service implements Field_Manager_Interface {
use Container_Service_Trait, Args_Service_Trait;
/**
* Instance ID of this field manager. Used internally.
Method enqueue
has 105 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function enqueue() {
if ( ! $this->enqueued( '_core' ) ) {
$this->library_assets()->register_style(
'fields',
'assets/dist/css/fields.css',
Function enqueue
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
public function enqueue() {
if ( ! $this->enqueued( '_core' ) ) {
$this->library_assets()->register_style(
'fields',
'assets/dist/css/fields.css',
- 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 Field_Manager has an overall complexity of 121 which is very high. The configured complexity threshold is 50. Open
class Field_Manager extends Service implements Field_Manager_Interface {
use Container_Service_Trait, Args_Service_Trait;
/**
* Instance ID of this field manager. Used internally.
- Exclude checks
The class Field_Manager has 14 public methods. Consider refactoring Field_Manager to keep number of public methods under 10. Open
class Field_Manager extends Service implements Field_Manager_Interface {
use Container_Service_Trait, Args_Service_Trait;
/**
* Instance ID of this field manager. Used internally.
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
The class Field_Manager has 29 non-getter- and setter-methods. Consider refactoring Field_Manager to keep number of methods under 25. Open
class Field_Manager extends Service implements Field_Manager_Interface {
use Container_Service_Trait, Args_Service_Trait;
/**
* Instance ID of this field manager. Used internally.
- Read upRead up
- Exclude checks
TooManyMethods
Since: 0.1
A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
The default was changed from 10 to 25 in PHPMD 2.3.
Example
Source https://phpmd.org/rules/codesize.html#toomanymethods
Function update_values
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
public function update_values( $values, $sections = null ) {
$field_instances = $this->get_fields( $sections );
$field_instances = $this->resolve_dependency_order( $field_instances );
$validated_values = $this->get_values();
- 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_dependency_order_for_instance
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
protected function resolve_dependency_order_for_instance( $field_instance, $all_instances, $resolved, $queued_ids ) {
if ( isset( $resolved[ $field_instance->id ] ) ) {
return $resolved;
}
- 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 update_values
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function update_values( $values, $sections = null ) {
$field_instances = $this->get_fields( $sections );
$field_instances = $this->resolve_dependency_order( $field_instances );
$validated_values = $this->get_values();
Function process_update_result
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
protected function process_update_result( $result, WP_Error $errors ) {
if ( is_wp_error( $result ) ) {
foreach ( $result->errors as $error_code => $error_messages ) {
foreach ( $error_messages as $error_message ) {
$errors->add( $error_code, $error_message );
- 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_values
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function get_values() {
if ( empty( $this->current_values ) ) {
$field_instances = $this->get_fields();
$id_key = array_search( '{id}', $this->get_value_callback_args, 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
Method register_default_field_types
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected static function register_default_field_types() {
if ( self::$defaults_registered ) {
return;
}
Function get_fields
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function get_fields( $sections = null ) {
if ( null !== $sections ) {
$sections = (array) $sections;
} else {
$sections = array_keys( $this->field_instances );
- 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 make_id
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function make_id( $id, $index = null ) {
$field_id = str_replace( '_', '-', $id );
$instance_id = $this->get_instance_id();
if ( $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 render
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function render( $sections = null, $render_callback = null ) {
$field_instances = $this->get_fields( $sections );
if ( ! $render_callback || ! is_callable( $render_callback ) ) {
switch ( $this->render_mode ) {
- 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 add
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function add( $id, $type, $args = array() ) {
if ( ! self::is_field_type_registered( $type ) ) {
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
The class Field_Manager has 1175 lines of code. Current threshold is 1000. Avoid really long classes. Open
class Field_Manager extends Service implements Field_Manager_Interface {
use Container_Service_Trait, Args_Service_Trait;
/**
* Instance ID of this field manager. Used internally.
- Exclude checks
The method enqueue() has 138 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function enqueue() {
if ( ! $this->enqueued( '_core' ) ) {
$this->library_assets()->register_style(
'fields',
'assets/dist/css/fields.css',
- Exclude checks
The method enqueue() has an NPath complexity of 6048. The configured NPath complexity threshold is 200. Open
public function enqueue() {
if ( ! $this->enqueued( '_core' ) ) {
$this->library_assets()->register_style(
'fields',
'assets/dist/css/fields.css',
- 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 enqueue() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10. Open
public function enqueue() {
if ( ! $this->enqueued( '_core' ) ) {
$this->library_assets()->register_style(
'fields',
'assets/dist/css/fields.css',
- 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 class Field_Manager has a coupling between objects value of 24. Consider to reduce the number of dependencies under 13. Open
class Field_Manager extends Service implements Field_Manager_Interface {
use Container_Service_Trait, Args_Service_Trait;
/**
* Instance ID of this field manager. Used internally.
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
Avoid using static access to class '\Leaves_And_Love\Plugin_Lib\Assets' in method '__construct'. Open
$services['library_assets'] = Assets::get_library_instance();
- 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 '$name_prefix'. Open
$name_prefix = $this->name_prefix;
- 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 local variables such as '$field_instance'. Open
foreach ( $field_instances 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 local variables such as '$id'. Open
foreach ( $field_instances 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 excessively long variable names like $prefixed_script_handle. Keep variable name length under 20. Open
$prefixed_script_handle = str_replace( '_', '-', $this->library_assets()->get_prefix() ) . 'fields';
- 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++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $service_library_assets. Keep variable name length under 20. Open
protected static $service_library_assets = Assets::class;
- 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++ ) {
}
}
}