Conditions | 1 |
Paths | 1 |
Total Lines | 87 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
185 | function setup_cpts() { |
||
186 | |||
187 | /* |
||
188 | * ORDER data structure. holds: |
||
189 | * title = customer_name | 4xproduct_name |
||
190 | * excerpt = customer_name + customer contact info + customer notes from paypal form |
||
191 | * metadata: |
||
192 | * spay_paypal_id - paypal id of transaction |
||
193 | * spay_status |
||
194 | * spay_product_id - post_id of bought product |
||
195 | * spay_quantity - quantity of product |
||
196 | * spay_price - item price at the time of purchase |
||
197 | * spay_customer_email - customer email |
||
198 | * ... (WIP) |
||
199 | */ |
||
200 | $order_capabilities = array( |
||
201 | 'edit_post' => 'edit_posts', |
||
202 | 'read_post' => 'read_private_posts', |
||
203 | 'delete_post' => 'delete_posts', |
||
204 | 'edit_posts' => 'edit_posts', |
||
205 | 'edit_others_posts' => 'edit_others_posts', |
||
206 | 'publish_posts' => 'publish_posts', |
||
207 | 'read_private_posts' => 'read_private_posts', |
||
208 | ); |
||
209 | $order_args = array( |
||
210 | 'label' => esc_html__( 'Order', 'jetpack' ), |
||
211 | 'description' => esc_html__( 'Simple Payments orders', 'jetpack' ), |
||
212 | 'supports' => array( 'custom-fields', 'excerpt' ), |
||
213 | 'hierarchical' => false, |
||
214 | 'public' => false, |
||
215 | 'show_ui' => false, |
||
216 | 'show_in_menu' => false, |
||
217 | 'show_in_admin_bar' => false, |
||
218 | 'show_in_nav_menus' => false, |
||
219 | 'can_export' => true, |
||
220 | 'has_archive' => false, |
||
221 | 'exclude_from_search' => true, |
||
222 | 'publicly_queryable' => false, |
||
223 | 'rewrite' => false, |
||
224 | 'capabilities' => $order_capabilities, |
||
225 | 'show_in_rest' => true, |
||
226 | ); |
||
227 | register_post_type( self::$post_type_order, $order_args ); |
||
228 | |||
229 | /* |
||
230 | * PRODUCT data structure. Holds: |
||
231 | * title - title |
||
232 | * content - description |
||
233 | * thumbnail - image |
||
234 | * metadata: |
||
235 | * spay_price - price |
||
236 | * spay_formatted_price |
||
237 | * spay_currency - currency code |
||
238 | * spay_cta - text with "Buy" or other CTA |
||
239 | * spay_email - paypal email |
||
240 | * spay_multiple - allow for multiple items |
||
241 | * spay_status - status. { enabled | disabled } |
||
242 | */ |
||
243 | $product_capabilities = array( |
||
244 | 'edit_post' => 'edit_posts', |
||
245 | 'read_post' => 'read_private_posts', |
||
246 | 'delete_post' => 'delete_posts', |
||
247 | 'edit_posts' => 'edit_posts', |
||
248 | 'edit_others_posts' => 'edit_others_posts', |
||
249 | 'publish_posts' => 'publish_posts', |
||
250 | 'read_private_posts' => 'read_private_posts', |
||
251 | ); |
||
252 | $product_args = array( |
||
253 | 'label' => esc_html__( 'Product', 'jetpack' ), |
||
254 | 'description' => esc_html__( 'Simple Payments products', 'jetpack' ), |
||
255 | 'supports' => array( 'title', 'editor','thumbnail', 'custom-fields' ), |
||
256 | 'hierarchical' => false, |
||
257 | 'public' => false, |
||
258 | 'show_ui' => false, |
||
259 | 'show_in_menu' => false, |
||
260 | 'show_in_admin_bar' => false, |
||
261 | 'show_in_nav_menus' => false, |
||
262 | 'can_export' => true, |
||
263 | 'has_archive' => false, |
||
264 | 'exclude_from_search' => true, |
||
265 | 'publicly_queryable' => false, |
||
266 | 'rewrite' => false, |
||
267 | 'capabilities' => $product_capabilities, |
||
268 | 'show_in_rest' => true, |
||
269 | ); |
||
270 | register_post_type( self::$post_type_product, $product_args ); |
||
271 | } |
||
272 | |||
275 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.