| Conditions | 1 |
| Paths | 1 |
| Total Lines | 86 |
| 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 |
||
| 62 | function setup_cpts() { |
||
| 63 | |||
| 64 | /* |
||
| 65 | * ORDER data structure. holds: |
||
| 66 | * title = customer_name | 4xproduct_name |
||
| 67 | * excerpt = customer_name + customer contact info + customer notes from paypal form |
||
| 68 | * metadata: |
||
| 69 | * spay_paypal_id - paypal id of transaction |
||
| 70 | * spay_status |
||
| 71 | * spay_product_id - post_id of bought product |
||
| 72 | * spay_quantity - quantity of product |
||
| 73 | * spay_price - item price at the time of purchase |
||
| 74 | * spay_customer_email - customer email |
||
| 75 | * ... (WIP) |
||
| 76 | */ |
||
| 77 | $order_capabilities = array( |
||
| 78 | 'edit_post' => 'edit_posts', |
||
| 79 | 'read_post' => 'read_private_posts', |
||
| 80 | 'delete_post' => 'delete_posts', |
||
| 81 | 'edit_posts' => 'edit_posts', |
||
| 82 | 'edit_others_posts' => 'edit_others_posts', |
||
| 83 | 'publish_posts' => 'publish_posts', |
||
| 84 | 'read_private_posts' => 'read_private_posts', |
||
| 85 | ); |
||
| 86 | $order_args = array( |
||
| 87 | 'label' => __( 'Order', 'jetpack' ), |
||
| 88 | 'description' => __( 'Simple Payments orders', 'jetpack' ), |
||
| 89 | 'supports' => array( 'custom-fields', 'excerpt' ), |
||
| 90 | 'hierarchical' => false, |
||
| 91 | 'public' => false, |
||
| 92 | 'show_ui' => false, |
||
| 93 | 'show_in_menu' => false, |
||
| 94 | 'show_in_admin_bar' => false, |
||
| 95 | 'show_in_nav_menus' => false, |
||
| 96 | 'can_export' => true, |
||
| 97 | 'has_archive' => false, |
||
| 98 | 'exclude_from_search' => true, |
||
| 99 | 'publicly_queryable' => false, |
||
| 100 | 'rewrite' => false, |
||
| 101 | 'capabilities' => $order_capabilities, |
||
| 102 | 'show_in_rest' => true, |
||
| 103 | ); |
||
| 104 | register_post_type( self::$post_type_order, $order_args ); |
||
| 105 | |||
| 106 | /* |
||
| 107 | * PRODUCT data structure. Holds: |
||
| 108 | * title - title |
||
| 109 | * content - description |
||
| 110 | * thumbnail - image |
||
| 111 | * metadata: |
||
| 112 | * spay_price - price |
||
| 113 | * spay_currency - currency code |
||
| 114 | * spay_cta - text with "Buy" or other CTA |
||
| 115 | * spay_email - paypal email |
||
| 116 | * spay_multiple - allow for multiple items |
||
| 117 | * spay_status - status. { enabled | disabled } |
||
| 118 | */ |
||
| 119 | $product_capabilities = array( |
||
| 120 | 'edit_post' => 'edit_posts', |
||
| 121 | 'read_post' => 'read_private_posts', |
||
| 122 | 'delete_post' => 'delete_posts', |
||
| 123 | 'edit_posts' => 'edit_posts', |
||
| 124 | 'edit_others_posts' => 'edit_others_posts', |
||
| 125 | 'publish_posts' => 'publish_posts', |
||
| 126 | 'read_private_posts' => 'read_private_posts', |
||
| 127 | ); |
||
| 128 | $product_args = array( |
||
| 129 | 'label' => __( 'Product', 'jetpack' ), |
||
| 130 | 'description' => __( 'Simple Payments products', 'jetpack' ), |
||
| 131 | 'supports' => array( 'title', 'editor','thumbnail', 'custom-fields' ), |
||
| 132 | 'hierarchical' => false, |
||
| 133 | 'public' => false, |
||
| 134 | 'show_ui' => false, |
||
| 135 | 'show_in_menu' => false, |
||
| 136 | 'show_in_admin_bar' => false, |
||
| 137 | 'show_in_nav_menus' => false, |
||
| 138 | 'can_export' => true, |
||
| 139 | 'has_archive' => false, |
||
| 140 | 'exclude_from_search' => true, |
||
| 141 | 'publicly_queryable' => false, |
||
| 142 | 'rewrite' => false, |
||
| 143 | 'capabilities' => $product_capabilities, |
||
| 144 | 'show_in_rest' => true, |
||
| 145 | ); |
||
| 146 | register_post_type( self::$post_type_product, $product_args ); |
||
| 147 | } |
||
| 148 | |||
| 151 |
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.