Conditions | 1 |
Paths | 1 |
Total Lines | 80 |
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 |
||
43 | function setup_cpts() { |
||
44 | |||
45 | /* |
||
46 | * ORDER data structure. holds: |
||
47 | * title = customer name |
||
48 | * metadata: |
||
49 | * spay_paypal_id |
||
50 | * spay_status |
||
51 | * ... (WIP) |
||
52 | */ |
||
53 | $order_capabilities = array( |
||
54 | 'edit_post' => 'edit_posts', |
||
55 | 'read_post' => 'read_private_posts', |
||
56 | 'delete_post' => 'delete_posts', |
||
57 | 'edit_posts' => 'edit_posts', |
||
58 | 'edit_others_posts' => 'edit_others_posts', |
||
59 | 'publish_posts' => 'publish_posts', |
||
60 | 'read_private_posts' => 'read_private_posts', |
||
61 | ); |
||
62 | $order_args = array( |
||
63 | 'label' => __( 'Order', 'jetpack' ), |
||
64 | 'description' => __( 'Simple Payments orders', 'jetpack' ), |
||
65 | 'supports' => array( 'custom-fields' ), |
||
66 | 'hierarchical' => false, |
||
67 | 'public' => false, |
||
68 | 'show_ui' => false, |
||
69 | 'show_in_menu' => false, |
||
70 | 'show_in_admin_bar' => false, |
||
71 | 'show_in_nav_menus' => false, |
||
72 | 'can_export' => true, |
||
73 | 'has_archive' => false, |
||
74 | 'exclude_from_search' => true, |
||
75 | 'publicly_queryable' => false, |
||
76 | 'rewrite' => false, |
||
77 | 'capabilities' => $order_capabilities, |
||
78 | 'show_in_rest' => true, |
||
79 | ); |
||
80 | register_post_type( self::$post_type_order, $order_args ); |
||
81 | |||
82 | /* |
||
83 | * PRODUCT data structure. Holds: |
||
84 | * title - title |
||
85 | * content - description |
||
86 | * thumbnail - image |
||
87 | * metadata: |
||
88 | * spay_price - price |
||
89 | * spay_currency - currency code |
||
90 | * spay_cta - text with "Buy" or other CTA |
||
91 | * spay_email - paypal email |
||
92 | * spay_multiple - allow for multiple items |
||
93 | */ |
||
94 | $product_capabilities = array( |
||
95 | 'edit_post' => 'edit_posts', |
||
96 | 'read_post' => 'read_private_posts', |
||
97 | 'delete_post' => 'delete_posts', |
||
98 | 'edit_posts' => 'edit_posts', |
||
99 | 'edit_others_posts' => 'edit_others_posts', |
||
100 | 'publish_posts' => 'publish_posts', |
||
101 | 'read_private_posts' => 'read_private_posts', |
||
102 | ); |
||
103 | $product_args = array( |
||
104 | 'label' => __( 'Product', 'jetpack' ), |
||
105 | 'description' => __( 'Simple Payments products', 'jetpack' ), |
||
106 | 'supports' => array( 'title', 'editor','thumbnail', 'custom-fields' ), |
||
107 | 'hierarchical' => false, |
||
108 | 'public' => false, |
||
109 | 'show_ui' => false, |
||
110 | 'show_in_menu' => false, |
||
111 | 'show_in_admin_bar' => false, |
||
112 | 'show_in_nav_menus' => false, |
||
113 | 'can_export' => true, |
||
114 | 'has_archive' => false, |
||
115 | 'exclude_from_search' => true, |
||
116 | 'publicly_queryable' => false, |
||
117 | 'rewrite' => false, |
||
118 | 'capabilities' => $product_capabilities, |
||
119 | 'show_in_rest' => true, |
||
120 | ); |
||
121 | register_post_type( self::$post_type_product, $product_args ); |
||
122 | } |
||
123 | |||
126 |
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.