File media.php
has 620 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* WordPress API for media display.
*
* @package WordPress
Method gallery_shortcode
has 94 lines of code (exceeds 25 allowed). Consider refactoring. Open
function gallery_shortcode($attr) {
global $post, $wp_locale;
static $instance = 0;
$instance++;
Function shortcode
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
function shortcode( $attr, $url = '' ) {
global $post;
if ( empty($url) )
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
Function image_get_intermediate_size
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
function image_get_intermediate_size($post_id, $size='thumbnail') {
if ( !is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) )
return false;
// get the best one for a specified set of dimensions
- 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 gallery_shortcode
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
function gallery_shortcode($attr) {
global $post, $wp_locale;
static $instance = 0;
$instance++;
- 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_attachment_taxonomies
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
function get_attachment_taxonomies($attachment) {
if ( is_int( $attachment ) )
$attachment = get_post($attachment);
else if ( is_array($attachment) )
$attachment = (object) $attachment;
- 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 image_resize
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
$image = wp_load_image( $file );
if ( !is_resource( $image ) )
return new WP_Error('error_loading_image', $image);
- 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 image_constrain_size_for_editor
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
function image_constrain_size_for_editor($width, $height, $size = 'medium') {
global $content_width, $_wp_additional_image_sizes;
if ( is_array($size) ) {
$max_width = $size[0];
- 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 image_resize
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
$image = wp_load_image( $file );
if ( !is_resource( $image ) )
return new WP_Error('error_loading_image', $image);
Method image_constrain_size_for_editor
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
function image_constrain_size_for_editor($width, $height, $size = 'medium') {
global $content_width, $_wp_additional_image_sizes;
if ( is_array($size) ) {
$max_width = $size[0];
Method shortcode
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
function shortcode( $attr, $url = '' ) {
global $post;
if ( empty($url) )
return '';
Method image_get_intermediate_size
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
function image_get_intermediate_size($post_id, $size='thumbnail') {
if ( !is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) )
return false;
// get the best one for a specified set of dimensions
Function image_resize_dimensions
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false) {
if ($orig_w <= 0 || $orig_h <= 0)
return false;
// at least one of dest_w or dest_h must be specific
- 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 image_downsize
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
function image_downsize($id, $size = 'medium') {
if ( !wp_attachment_is_image($id) )
return false;
Method image_resize_dimensions
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false) {
if ($orig_w <= 0 || $orig_h <= 0)
return false;
// at least one of dest_w or dest_h must be specific
Function image_downsize
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
function image_downsize($id, $size = 'medium') {
if ( !wp_attachment_is_image($id) )
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
Method image_resize
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
Method image_resize_dimensions
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false) {
Method get_image_tag
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function get_image_tag($id, $alt, $title, $align, $size='medium') {
Avoid too many return
statements within this method. Open
return apply_filters( 'embed_oembed_html', $html, $url, $attr );
Avoid too many return
statements within this method. Open
return $this->maybe_make_link( $url );
Avoid too many return
statements within this method. Open
return function_exists('imagecreatefrompng');
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return $destfilename;
Avoid too many return
statements within this method. Open
return $data;
Avoid too many return
statements within this method. Open
return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
Avoid too many return
statements within this method. Open
return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
Avoid too many return
statements within this method. Open
return function_exists('imagecreatefromgif');
Identical blocks of code found in 2 locations. Consider refactoring. Open
foreach ( $this->handlers as $priority => $handlers ) {
foreach ( $handlers as $id => $handler ) {
if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) {
if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) )
return apply_filters( 'embed_handler_html', $return, $url, $attr );
- 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 113.
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