| Conditions | 5 |
| Paths | 9 |
| Total Lines | 66 |
| Code Lines | 20 |
| 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 |
||
| 105 | return apply_filters( 'getpaid_rest_items_collection_params', $params, $this ); |
||
| 106 | |||
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Get all the WP Query vars that are allowed for the API request. |
||
| 111 | * |
||
| 112 | * @return array |
||
| 113 | */ |
||
| 114 | protected function get_allowed_query_vars() { |
||
| 115 | $vars = array_merge( array( 'type' ), parent::get_allowed_query_vars() ); |
||
| 116 | return apply_filters( 'getpaid_rest_items_allowed_query_vars', $vars, $this ); |
||
| 117 | } |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Determine the allowed query_vars for a get_items() response and |
||
| 121 | * prepare for WP_Query. |
||
| 122 | * |
||
| 123 | * @param array $prepared_args Prepared arguments. |
||
| 124 | * @param WP_REST_Request $request Request object. |
||
| 125 | * @return array $query_args |
||
| 126 | */ |
||
| 127 | protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
||
| 128 | |||
| 129 | $query_args = parent::prepare_items_query( $prepared_args ); |
||
| 130 | |||
| 131 | // Retrieve items by type. |
||
| 132 | if ( isset( $query_args['type'] ) && 'any' != $query_args['type'] ) { |
||
| 133 | |||
| 134 | if ( empty( $query_args['meta_query'] ) ) { |
||
| 135 | $query_args['meta_query'] = array(); |
||
| 136 | } |
||
| 137 | |||
| 138 | $types = wpinv_parse_list( $query_args['type'] ); |
||
| 139 | $query_args['meta_query'][] = array( |
||
| 140 | 'key' => '_wpinv_type', |
||
| 141 | 'value' => implode( ',', $types ), |
||
| 142 | 'compare' => 'IN', |
||
| 143 | ); |
||
| 144 | unset( $query_args['type'] ); |
||
| 145 | |||
| 146 | } |
||
| 147 | |||
| 148 | return apply_filters( 'getpaid_rest_items_prepare_items_query', $query_args, $request, $this ); |
||
| 149 | |||
| 150 | } |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Retrieves a valid list of post statuses. |
||
| 154 | * |
||
| 155 | * @since 1.0.15 |
||
| 156 | * |
||
| 157 | * @return array A list of registered item statuses. |
||
| 158 | */ |
||
| 159 | public function get_post_statuses() { |
||
| 160 | return array( 'draft', 'pending', 'publish' ); |
||
| 161 | } |
||
| 162 | |||
| 163 | } |
||
| 164 |