| Conditions | 13 |
| Paths | 100 |
| Total Lines | 106 |
| Lines | 6 |
| Ratio | 5.66 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 80 | public function shortcode_callback( $attr ) { |
||
| 81 | global $content_width; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * We only accept GUIDs as a first unnamed argument. |
||
| 85 | */ |
||
| 86 | $guid = isset( $attr[0] ) ? $attr[0] : null; |
||
| 87 | |||
| 88 | if ( isset( $attr['postid'] ) ) { |
||
| 89 | $guid = get_post_meta( $attr['postid'], 'videopress_guid', true ); |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Make sure the GUID passed in matches how actual GUIDs are formatted. |
||
| 94 | */ |
||
| 95 | if ( ! videopress_is_valid_guid( $guid ) ) { |
||
| 96 | return ''; |
||
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Set the defaults |
||
| 101 | */ |
||
| 102 | $defaults = array( |
||
| 103 | 'w' => 0, // Width of the video player, in pixels |
||
| 104 | 'at' => 0, // How many seconds in to initially seek to |
||
| 105 | 'hd' => true, // Whether to display a high definition version |
||
| 106 | 'loop' => false, // Whether to loop the video repeatedly |
||
| 107 | 'freedom' => false, // Whether to use only free/libre codecs |
||
| 108 | 'autoplay' => false, // Whether to autoplay the video on load |
||
| 109 | 'permalink' => true, // Whether to display the permalink to the video |
||
| 110 | 'flashonly' => false, // Whether to support the Flash player exclusively |
||
| 111 | 'defaultlangcode' => false, // Default language code |
||
| 112 | ); |
||
| 113 | |||
| 114 | $attr = shortcode_atts( $defaults, $attr, 'videopress' ); |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Cast the attributes, post-input. |
||
| 118 | */ |
||
| 119 | $attr['width'] = absint( $attr['w'] ); |
||
| 120 | $attr['hd'] = (bool) $attr['hd']; |
||
| 121 | $attr['freedom'] = (bool) $attr['freedom']; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * If the provided width is less than the minimum allowed |
||
| 125 | * width, or greater than `$content_width` ignore. |
||
| 126 | */ |
||
| 127 | if ( $attr['width'] < VIDEOPRESS_MIN_WIDTH ) { |
||
| 128 | $attr['width'] = 0; |
||
| 129 | View Code Duplication | } elseif ( isset( $content_width ) && $content_width > VIDEOPRESS_MIN_WIDTH && $attr['width'] > $content_width ) { |
|
| 130 | $attr['width'] = 0; |
||
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * If there was an invalid or unspecified width, set the width equal to the theme's `$content_width`. |
||
| 135 | */ |
||
| 136 | View Code Duplication | if ( 0 === $attr['width'] && isset( $content_width ) && $content_width >= VIDEOPRESS_MIN_WIDTH ) { |
|
| 137 | $attr['width'] = $content_width; |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * If the width isn't an even number, reduce it by one (making it even). |
||
| 142 | */ |
||
| 143 | if ( 1 === ( $attr['width'] % 2 ) ) { |
||
| 144 | $attr['width'] --; |
||
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Filter the default VideoPress shortcode options. |
||
| 149 | * |
||
| 150 | * @module videopress |
||
| 151 | * |
||
| 152 | * @since 2.5.0 |
||
| 153 | * |
||
| 154 | * @param array $args Array of VideoPress shortcode options. |
||
| 155 | */ |
||
| 156 | $options = apply_filters( |
||
| 157 | 'videopress_shortcode_options', |
||
| 158 | array( |
||
| 159 | 'at' => (int) $attr['at'], |
||
| 160 | 'hd' => $attr['hd'], |
||
| 161 | 'loop' => $attr['loop'], |
||
| 162 | 'freedom' => $attr['freedom'], |
||
| 163 | 'autoplay' => $attr['autoplay'], |
||
| 164 | 'permalink' => $attr['permalink'], |
||
| 165 | 'force_flash' => (bool) $attr['flashonly'], |
||
| 166 | 'defaultlangcode' => $attr['defaultlangcode'], |
||
| 167 | 'forcestatic' => false, // This used to be a displayed option, but now is only |
||
| 168 | // accessible via the `videopress_shortcode_options` filter. |
||
| 169 | ) |
||
| 170 | ); |
||
| 171 | |||
| 172 | // Register VideoPress scripts |
||
| 173 | wp_register_script( 'videopress', 'https://v0.wordpress.com/js/videopress.js', array( 'jquery', 'swfobject' ), '1.09' ); |
||
| 174 | |||
| 175 | require_once dirname( __FILE__ ) . '/class.videopress-video.php'; |
||
| 176 | require_once dirname( __FILE__ ) . '/class.videopress-player.php'; |
||
| 177 | |||
| 178 | $player = new VideoPress_Player( $guid, $attr['width'], $options ); |
||
| 179 | |||
| 180 | if ( is_feed() ) { |
||
| 181 | return $player->asXML(); |
||
| 182 | } else { |
||
| 183 | return $player->asHTML(); |
||
| 184 | } |
||
| 185 | } |
||
| 186 | |||
| 278 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: