Function editor_settings
has a Cognitive Complexity of 195 (exceeds 5 allowed). Consider refactoring. Open
public static function editor_settings($editor_id, $set) {
$first_run = false;
if ( empty(self::$first_init) ) {
if ( is_admin() ) {
- 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 899 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 249 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function editor_settings($editor_id, $set) {
$first_run = false;
if ( empty(self::$first_init) ) {
if ( is_admin() ) {
Method wp_mce_translation
has 190 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function wp_mce_translation() {
$mce_translation = array(
// Default TinyMCE strings
'New document' => __( 'New document' ),
Method editor_js
has 125 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function editor_js() {
global $tinymce_version, $concatenate_scripts, $compress_scripts;
/**
* Filter "tiny_mce_version" is deprecated
Function editor_js
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
public static function editor_js() {
global $tinymce_version, $concatenate_scripts, $compress_scripts;
/**
* Filter "tiny_mce_version" is deprecated
- 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 editor
has a Cognitive Complexity of 20 (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( $set['editor_class'] . ' wp-editor-area' ) . '"';
$tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
- 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_fullscreen_html
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function wp_fullscreen_html() {
global $content_width;
$post = get_post();
$width = isset( $content_width ) && 800 > $content_width ? $content_width : 800;
Method editor
has 61 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( $set['editor_class'] . ' wp-editor-area' ) . '"';
$tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
Method wp_link_dialog
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function wp_link_dialog() {
$search_panel_visible = '1' == get_user_setting( 'wplink', '0' ) ? ' search-panel-visible' : '';
// display: none is required here, see #WP27605
?>
Function parse_settings
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public static function parse_settings( $editor_id, $settings ) {
$set = wp_parse_args( $settings, array(
'wpautop' => true,
'media_buttons' => true,
'default_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
Method parse_settings
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function parse_settings( $editor_id, $settings ) {
$set = wp_parse_args( $settings, array(
'wpautop' => true,
'media_buttons' => true,
'default_editor' => '',
Method wp_link_query
has 33 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(
Function wp_fullscreen_html
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public static function wp_fullscreen_html() {
global $content_width;
$post = get_post();
$width = isset( $content_width ) && 800 > $content_width ? $content_width : 800;
- 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 _parse_init
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private static function _parse_init($init) {
$options = '';
foreach ( $init as $k => $v ) {
if ( is_bool($v) ) {
- 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($v) ) {
$val = $v ? 'true' : 'false';
$options .= $k . ':' . $val . ',';
continue;
} elseif ( !empty($v) && is_string($v) && ( ('{' == $v{0} && '}' == $v{strlen($v) - 1}) || ('[' == $v{0} && ']' == $v{strlen($v) - 1}) || preg_match('/^\(?function ?\(/', $v) ) ) {
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 ( @is_file( $path . $mce_locale . '.js' ) )
$strings .= @file_get_contents( $path . $mce_locale . '.js' ) . "\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 ( $file && file_exists( "$template_dir/$file" ) )
$mce_css[] = "$template_uri/$file";
Avoid deeply nested control flow statements. Open
if ( function_exists('realpath') )
$path = trailingslashit( realpath($path) );
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 ( ! empty( $strings ) )
$ext_plugins .= "\n" . $strings . "\n";
Function wp_link_query
has a Cognitive Complexity of 6 (exceeds 5 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(
- 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_scripts
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function enqueue_scripts() {
wp_enqueue_script('word-count');
if ( 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
Identical blocks of code found in 2 locations. Consider refactoring. 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";
}
- 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 161.
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