Conditions | 22 |
Paths | 1154 |
Total Lines | 90 |
Code Lines | 52 |
Lines | 9 |
Ratio | 10 % |
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 |
||
26 | function slideshare_shortcode( $atts ) { |
||
27 | global $content_width; |
||
28 | |||
29 | $params = shortcode_new_to_old_params( $atts ); |
||
30 | parse_str( $params, $arguments ); |
||
31 | |||
32 | if ( empty( $arguments ) ) { |
||
33 | return '<!-- SlideShare error: no arguments -->'; |
||
34 | } |
||
35 | |||
36 | $attr = shortcode_atts( |
||
37 | array( |
||
38 | 'id' => '', |
||
39 | 'w' => '', |
||
40 | 'h' => '', |
||
41 | 'fb' => '', |
||
42 | 'mw' => '', |
||
43 | 'mh' => '', |
||
44 | 'sc' => '', |
||
45 | 'pro' => '', |
||
46 | 'style' => '', |
||
47 | ), $arguments |
||
48 | ); |
||
49 | |||
50 | // check that the Slideshare ID contains letters, numbers and query strings |
||
51 | $pattern = '/[^-_a-zA-Z0-9?=&]/'; |
||
52 | if ( empty( $attr['id'] ) || preg_match( $pattern, $attr['id'] ) ) { |
||
53 | return '<!-- SlideShare error: id is missing or has illegal characters -->'; |
||
54 | } |
||
55 | |||
56 | // check the width/height |
||
57 | $w = $attr['w']; |
||
58 | if ( empty( $w ) && ! empty( $content_width ) ) { |
||
59 | $w = intval( $content_width ); |
||
60 | } elseif ( ! ( $w = intval( $w ) ) || $w < 300 || $w > 1600 ) { |
||
61 | $w = 425; |
||
62 | } else { |
||
63 | $w = intval( $w ); |
||
64 | } |
||
65 | |||
66 | $h = ceil( $w * 348 / 425 ); // Note: user-supplied height is ignored. |
||
67 | |||
68 | if ( isset( $attr['pro'] ) && $attr['pro'] ) { |
||
69 | $source = 'https://www.slideshare.net/slidesharepro/' . $attr['id']; |
||
70 | } else { |
||
71 | $source = 'https://www.slideshare.net/slideshow/embed_code/' . $attr['id']; |
||
72 | } |
||
73 | |||
74 | if ( isset( $rel ) ) { |
||
|
|||
75 | $source = add_query_arg( 'rel', intval( $rel ), $source ); |
||
76 | } |
||
77 | |||
78 | if ( isset( $startSlide ) ) { |
||
79 | $source = add_query_arg( 'startSlide', intval( $startSlide ), $source ); |
||
80 | } |
||
81 | |||
82 | $player = sprintf( "<iframe src='%s' width='%d' height='%d'", esc_url( $source ), $w, $h ); |
||
83 | |||
84 | // check the frameborder |
||
85 | View Code Duplication | if ( ! empty( $attr['fb'] ) || '0' === $attr['fb'] ) { |
|
86 | $player .= " frameborder='" . intval( $attr['fb'] ) . "'"; |
||
87 | } |
||
88 | |||
89 | // check the margin width; if not empty, cast as int |
||
90 | View Code Duplication | if ( ! empty( $attr['mw'] ) || '0' === $attr['mw'] ) { |
|
91 | $player .= " marginwidth='" . intval( $attr['mw'] ) . "'"; |
||
92 | } |
||
93 | |||
94 | // check the margin height, if not empty, cast as int |
||
95 | View Code Duplication | if ( ! empty( $attr['mh'] ) || '0' === $attr['mh'] ) { |
|
96 | $player .= " marginheight='" . intval( $attr['mh'] ) . "'"; |
||
97 | } |
||
98 | |||
99 | if ( ! empty( $attr['style'] ) ) { |
||
100 | $player .= " style='" . esc_attr( $attr['style'] ) . "'"; |
||
101 | } |
||
102 | |||
103 | // check the scrollbar; cast as a lowercase string for comparison |
||
104 | if ( ! empty( $attr['sc'] ) ) { |
||
105 | $sc = strtolower( $attr['sc'] ); |
||
106 | |||
107 | if ( in_array( $sc, array( 'yes', 'no' ) ) ) { |
||
108 | $player .= " scrolling='" . $sc . "'"; |
||
109 | } |
||
110 | } |
||
111 | |||
112 | $player .= ' allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>'; |
||
113 | |||
114 | return $player; |
||
115 | } |
This check looks for calls to
isset(...)
orempty()
on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.