Conditions | 15 |
Paths | 36 |
Total Lines | 38 |
Code Lines | 26 |
Lines | 0 |
Ratio | 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 |
||
11 | public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm') { |
||
12 | if ( is_string($maybe_args) && !strstr($maybe_args, '=') ) { |
||
13 | //the user is sending the $TermClass in the second argument |
||
14 | $TermClass = $maybe_args; |
||
15 | } |
||
16 | if ( is_string($maybe_args) && strstr($maybe_args, '=') ) { |
||
17 | parse_str($maybe_args, $maybe_args); |
||
18 | } |
||
19 | if ( is_string($args) && strstr($args, '=') ) { |
||
20 | //a string and a query string! |
||
21 | $parsed = self::get_term_query_from_query_string($args); |
||
22 | if ( is_array($maybe_args) ) { |
||
23 | $parsed->args = array_merge($parsed->args, $maybe_args); |
||
24 | } |
||
25 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
||
26 | } else if ( is_string($args) ) { |
||
27 | //its just a string with a single taxonomy |
||
28 | $parsed = self::get_term_query_from_string($args); |
||
29 | if ( is_array($maybe_args) ) { |
||
30 | $parsed->args = array_merge($parsed->args, $maybe_args); |
||
31 | } |
||
32 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
||
33 | } else if ( is_array($args) && TimberHelper::is_array_assoc($args) ) { |
||
34 | //its an associative array, like a good ole query |
||
35 | $parsed = self::get_term_query_from_assoc_array($args); |
||
36 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
||
37 | } else if ( is_array($args) ) { |
||
38 | //its just an array of strings or IDs (hopefully) |
||
39 | $parsed = self::get_term_query_from_array($args); |
||
40 | if ( is_array($maybe_args) ) { |
||
41 | $parsed->args = array_merge($parsed->args, $maybe_args); |
||
42 | } |
||
43 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
||
44 | } else if ( is_null($args) ) { |
||
45 | return self::handle_term_query(get_taxonomies(), array(), $TermClass); |
||
46 | } |
||
47 | return null; |
||
48 | } |
||
49 | |||
182 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.