| Conditions | 4 |
| Paths | 6 |
| Total Lines | 62 |
| Code Lines | 18 |
| 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 |
||
| 106 | // Filter collection parameters for the discounts controller. |
||
| 107 | return apply_filters( 'getpaid_rest_discounts_collection_params', $params, $this ); |
||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Determine the allowed query_vars for a get_items() response and |
||
| 112 | * prepare for WP_Query. |
||
| 113 | * |
||
| 114 | * @param array $prepared_args Prepared arguments. |
||
| 115 | * @param WP_REST_Request $request Request object. |
||
| 116 | * @return array $query_args |
||
| 117 | */ |
||
| 118 | protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
||
| 119 | |||
| 120 | $query_args = parent::prepare_items_query( $prepared_args ); |
||
| 121 | |||
| 122 | // Retrieve items by type. |
||
| 123 | if ( ! in_array( 'any', $request['type'] ) ) { |
||
|
|
|||
| 124 | |||
| 125 | if ( empty( $query_args['meta_query'] ) ) { |
||
| 126 | $query_args['meta_query'] = array(); |
||
| 127 | } |
||
| 128 | |||
| 129 | $query_args['meta_query'][] = array( |
||
| 130 | 'key' => '_wpi_discount_type', |
||
| 131 | 'value' => implode( ',', $request['type'] ), |
||
| 132 | 'compare' => 'IN', |
||
| 133 | ); |
||
| 134 | |||
| 135 | } |
||
| 136 | |||
| 137 | return apply_filters( 'getpaid_rest_discounts_prepare_items_query', $query_args, $request, $this ); |
||
| 138 | |||
| 139 | } |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Retrieves a valid list of post statuses. |
||
| 143 | * |
||
| 144 | * @since 1.0.15 |
||
| 145 | * |
||
| 146 | * @return array A list of registered item statuses. |
||
| 147 | */ |
||
| 148 | public function get_post_statuses() { |
||
| 149 | return array( 'publish', 'pending', 'draft', 'expired' ); |
||
| 150 | } |
||
| 151 | |||
| 152 | } |
||
| 153 |