| Conditions | 14 |
| Paths | 100 |
| Total Lines | 103 |
| Code Lines | 47 |
| Lines | 6 |
| Ratio | 5.83 % |
| 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 |
||
| 21 | add_filter('wp_video_shortcode_override', array( $this, 'video_shortcode_override' ), 10, 4); |
||
| 22 | |||
| 23 | add_filter( 'oembed_fetch_url', array( $this, 'add_oembed_for_parameter' ) ); |
||
| 24 | |||
| 25 | $this->add_video_embed_hander(); |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @return VideoPress_Shortcode |
||
| 30 | */ |
||
| 31 | public static function initialize() { |
||
| 32 | if ( ! isset ( self::$instance ) ) { |
||
| 33 | self::$instance = new self(); |
||
| 34 | } |
||
| 35 | |||
| 36 | return self::$instance; |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Translate a 'videopress' or 'wpvideo' shortcode and arguments into a video player display. |
||
| 41 | * |
||
| 42 | * Expected input formats: |
||
| 43 | * |
||
| 44 | * [videopress OcobLTqC] |
||
| 45 | * [wpvideo OcobLTqC] |
||
| 46 | * |
||
| 47 | * @link http://codex.wordpress.org/Shortcode_API Shortcode API |
||
| 48 | * @param array $attr shortcode attributes |
||
| 49 | * @return string HTML markup or blank string on fail |
||
| 50 | */ |
||
| 51 | public function shortcode_callback( $attr ) { |
||
| 52 | global $content_width; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * We only accept GUIDs as a first unnamed argument. |
||
| 56 | */ |
||
| 57 | $guid = isset( $attr[0] ) ? $attr[0] : null; |
||
| 58 | |||
| 59 | if ( isset( $attr['postid'] ) ) { |
||
| 60 | $guid = get_post_meta( $attr['postid'], 'videopress_guid', true ); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Make sure the GUID passed in matches how actual GUIDs are formatted. |
||
| 65 | */ |
||
| 66 | if ( ! videopress_is_valid_guid( $guid ) ) { |
||
| 67 | return ''; |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Set the defaults |
||
| 72 | */ |
||
| 73 | $defaults = array( |
||
| 74 | 'w' => 0, // Width of the video player, in pixels |
||
| 75 | 'at' => 0, // How many seconds in to initially seek to |
||
| 76 | 'hd' => true, // Whether to display a high definition version |
||
| 77 | 'loop' => false, // Whether to loop the video repeatedly |
||
| 78 | 'freedom' => false, // Whether to use only free/libre codecs |
||
| 79 | 'autoplay' => false, // Whether to autoplay the video on load |
||
| 80 | 'permalink' => true, // Whether to display the permalink to the video |
||
| 81 | 'flashonly' => false, // Whether to support the Flash player exclusively |
||
| 82 | 'defaultlangcode' => false, // Default language code |
||
| 83 | ); |
||
| 84 | |||
| 85 | $attr = shortcode_atts( $defaults, $attr, 'videopress' ); |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Cast the attributes, post-input. |
||
| 89 | */ |
||
| 90 | $attr['width'] = absint( $attr['w'] ); |
||
| 91 | $attr['hd'] = (bool) $attr['hd']; |
||
| 92 | $attr['freedom'] = (bool) $attr['freedom']; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * If the provided width is less than the minimum allowed |
||
| 96 | * width, or greater than `$content_width` ignore. |
||
| 97 | */ |
||
| 98 | if ( $attr['width'] < VIDEOPRESS_MIN_WIDTH ) { |
||
| 99 | $attr['width'] = 0; |
||
| 100 | View Code Duplication | } elseif ( isset( $content_width ) && $content_width > VIDEOPRESS_MIN_WIDTH && $attr['width'] > $content_width ) { |
|
| 101 | $attr['width'] = 0; |
||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * If there was an invalid or unspecified width, set the width equal to the theme's `$content_width`. |
||
| 106 | */ |
||
| 107 | View Code Duplication | if ( 0 === $attr['width'] && isset( $content_width ) && $content_width >= VIDEOPRESS_MIN_WIDTH ) { |
|
| 108 | $attr['width'] = $content_width; |
||
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * If the width isn't an even number, reduce it by one (making it even). |
||
| 113 | */ |
||
| 114 | if ( 1 === ( $attr['width'] % 2 ) ) { |
||
| 115 | $attr['width'] --; |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Filter the default VideoPress shortcode options. |
||
| 120 | * |
||
| 121 | * @module videopress |
||
| 122 | * |
||
| 123 | * @since 2.5.0 |
||
| 124 | * |
||
| 241 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.