| 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 |
||
| 189 | function setup_cpts() { |
||
| 190 | |||
| 191 | /* |
||
| 192 | * ORDER data structure. holds: |
||
| 193 | * title = customer_name | 4xproduct_name |
||
| 194 | * excerpt = customer_name + customer contact info + customer notes from paypal form |
||
| 195 | * metadata: |
||
| 196 | * spay_paypal_id - paypal id of transaction |
||
| 197 | * spay_status |
||
| 198 | * spay_product_id - post_id of bought product |
||
| 199 | * spay_quantity - quantity of product |
||
| 200 | * spay_price - item price at the time of purchase |
||
| 201 | * spay_customer_email - customer email |
||
| 202 | * ... (WIP) |
||
| 203 | */ |
||
| 204 | $order_capabilities = array( |
||
| 205 | 'edit_post' => 'edit_posts', |
||
| 206 | 'read_post' => 'read_private_posts', |
||
| 207 | 'delete_post' => 'delete_posts', |
||
| 208 | 'edit_posts' => 'edit_posts', |
||
| 209 | 'edit_others_posts' => 'edit_others_posts', |
||
| 210 | 'publish_posts' => 'publish_posts', |
||
| 211 | 'read_private_posts' => 'read_private_posts', |
||
| 212 | ); |
||
| 213 | $order_args = array( |
||
| 214 | 'label' => esc_html__( 'Order', 'jetpack' ), |
||
| 215 | 'description' => esc_html__( 'Simple Payments orders', 'jetpack' ), |
||
| 216 | 'supports' => array( 'custom-fields', 'excerpt' ), |
||
| 217 | 'hierarchical' => false, |
||
| 218 | 'public' => false, |
||
| 219 | 'show_ui' => false, |
||
| 220 | 'show_in_menu' => false, |
||
| 221 | 'show_in_admin_bar' => false, |
||
| 222 | 'show_in_nav_menus' => false, |
||
| 223 | 'can_export' => true, |
||
| 224 | 'has_archive' => false, |
||
| 225 | 'exclude_from_search' => true, |
||
| 226 | 'publicly_queryable' => false, |
||
| 227 | 'rewrite' => false, |
||
| 228 | 'capabilities' => $order_capabilities, |
||
| 229 | 'show_in_rest' => true, |
||
| 230 | ); |
||
| 231 | register_post_type( self::$post_type_order, $order_args ); |
||
| 232 | |||
| 233 | /* |
||
| 234 | * PRODUCT data structure. Holds: |
||
| 235 | * title - title |
||
| 236 | * content - description |
||
| 237 | * thumbnail - image |
||
| 238 | * metadata: |
||
| 239 | * spay_price - price |
||
| 240 | * spay_formatted_price |
||
| 241 | * spay_currency - currency code |
||
| 242 | * spay_cta - text with "Buy" or other CTA |
||
| 243 | * spay_email - paypal email |
||
| 244 | * spay_multiple - allow for multiple items |
||
| 245 | * spay_status - status. { enabled | disabled } |
||
| 246 | */ |
||
| 247 | $product_capabilities = array( |
||
| 248 | 'edit_post' => 'edit_posts', |
||
| 249 | 'read_post' => 'read_private_posts', |
||
| 250 | 'delete_post' => 'delete_posts', |
||
| 251 | 'edit_posts' => 'edit_posts', |
||
| 252 | 'edit_others_posts' => 'edit_others_posts', |
||
| 253 | 'publish_posts' => 'publish_posts', |
||
| 254 | 'read_private_posts' => 'read_private_posts', |
||
| 255 | ); |
||
| 256 | $product_args = array( |
||
| 257 | 'label' => esc_html__( 'Product', 'jetpack' ), |
||
| 258 | 'description' => esc_html__( 'Simple Payments products', 'jetpack' ), |
||
| 259 | 'supports' => array( 'title', 'editor','thumbnail', 'custom-fields' ), |
||
| 260 | 'hierarchical' => false, |
||
| 261 | 'public' => false, |
||
| 262 | 'show_ui' => false, |
||
| 263 | 'show_in_menu' => false, |
||
| 264 | 'show_in_admin_bar' => false, |
||
| 265 | 'show_in_nav_menus' => false, |
||
| 266 | 'can_export' => true, |
||
| 267 | 'has_archive' => false, |
||
| 268 | 'exclude_from_search' => true, |
||
| 269 | 'publicly_queryable' => false, |
||
| 270 | 'rewrite' => false, |
||
| 271 | 'capabilities' => $product_capabilities, |
||
| 272 | 'show_in_rest' => true, |
||
| 273 | ); |
||
| 274 | register_post_type( self::$post_type_product, $product_args ); |
||
| 275 | } |
||
| 276 | |||
| 279 |
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.