| Conditions | 21 |
| Paths | 900 |
| Total Lines | 129 |
| Code Lines | 89 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 133 | static public function convert_to_legacy_studio( $atts ) { |
||
| 134 | $attr = shortcode_atts( array( |
||
| 135 | 'bg' => '', |
||
| 136 | 'exp' => '', |
||
| 137 | 'exp3' => '', |
||
| 138 | 'h' => '', |
||
| 139 | 'lbu' => '', |
||
| 140 | 'pk' => '', |
||
| 141 | 'pubid' => '', |
||
| 142 | 's' => '', |
||
| 143 | 'surl' => '', |
||
| 144 | 'vid' => '', |
||
| 145 | 'vref' => '', |
||
| 146 | 'w' => '', |
||
| 147 | ), $atts ); |
||
| 148 | |||
| 149 | if ( isset( $attr['pk'] ) ) { |
||
| 150 | $attr['pk'] = rawurlencode( preg_replace( '/[^a-zA-Z0-9!*\'();:@&=+$,\/?#\[\]\-_.~ ]/', '', $attr['pk'] ) ); |
||
| 151 | } |
||
| 152 | |||
| 153 | if ( isset( $attr['bg'] ) ) { |
||
| 154 | $attr['bg'] = preg_replace( '![^-a-zA-Z0-9#]!', '', $attr['bg'] ); |
||
| 155 | } |
||
| 156 | |||
| 157 | $fv = array( |
||
| 158 | 'viewerSecureGatewayURL' => 'https://services.brightcove.com/services/amfgateway', |
||
| 159 | 'servicesURL' => 'http://services.brightcove.com/services', |
||
| 160 | 'cdnURL' => 'http://admin.brightcove.com', |
||
| 161 | 'autoStart' => 'false', |
||
| 162 | ); |
||
| 163 | |||
| 164 | $js_tld = 'com'; |
||
| 165 | $src = ''; |
||
| 166 | $name = 'flashObj'; |
||
| 167 | $html5 = false; |
||
| 168 | |||
| 169 | if ( isset( $attr['exp3'] ) ) { |
||
| 170 | if ( isset( $attr['surl'] ) && strpos( $attr['surl'], 'brightcove.co.jp' ) ) { |
||
| 171 | $js_tld = 'co.jp'; |
||
| 172 | } |
||
| 173 | if ( ! isset( $attr['surl'] ) || ! preg_match( '#^https?://(?:[a-z\d-]+\.)*brightcove\.(?:com|co\.jp)/#', $attr['surl'] ) ) { |
||
| 174 | $attr['surl'] = 'http://c.brightcove.com/services'; |
||
| 175 | } |
||
| 176 | |||
| 177 | $attr['exp3'] = intval( $attr['exp3'] ); |
||
| 178 | $attr['pubid'] = intval( $attr['pubid'] ); |
||
| 179 | $attr['vid'] = intval( $attr['vid'] ); |
||
| 180 | |||
| 181 | $fv['servicesURL'] = $attr['surl']; |
||
| 182 | $fv['playerID'] = $attr['exp3']; |
||
| 183 | $fv['domain'] = 'embed'; |
||
| 184 | $fv['videoID'] = intval( $attr['vid'] ); |
||
| 185 | |||
| 186 | $src = sprintf( '%s/viewer/federated_f9/%s?isVid=1&isUI=1&publisherID=%s', |
||
| 187 | $attr['surl'], |
||
| 188 | $attr['exp3'], |
||
| 189 | $attr['pubid'] |
||
| 190 | ); |
||
| 191 | $html5 = true; |
||
| 192 | } elseif ( isset( $attr['exp'] ) ) { |
||
| 193 | $attr['exp'] = intval( $attr['exp'] ); |
||
| 194 | $src = 'http://services.brightcove.com/services/viewer/federated_f8/' . $attr['exp']; |
||
| 195 | if ( $attr['vid'] ) { |
||
| 196 | $fv['videoId'] = $attr['vid']; |
||
| 197 | } else if ( $attr['vref'] ) { |
||
| 198 | $fv['videoRef'] = $attr['vref']; |
||
| 199 | } |
||
| 200 | |||
| 201 | $fv['playerId'] = $attr['exp']; |
||
| 202 | $fv['domain'] = 'embed'; |
||
| 203 | } else { |
||
| 204 | return '<small>brightcove error: missing required parameter exp or exp3</small>'; |
||
| 205 | } |
||
| 206 | |||
| 207 | if ( ! empty( $attr['lbu'] ) ) { |
||
| 208 | $fv['linkBaseURL'] = $attr['lbu']; |
||
| 209 | } |
||
| 210 | |||
| 211 | $flashvars = trim( add_query_arg( array_map( 'urlencode', $fv ), '' ), '?' ); |
||
| 212 | |||
| 213 | $width = $height = null; |
||
| 214 | if ( ! empty( $attr['w'] ) && ! empty( $attr['h'] ) ) { |
||
| 215 | $w = abs( (int) $attr['w'] ); |
||
| 216 | $h = abs( (int) $attr['h'] ); |
||
| 217 | if ( $w && $h ) { |
||
| 218 | $width = $w; |
||
| 219 | $height = $h; |
||
| 220 | } |
||
| 221 | } elseif ( empty( $attr['s'] ) || 'l' === $attr['s'] ) { |
||
| 222 | $width = '480'; |
||
| 223 | $height = '360'; |
||
| 224 | } |
||
| 225 | |||
| 226 | if ( empty( $width ) || empty( $height ) ) { |
||
| 227 | $width = '280'; |
||
| 228 | $height = '210'; |
||
| 229 | } |
||
| 230 | |||
| 231 | if ( $html5 ) { |
||
| 232 | wp_enqueue_script( 'brightcove-loader', plugins_url( 'js/brightcove.js', __FILE__ ), array( 'jquery' ), 20121127, false ); |
||
| 233 | wp_localize_script( 'brightcove-loader', 'brightcoveData', array( |
||
| 234 | 'tld' => esc_js( $js_tld ) |
||
| 235 | ) ); |
||
| 236 | |||
| 237 | return ' |
||
| 238 | <object id="myExperience" class="BrightcoveExperience"> |
||
| 239 | <param name="bgcolor" value="' . esc_attr( $attr['bg'] ) . '" /> |
||
| 240 | <param name="width" value="' . esc_attr( $width ) . '" /> |
||
| 241 | <param name="height" value="' . esc_attr( $height ) . '" /> |
||
| 242 | <param name="playerID" value="' . esc_attr( $attr['exp3'] ) . '" /> |
||
| 243 | <param name="@videoPlayer" value="' . esc_attr( $attr['vid'] ) . '" /> |
||
| 244 | <param name="playerKey" value="' . esc_attr( $attr['pk'] ) . '" /> |
||
| 245 | <param name="isVid" value="1" /> |
||
| 246 | <param name="isUI" value="1" /> |
||
| 247 | <param name="dynamicStreaming" value="true" /> |
||
| 248 | <param name="autoStart" value="false" /> |
||
| 249 | <param name="secureConnections" value="true" /> |
||
| 250 | <param name="secureHTMLConnections" value="true" /> |
||
| 251 | </object>'; |
||
| 252 | } |
||
| 253 | |||
| 254 | return sprintf( '<embed src="%s" bgcolor="#FFFFFF" flashvars="%s" base="http://admin.brightcove.com" name="%s" width="%s" height="%s" allowFullScreen="true" seamlesstabbing="false" type="application/x-shockwave-flash" swLiveConnect="true" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" />', |
||
| 255 | esc_url( $src ), |
||
| 256 | $flashvars, |
||
| 257 | esc_attr( $name ), |
||
| 258 | esc_attr( $width ), |
||
| 259 | esc_attr( $height ) |
||
| 260 | ); |
||
| 261 | } |
||
| 262 | } |
||
| 265 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.