| 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 |
||
| 92 | function setup_cpts() { |
||
| 93 | |||
| 94 | /* |
||
| 95 | * ORDER data structure. holds: |
||
| 96 | * title = customer_name | 4xproduct_name |
||
| 97 | * excerpt = customer_name + customer contact info + customer notes from paypal form |
||
| 98 | * metadata: |
||
| 99 | * spay_paypal_id - paypal id of transaction |
||
| 100 | * spay_status |
||
| 101 | * spay_product_id - post_id of bought product |
||
| 102 | * spay_quantity - quantity of product |
||
| 103 | * spay_price - item price at the time of purchase |
||
| 104 | * spay_customer_email - customer email |
||
| 105 | * ... (WIP) |
||
| 106 | */ |
||
| 107 | $order_capabilities = array( |
||
| 108 | 'edit_post' => 'edit_posts', |
||
| 109 | 'read_post' => 'read_private_posts', |
||
| 110 | 'delete_post' => 'delete_posts', |
||
| 111 | 'edit_posts' => 'edit_posts', |
||
| 112 | 'edit_others_posts' => 'edit_others_posts', |
||
| 113 | 'publish_posts' => 'publish_posts', |
||
| 114 | 'read_private_posts' => 'read_private_posts', |
||
| 115 | ); |
||
| 116 | $order_args = array( |
||
| 117 | 'label' => __( 'Order', 'jetpack' ), |
||
| 118 | 'description' => __( 'Simple Payments orders', 'jetpack' ), |
||
| 119 | 'supports' => array( 'custom-fields', 'excerpt' ), |
||
| 120 | 'hierarchical' => false, |
||
| 121 | 'public' => false, |
||
| 122 | 'show_ui' => false, |
||
| 123 | 'show_in_menu' => false, |
||
| 124 | 'show_in_admin_bar' => false, |
||
| 125 | 'show_in_nav_menus' => false, |
||
| 126 | 'can_export' => true, |
||
| 127 | 'has_archive' => false, |
||
| 128 | 'exclude_from_search' => true, |
||
| 129 | 'publicly_queryable' => false, |
||
| 130 | 'rewrite' => false, |
||
| 131 | 'capabilities' => $order_capabilities, |
||
| 132 | 'show_in_rest' => true, |
||
| 133 | ); |
||
| 134 | register_post_type( self::$post_type_order, $order_args ); |
||
| 135 | |||
| 136 | /* |
||
| 137 | * PRODUCT data structure. Holds: |
||
| 138 | * title - title |
||
| 139 | * content - description |
||
| 140 | * thumbnail - image |
||
| 141 | * metadata: |
||
| 142 | * spay_price - price |
||
| 143 | * spay_currency - currency code |
||
| 144 | * spay_cta - text with "Buy" or other CTA |
||
| 145 | * spay_email - paypal email |
||
| 146 | * spay_multiple - allow for multiple items |
||
| 147 | * spay_status - status. { enabled | disabled } |
||
| 148 | */ |
||
| 149 | $product_capabilities = array( |
||
| 150 | 'edit_post' => 'edit_posts', |
||
| 151 | 'read_post' => 'read_private_posts', |
||
| 152 | 'delete_post' => 'delete_posts', |
||
| 153 | 'edit_posts' => 'edit_posts', |
||
| 154 | 'edit_others_posts' => 'edit_others_posts', |
||
| 155 | 'publish_posts' => 'publish_posts', |
||
| 156 | 'read_private_posts' => 'read_private_posts', |
||
| 157 | ); |
||
| 158 | $product_args = array( |
||
| 159 | 'label' => __( 'Product', 'jetpack' ), |
||
| 160 | 'description' => __( 'Simple Payments products', 'jetpack' ), |
||
| 161 | 'supports' => array( 'title', 'editor','thumbnail', 'custom-fields' ), |
||
| 162 | 'hierarchical' => false, |
||
| 163 | 'public' => false, |
||
| 164 | 'show_ui' => false, |
||
| 165 | 'show_in_menu' => false, |
||
| 166 | 'show_in_admin_bar' => false, |
||
| 167 | 'show_in_nav_menus' => false, |
||
| 168 | 'can_export' => true, |
||
| 169 | 'has_archive' => false, |
||
| 170 | 'exclude_from_search' => true, |
||
| 171 | 'publicly_queryable' => false, |
||
| 172 | 'rewrite' => false, |
||
| 173 | 'capabilities' => $product_capabilities, |
||
| 174 | 'show_in_rest' => true, |
||
| 175 | ); |
||
| 176 | register_post_type( self::$post_type_product, $product_args ); |
||
| 177 | } |
||
| 178 | |||
| 181 |
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.