Conditions | 15 |
Paths | 14 |
Total Lines | 40 |
Code Lines | 23 |
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 |
||
16 | public function __construct( $query = false, $posts_class = 'TimberPost' ) { |
||
17 | add_action( 'pre_get_posts', array($this, 'fix_number_posts_wp_quirk' )); |
||
18 | if ( $posts_class ) |
||
19 | $this->_posts_class = $posts_class; |
||
20 | |||
21 | if ( is_a( $query, 'WP_Query' ) ) { |
||
22 | // We got a full-fledged WP Query, look no further! |
||
23 | $the_query = $query; |
||
24 | |||
25 | } elseif ( false === $query ) { |
||
26 | // If query is explicitly set to false, use the main loop |
||
27 | global $wp_query; |
||
28 | $the_query =& $wp_query; |
||
29 | //if we're on a custom posts page? |
||
30 | $the_query = self::handle_maybe_custom_posts_page($the_query); |
||
31 | } elseif ( TimberHelper::is_array_assoc( $query ) || ( is_string( $query ) && strstr( $query, '=' ) ) ) { |
||
|
|||
32 | // We have a regularly formed WP query string or array to use |
||
33 | $the_query = new WP_Query( $query ); |
||
34 | |||
35 | } elseif ( is_numeric( $query ) || is_string( $query ) ) { |
||
36 | // We have what could be a post name or post ID to pull out |
||
37 | $the_query = self::get_query_from_string( $query ); |
||
38 | |||
39 | } elseif ( is_array( $query ) && count( $query ) && ( is_integer( $query[0] ) || is_string( $query[0] ) ) ) { |
||
40 | // We have a list of pids (post IDs) to extract from |
||
41 | $the_query = self::get_query_from_array_of_ids( $query ); |
||
42 | } elseif ( is_array($query) && empty($query)) { |
||
43 | // it's an empty array |
||
44 | $the_query = array(); |
||
45 | } else { |
||
46 | TimberHelper::error_log( 'I have failed you! in ' . basename( __FILE__ ) . '::' . __LINE__ ); |
||
47 | TimberHelper::error_log( $query ); |
||
48 | |||
49 | // We have failed hard, at least let get something. |
||
50 | $the_query = new WP_Query(); |
||
51 | } |
||
52 | |||
53 | $this->_query = $the_query; |
||
54 | |||
55 | } |
||
56 | |||
157 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: