Conditions | 11 |
Paths | 25 |
Total Lines | 71 |
Code Lines | 47 |
Lines | 4 |
Ratio | 5.63 % |
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 |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Set the defaults |
||
38 | */ |
||
39 | $defaults = array( |
||
40 | 'w' => 0, // Width of the video player, in pixels |
||
41 | 'at' => 0, // How many seconds in to initially seek to |
||
42 | 'hd' => false, // Whether to display a high definition version |
||
43 | 'loop' => false, // Whether to loop the video repeatedly |
||
44 | 'freedom' => false, // Whether to use only free/libre codecs |
||
45 | 'autoplay' => false, // Whether to autoplay the video on load |
||
46 | 'permalink' => true, // Whether to display the permalink to the video |
||
47 | 'flashonly' => false, // Whether to support the Flash player exclusively |
||
48 | 'defaultlangcode' => false, // Default language code |
||
49 | ); |
||
50 | |||
51 | $attr = shortcode_atts( $defaults, $attr, 'videopress' ); |
||
52 | |||
53 | /** |
||
54 | * Cast the attributes, post-input. |
||
55 | */ |
||
56 | $attr['width'] = absint( $attr['w'] ); |
||
57 | $attr['hd'] = (bool) $attr['hd']; |
||
58 | $attr['freedom'] = (bool) $attr['freedom']; |
||
59 | |||
60 | /** |
||
61 | * If the provided width is less than the minimum allowed |
||
62 | * width, or greater than `$content_width` ignore. |
||
63 | */ |
||
64 | if ( $attr['width'] < VIDEOPRESS_MIN_WIDTH ) { |
||
65 | $attr['width'] = 0; |
||
66 | View Code Duplication | } elseif ( isset( $content_width ) && $content_width > VIDEOPRESS_MIN_WIDTH && $attr['width'] > $content_width ) { |
|
67 | $attr['width'] = 0; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * If there was an invalid or unspecified width, set the width equal to the theme's `$content_width`. |
||
72 | */ |
||
73 | View Code Duplication | if ( $attr['width'] === 0 && isset( $content_width ) && $content_width > VIDEOPRESS_MIN_WIDTH ) { |
|
74 | $attr['width'] = $content_width; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * If the width isn't an even number, reduce it by one (making it even). |
||
79 | */ |
||
80 | if ( ( $attr['width'] % 2 ) === 1 ) { |
||
81 | $attr['width'] --; |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Filter the default VideoPress shortcode options. |
||
86 | * |
||
87 | * @module videopress |
||
88 | * |
||
89 | * @since 2.5.0 |
||
90 | * |
||
91 | * @param array $args Array of VideoPress shortcode options. |
||
92 | */ |
||
93 | $options = apply_filters( 'videopress_shortcode_options', array( |
||
94 | 'at' => (int) $attr['at'], |
||
95 | 'hd' => $attr['hd'], |
||
96 | 'loop' => $attr['autoplay'] || $attr['loop'], |
||
97 | 'freedom' => $attr['freedom'], |
||
98 | 'autoplay' => $attr['autoplay'], |
||
99 | 'permalink' => $attr['permalink'], |
||
100 | 'force_flash' => (bool) $attr['flashonly'], |
||
101 | 'defaultlangcode' => $attr['defaultlangcode'], |
||
102 | 'forcestatic' => false, // This used to be a displayed option, but now is only |
||
103 | // accessible via the `videopress_shortcode_options` filter. |
||
104 | ) ); |
||
105 | |||
139 | add_filter( 'oembed_fetch_url', 'videopress_add_oembed_for_parameter' ); |