File class-connector-widgets.php
has 472 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Connector for Widgets
*
* @package WP_Stream
Function callback_updated_option
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
public function callback_updated_option( $option_name, $old_value, $new_value ) {
if ( ! preg_match( '/^widget_(.+)$/', $option_name, $matches ) || ! is_array( $new_value ) ) {
return;
}
- 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 callback_updated_option
has 116 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function callback_updated_option( $option_name, $old_value, $new_value ) {
if ( ! preg_match( '/^widget_(.+)$/', $option_name, $matches ) || ! is_array( $new_value ) ) {
return;
}
Function handle_widget_moved
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
protected function handle_widget_moved( $old, $new ) {
$all_sidebar_ids = array_intersect( array_keys( $old ), array_keys( $new ) );
foreach ( $all_sidebar_ids as $new_sidebar_id ) {
if ( $old[ $new_sidebar_id ] === $new[ $new_sidebar_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
Connector_Widgets
has 21 functions (exceeds 20 allowed). Consider refactoring. Open
class Connector_Widgets extends Connector {
/**
* Whether or not 'created' and 'deleted' actions should be logged. Normally
* the sidebar 'added' and 'removed' actions will correspond with these.
Method handle_widget_moved
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function handle_widget_moved( $old, $new ) {
$all_sidebar_ids = array_intersect( array_keys( $old ), array_keys( $new ) );
foreach ( $all_sidebar_ids as $new_sidebar_id ) {
if ( $old[ $new_sidebar_id ] === $new[ $new_sidebar_id ] ) {
Function handle_reactivated_widgets
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
protected function handle_reactivated_widgets( $old, $new ) {
$new_reactivated_widget_ids = array_diff( $old['wp_inactive_widgets'], $new['wp_inactive_widgets'] );
foreach ( $new_reactivated_widget_ids as $widget_id ) {
$sidebar_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 handle_widget_addition
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
protected function handle_widget_addition( $old, $new ) {
$all_old_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $old ) ) );
$all_new_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $new ) ) );
$added_widget_ids = array_diff( $all_new_widget_ids, $all_old_widget_ids );
- 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 handle_deactivated_widgets
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
protected function handle_deactivated_widgets( $old, $new ) {
$new_deactivated_widget_ids = array_diff( $new['wp_inactive_widgets'], $old['wp_inactive_widgets'] );
foreach ( $new_deactivated_widget_ids as $widget_id ) {
$sidebar_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 handle_widget_removal
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
protected function handle_widget_removal( $old, $new ) {
$all_old_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $old ) ) );
$all_new_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $new ) ) );
// @todo In the customizer, moving widgets to other sidebars is problematic because each sidebar is registered as a separate setting; so we need to make sure that all $_POST['customized'] are applied?
// @todo The widget option is getting updated before the sidebars_widgets are updated, so we need to hook into the option update to try to cache any deletions for future lookup
- 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 handle_widget_removal
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function handle_widget_removal( $old, $new ) {
$all_old_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $old ) ) );
$all_new_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $new ) ) );
// @todo In the customizer, moving widgets to other sidebars is problematic because each sidebar is registered as a separate setting; so we need to make sure that all $_POST['customized'] are applied?
// @todo The widget option is getting updated before the sidebars_widgets are updated, so we need to hook into the option update to try to cache any deletions for future lookup
Method handle_widget_addition
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function handle_widget_addition( $old, $new ) {
$all_old_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $old ) ) );
$all_new_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $new ) ) );
$added_widget_ids = array_diff( $all_new_widget_ids, $all_old_widget_ids );
Method handle_deactivated_widgets
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function handle_deactivated_widgets( $old, $new ) {
$new_deactivated_widget_ids = array_diff( $new['wp_inactive_widgets'], $old['wp_inactive_widgets'] );
foreach ( $new_deactivated_widget_ids as $widget_id ) {
$sidebar_id = '';
Method handle_reactivated_widgets
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function handle_reactivated_widgets( $old, $new ) {
$new_reactivated_widget_ids = array_diff( $old['wp_inactive_widgets'], $new['wp_inactive_widgets'] );
foreach ( $new_reactivated_widget_ids as $widget_id ) {
$sidebar_id = '';
Method handle_widget_reordering
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function handle_widget_reordering( $old, $new ) {
$all_sidebar_ids = array_intersect( array_keys( $old ), array_keys( $new ) );
foreach ( $all_sidebar_ids as $sidebar_id ) {
if ( $old[ $sidebar_id ] === $new[ $sidebar_id ] ) {
Function get_widget_instance
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function get_widget_instance( $widget_id ) {
$instance = null;
$parsed_widget_id = $this->parse_widget_id( $widget_id );
$widget_obj = $this->get_widget_object( $widget_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 handle_widget_reordering
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function handle_widget_reordering( $old, $new ) {
$all_sidebar_ids = array_intersect( array_keys( $old ), array_keys( $new ) );
foreach ( $all_sidebar_ids as $sidebar_id ) {
if ( $old[ $sidebar_id ] === $new[ $sidebar_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
Similar blocks of code found in 2 locations. Consider refactoring. Open
protected function handle_widget_removal( $old, $new ) {
$all_old_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $old ) ) );
$all_new_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $new ) ) );
// @todo In the customizer, moving widgets to other sidebars is problematic because each sidebar is registered as a separate setting; so we need to make sure that all $_POST['customized'] are applied?
// @todo The widget option is getting updated before the sidebars_widgets are updated, so we need to hook into the option update to try to cache any deletions for future lookup
- 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 367.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
protected function handle_widget_addition( $old, $new ) {
$all_old_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $old ) ) );
$all_new_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $new ) ) );
$added_widget_ids = array_diff( $all_new_widget_ids, $all_old_widget_ids );
- 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 367.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
foreach ( $deletes as $delete ) {
if ( $delete['name'] && $delete['title'] ) {
/* translators: %1$s: a widget name, %2$s: a widget title (e.g. "Archives", "Browse") */
$message = _x( '%1$s widget named "%2$s" deleted', '1: Name, 2: Title', 'stream' );
} elseif ( $delete['name'] ) {
- 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 197.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
foreach ( $creates as $create ) {
if ( $create['name'] && $create['title'] ) {
/* translators: %1$s: a widget name, %2$s: a widget title (e.g. "Archives", "Browse") */
$message = _x( '%1$s widget named "%2$s" created', '1: Name, 2: Title', 'stream' );
} elseif ( $create['name'] ) {
- 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 197.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
public function get_action_labels() {
return array(
'added' => esc_html__( 'Added', 'stream' ),
'removed' => esc_html__( 'Removed', 'stream' ),
'moved' => esc_html__( 'Moved', 'stream' ),
- 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 143.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
foreach ( $created_widget_numbers as $widget_number ) {
$instance = $new_value[ $widget_number ];
$widget_id = sprintf( $widget_id_format, $widget_number );
$name = $this->get_widget_name( $widget_id );
$title = ! empty( $instance['title'] ) ? $instance['title'] : null;
- 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 116.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
foreach ( $deleted_widget_numbers as $widget_number ) {
$instance = $old_value[ $widget_number ];
$widget_id = sprintf( $widget_id_format, $widget_number );
$name = $this->get_widget_name( $widget_id );
$title = ! empty( $instance['title'] ) ? $instance['title'] : null;
- 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 116.
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