Conditions | 8 |
Paths | 4 |
Total Lines | 52 |
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 |
||
123 | function get_track_list( $feed, $quantity = 5 ) { |
||
124 | if ( empty( $feed ) ) { |
||
125 | return new WP_Error( 'missing_feed', __( 'Podcast audio RSS feed missing.', 'jetpack' ) ); |
||
|
|||
126 | } |
||
127 | |||
128 | $rss = fetch_feed( $feed ); |
||
129 | |||
130 | if ( is_wp_error( $rss ) ) { |
||
131 | return new WP_Error( 'invalid_url', __( 'Your podcast couldn\'t be embedded. Please double check your URL.', 'jetpack' ) ); |
||
132 | } |
||
133 | |||
134 | if ( ! $rss->get_item_quantity() ) { |
||
135 | return new WP_Error( 'no_tracks', __( 'Podcast audio RSS feed has no tracks.', 'jetpack' ) ); |
||
136 | } |
||
137 | |||
138 | $episodes = $rss->get_items( 0, $quantity ); |
||
139 | |||
140 | $track_list = array_map( |
||
141 | function( $episode ) { |
||
142 | |||
143 | $url = ! empty( $episode->data['child']['']['enclosure'][0]['attribs']['']['url'] ) ? $episode->data['child']['']['enclosure'][0]['attribs']['']['url'] : null; |
||
144 | $type = ! empty( $episode->data['child']['']['enclosure'][0]['attribs']['']['type'] ) ? $episode->data['child']['']['enclosure'][0]['attribs']['']['type'] : null; |
||
145 | |||
146 | // If there is no type return an empty array as the array entry. We will filter out later. |
||
147 | if ( ! $url ) { |
||
148 | return array(); |
||
149 | } |
||
150 | |||
151 | // Build track data. |
||
152 | $track = array( |
||
153 | 'link' => esc_url( $episode->get_link() ), |
||
154 | 'src' => $url, |
||
155 | 'type' => $type, |
||
156 | 'caption' => '', |
||
157 | 'description' => wp_kses_post( $episode->get_description() ), |
||
158 | 'meta' => array(), |
||
159 | ); |
||
160 | |||
161 | $track['title'] = esc_html( trim( wp_strip_all_tags( $episode->get_title() ) ) ); |
||
162 | |||
163 | if ( empty( $track['title'] ) ) { |
||
164 | $track['title'] = esc_html__( '(no title)', 'jetpack' ); |
||
165 | } |
||
166 | |||
167 | return $track; |
||
168 | }, |
||
169 | $episodes |
||
170 | ); |
||
171 | |||
172 | // Remove empty tracks. |
||
173 | return \array_filter( $track_list ); |
||
174 | } |
||
175 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.