Complex classes like TimberTermGetter often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TimberTermGetter, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
3 | class TimberTermGetter { |
||
4 | |||
5 | /** |
||
6 | * @param string|array $args |
||
|
|||
7 | * @param array $maybe_args |
||
8 | * @param string $TermClass |
||
9 | * @return mixed |
||
10 | */ |
||
11 | public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm') { |
||
49 | |||
50 | /** |
||
51 | * @param string|array $taxonomies |
||
52 | * @param string|array $args |
||
53 | * @param string $TermClass |
||
54 | * @return mixed |
||
55 | */ |
||
56 | public static function handle_term_query($taxonomies, $args, $TermClass) { |
||
72 | |||
73 | /** |
||
74 | * @param string $query_string |
||
75 | * @return stdClass |
||
76 | */ |
||
77 | protected static function get_term_query_from_query_string($query_string) { |
||
83 | |||
84 | /** |
||
85 | * @param string $taxs |
||
86 | * @return stdClass |
||
87 | */ |
||
88 | protected static function get_term_query_from_string($taxs) { |
||
97 | |||
98 | /** |
||
99 | * @param array $args |
||
100 | * @return stdClass |
||
101 | */ |
||
102 | public static function get_term_query_from_assoc_array($args) { |
||
124 | |||
125 | /** |
||
126 | * @param array $args |
||
127 | * @return stdClass |
||
128 | */ |
||
129 | public static function get_term_query_from_array($args) { |
||
140 | |||
141 | /** |
||
142 | * @param integer[] $args |
||
143 | * @return stdClass |
||
144 | */ |
||
145 | public static function get_term_query_from_array_of_ids($args) { |
||
151 | |||
152 | /** |
||
153 | * @param string[] $args |
||
154 | * @return stdClass |
||
155 | */ |
||
156 | public static function get_term_query_from_array_of_strings($args) { |
||
162 | |||
163 | /** |
||
164 | * @param string|array $taxs |
||
165 | * @return array |
||
166 | */ |
||
167 | private static function correct_taxonomy_names($taxs) { |
||
180 | |||
181 | } |
||
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.