Conditions | 6 |
Paths | 6 |
Total Lines | 60 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
120 | public function delete( $slug, $echo = false ){ |
||
121 | |||
122 | $delete = new Delete; |
||
123 | |||
124 | // Make sure that the current user is logged in & has full permissions. |
||
125 | if ( !$delete->user_can_delete() ){ |
||
126 | return; |
||
127 | } |
||
128 | |||
129 | // Check that $cptslg has a string. |
||
130 | if ( empty( $slug ) ){ |
||
131 | return; |
||
132 | } |
||
133 | |||
134 | // Query for our terms |
||
135 | $args = array( |
||
136 | 'hide_empty' => false, |
||
137 | 'meta_query' => array( |
||
138 | array( |
||
139 | 'key' => 'evans_test_content', |
||
140 | 'value' => '__test__', |
||
141 | 'compare' => '=' |
||
142 | ) |
||
143 | ) |
||
144 | ); |
||
145 | |||
146 | $terms = get_terms( $slug, $args ); |
||
147 | |||
148 | if ( !empty( $terms ) ){ |
||
149 | |||
150 | $events = array(); |
||
151 | |||
152 | foreach ( $terms as $term ){ |
||
153 | |||
154 | if ( $echo === true ){ |
||
155 | $events[] = array( |
||
156 | 'type' => 'deleted', |
||
157 | 'pid' => $term->term_id, |
||
158 | 'post_type' => $slug, |
||
159 | 'link' => '' |
||
160 | ); |
||
161 | } |
||
162 | |||
163 | // Delete our term |
||
164 | wp_delete_term( $term->term_id, $slug ); |
||
165 | |||
166 | } |
||
167 | |||
168 | $taxonomy = get_taxonomy( $slug ); |
||
169 | |||
170 | $events[] = array( |
||
171 | 'type' => 'general', |
||
172 | 'message' => __( 'Deleted', 'otm-test-content' ) . ' ' . $taxonomy->labels->name |
||
173 | ); |
||
174 | |||
175 | echo \json_encode( $events ); |
||
176 | |||
177 | } |
||
178 | |||
179 | } |
||
180 | |||
182 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.