Conditions | 8 |
Paths | 25 |
Total Lines | 68 |
Code Lines | 45 |
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 |
||
46 | public function get_pages() { |
||
47 | // WC pages to check against. |
||
48 | $check_pages = array( |
||
49 | _x( 'Shop base', 'Page setting', 'woocommerce' ) => array( |
||
50 | 'option' => 'woocommerce_shop_page_id', |
||
51 | 'shortcode' => '', |
||
52 | ), |
||
53 | _x( 'Cart', 'Page setting', 'woocommerce' ) => array( |
||
54 | 'option' => 'woocommerce_cart_page_id', |
||
55 | 'shortcode' => '[' . apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) . ']', |
||
56 | ), |
||
57 | _x( 'Checkout', 'Page setting', 'woocommerce' ) => array( |
||
58 | 'option' => 'woocommerce_checkout_page_id', |
||
59 | 'shortcode' => '[' . apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) . ']', |
||
60 | ), |
||
61 | _x( 'My account', 'Page setting', 'woocommerce' ) => array( |
||
62 | 'option' => 'woocommerce_myaccount_page_id', |
||
63 | 'shortcode' => '[' . apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) . ']', |
||
64 | ), |
||
65 | _x( 'Terms and conditions', 'Page setting', 'woocommerce' ) => array( |
||
66 | 'option' => 'woocommerce_terms_page_id', |
||
67 | 'shortcode' => '', |
||
68 | ), |
||
69 | ); |
||
70 | |||
71 | $pages_output = array(); |
||
72 | foreach ( $check_pages as $page_name => $values ) { |
||
73 | $page_id = get_option( $values['option'] ); |
||
74 | $page_set = false; |
||
75 | $page_exists = false; |
||
76 | $page_visible = false; |
||
77 | $shortcode_present = false; |
||
78 | $shortcode_required = false; |
||
79 | |||
80 | // Page checks. |
||
81 | if ( $page_id ) { |
||
82 | $page_set = true; |
||
83 | } |
||
84 | if ( get_post( $page_id ) ) { |
||
85 | $page_exists = true; |
||
86 | } |
||
87 | if ( 'publish' === get_post_status( $page_id ) ) { |
||
88 | $page_visible = true; |
||
89 | } |
||
90 | |||
91 | // Shortcode checks. |
||
92 | if ( $values['shortcode'] && get_post( $page_id ) ) { |
||
93 | $shortcode_required = true; |
||
94 | $page = get_post( $page_id ); |
||
95 | if ( strstr( $page->post_content, $values['shortcode'] ) ) { |
||
96 | $shortcode_present = true; |
||
97 | } |
||
98 | } |
||
99 | |||
100 | // Wrap up our findings into an output array. |
||
101 | $pages_output[] = array( |
||
102 | 'page_name' => $page_name, |
||
103 | 'page_id' => $page_id, |
||
104 | 'page_set' => $page_set, |
||
105 | 'page_exists' => $page_exists, |
||
106 | 'page_visible' => $page_visible, |
||
107 | 'shortcode' => $values['shortcode'], |
||
108 | 'shortcode_required' => $shortcode_required, |
||
109 | 'shortcode_present' => $shortcode_present, |
||
110 | ); |
||
111 | } |
||
112 | |||
113 | return $pages_output; |
||
114 | } |
||
116 |