Function is_valid_slug
has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring. Open
public function is_valid_slug( $parent = null ) {
if ( $this->valid_slug === null ) {
$globalnames = $this->supports_globalslug();
if ( $globalnames !== true ) {
if ( $globalnames !== 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
Function validate
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
public function validate( $parent = null ) {
if ( null !== $parent ) {
if ( count( $this->parents ) > 0 && ! $this->supports_multiparents() ) {
return new UtilError( 'no_multiparent_component', sprintf( __( 'The component %1$s of class %2$s already has a parent assigned and is not a multiparent component.', 'wpdlib' ), $this->slug, get_class( $this ) ), '', ComponentManager::get_scope() );
}
- 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 12 (exceeds 5 allowed). Consider refactoring. Open
public function add( $component ) {
if ( ComponentManager::is_too_late() ) {
return new UtilError( 'too_late_component', sprintf( __( 'Components must not be added later than the %s hook.', 'wpdlib' ), '<code>init</code>' ), '', ComponentManager::get_scope() );
}
- 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 is_valid_slug
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function is_valid_slug( $parent = null ) {
if ( $this->valid_slug === null ) {
$globalnames = $this->supports_globalslug();
if ( $globalnames !== true ) {
if ( $globalnames !== false ) {
Avoid deeply nested control flow statements. Open
if ( $parent === null ) {
$found = false;
break;
}
Function get_children
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function get_children( $class = '' ) {
$children = array();
if ( $class && '*' !== $class ) {
if ( isset( $this->children[ $class ] ) ) {
- 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 $component;
Avoid too many return
statements within this method. Open
return new UtilError( 'no_valid_slug_component', sprintf( __( 'A component of class %1$s with slug %2$s already exists.', 'wpdlib' ), get_class( $component ), $component->slug ), '', ComponentManager::get_scope() );
Function get_parent
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function get_parent( $index = 0, $depth = 1 ) {
$current = $this;
for ( $i = 0; $i < $depth; $i++ ) {
$parents = array_values( $current->parents );
if ( isset( $parents[ $index ] ) ) {
- 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"