Function editor_settings
has a Cognitive Complexity of 184 (exceeds 5 allowed). Consider refactoring. Open
public static function editor_settings( $editor_id, $set ) {
if ( empty( self::$first_init ) ) {
if ( is_admin() ) {
add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
add_action( 'admin_print_footer_scripts', array( __CLASS__, 'force_uncompressed_tinymce' ), 1 );
- 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 class-wp-editor.php
has 1191 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Facilitates adding of the WordPress editor as used on the Write and Edit screens.
*
* @package WordPress
Method editor_settings
has 277 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function editor_settings( $editor_id, $set ) {
if ( empty( self::$first_init ) ) {
if ( is_admin() ) {
add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
add_action( 'admin_print_footer_scripts', array( __CLASS__, 'force_uncompressed_tinymce' ), 1 );
Method get_translation
has 254 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function get_translation() {
if ( empty( self::$translation ) ) {
self::$translation = array(
// Default TinyMCE strings.
'New document' => __( 'New document' ),
Method editor_js
has 119 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function editor_js() {
global $tinymce_version;
$tmce_on = ! empty( self::$mce_settings );
$mce_init = '';
Function editor
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring. Open
public static function editor( $content, $editor_id, $settings = array() ) {
$set = self::parse_settings( $editor_id, $settings );
$editor_class = ' class="' . trim( esc_attr( $set['editor_class'] ) . ' wp-editor-area' ) . '"';
$tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
$default_editor = 'html';
- 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 editor
has 94 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function editor( $content, $editor_id, $settings = array() ) {
$set = self::parse_settings( $editor_id, $settings );
$editor_class = ' class="' . trim( esc_attr( $set['editor_class'] ) . ' wp-editor-area' ) . '"';
$tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
$default_editor = 'html';
Method wp_link_dialog
has 73 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function wp_link_dialog() {
// Run once.
if ( self::$link_dialog_printed ) {
return;
}
Method print_default_editor_scripts
has 68 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function print_default_editor_scripts() {
$user_can_richedit = user_can_richedit();
if ( $user_can_richedit ) {
$settings = self::default_settings();
Function editor_js
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public static function editor_js() {
global $tinymce_version;
$tmce_on = ! empty( self::$mce_settings );
$mce_init = '';
- 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 default_settings
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function default_settings() {
global $tinymce_version;
$shortcut_labels = array();
Method parse_settings
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function parse_settings( $editor_id, $settings ) {
/**
* Filters the wp_editor() settings.
*
Function parse_settings
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public static function parse_settings( $editor_id, $settings ) {
/**
* Filters the wp_editor() settings.
*
- 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 wp_mce_translation
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
if ( ! $mce_locale ) {
$mce_locale = self::get_mce_locale();
}
- 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 wp_link_query
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function wp_link_query( $args = array() ) {
$pts = get_post_types( array( 'public' => true ), 'objects' );
$pt_names = array_keys( $pts );
$query = array(
Method wp_mce_translation
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
if ( ! $mce_locale ) {
$mce_locale = self::get_mce_locale();
}
Function _parse_init
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private static function _parse_init( $init ) {
$options = '';
foreach ( $init as $key => $value ) {
if ( is_bool( $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
Consider simplifying this complex logical expression. Open
if ( is_bool( $value ) ) {
$val = $value ? 'true' : 'false';
$options .= $key . ':' . $val . ',';
continue;
} elseif ( ! empty( $value ) && is_string( $value ) && (
Avoid deeply nested control flow statements. Open
if ( ! empty( $strings ) ) {
$ext_plugins .= "\n" . $strings . "\n";
}
Avoid deeply nested control flow statements. Open
if ( @is_file( $path . $mce_locale . '_dlg.js' ) ) {
$strings .= @file_get_contents( $path . $mce_locale . '_dlg.js' ) . "\n";
}
Avoid deeply nested control flow statements. Open
if ( @is_file( $path ) && @is_readable( $path ) ) {
include_once $path;
$ext_plugins .= $strings . "\n";
$loaded_langs[] = $name;
}
Avoid deeply nested control flow statements. Open
if ( str_contains( $url, ',' ) ) {
$editor_styles[ $key ] = str_replace( ',', '%2C', $url );
}
Avoid deeply nested control flow statements. Open
if ( 'en' !== $mce_locale && empty( $strings ) ) {
if ( @is_file( $path . 'en.js' ) ) {
$str1 = @file_get_contents( $path . 'en.js' );
$strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str1, 1 ) . "\n";
}
Avoid deeply nested control flow statements. Open
if ( @is_file( $path . $mce_locale . '.js' ) ) {
$strings .= @file_get_contents( $path . $mce_locale . '.js' ) . "\n";
}
Avoid deeply nested control flow statements. Open
if ( ! $path ) {
continue;
}
Function enqueue_scripts
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function enqueue_scripts( $default_scripts = false ) {
if ( $default_scripts || self::$has_tinymce ) {
wp_enqueue_script( 'editor' );
}
- 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 print_default_editor_scripts
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function print_default_editor_scripts() {
$user_can_richedit = user_can_richedit();
if ( $user_can_richedit ) {
$settings = self::default_settings();
- 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
foreach ( $init as $key => $value ) {
if ( is_bool( $value ) ) {
$val = $value ? 'true' : 'false';
$options .= $key . ':' . $val . ',';
continue;
- 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 195.
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