| Conditions | 12 |
| Paths | 6 |
| Total Lines | 78 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| Bugs | 1 | Features | 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 | public function configure_archive_fields( $cmb ) { |
||
| 93 | $archives = array(); |
||
| 94 | $post_type_args = array( |
||
| 95 | 'public' => true, |
||
| 96 | ); |
||
| 97 | $post_types = get_post_types($post_type_args); |
||
| 98 | if ( ! empty($post_types) ) { |
||
| 99 | foreach ( $post_types as $post_type_key => $post_type_value ) { |
||
| 100 | switch ( $post_type_key ) { |
||
| 101 | case 'post': |
||
| 102 | $page_url = home_url(); |
||
| 103 | $page_title = __('Home', 'lsx-search'); |
||
| 104 | $show_on_front = get_option('show_on_front'); |
||
| 105 | if ( 'page' === $show_on_front ) { |
||
| 106 | $page_for_posts = get_option('page_for_posts'); |
||
| 107 | if ( '' !== $page_for_posts ) { |
||
| 108 | $page_title = get_the_title($page_for_posts); |
||
| 109 | $page_url = get_permalink($page_for_posts); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | $description = sprintf( |
||
| 113 | /* translators: %s: The subscription info */ |
||
| 114 | __('Control the sharing buttons on your <a target="_blank" href="%1$s">%2$s</a> posts.', 'lsx-search'), |
||
| 115 | $page_url, |
||
| 116 | $page_title |
||
| 117 | ); |
||
| 118 | $archives[ $post_type_key ] = array( |
||
| 119 | 'title' => __('Blog', 'lsx-search'), |
||
| 120 | 'desc' => $description, |
||
| 121 | ); |
||
| 122 | break; |
||
| 123 | |||
| 124 | case 'product': |
||
| 125 | $page_url = home_url(); |
||
| 126 | $page_title = __('Shop', 'lsx-search'); |
||
| 127 | if ( function_exists('wc_get_page_id') ) { |
||
| 128 | $shop_page = wc_get_page_id('shop'); |
||
| 129 | $page_url = get_permalink($shop_page); |
||
| 130 | $page_title = get_the_title($shop_page); |
||
| 131 | } |
||
| 132 | $description = sprintf( |
||
| 133 | /* translators: %s: The subscription info */ |
||
| 134 | __('Control the sharing buttons which show on your <a target="_blank" href="%1$s">%2$s</a> product pages.', 'lsx-search'), |
||
| 135 | $page_url, |
||
| 136 | $page_title |
||
| 137 | ); |
||
| 138 | $archives[ $post_type_key ] = array( |
||
| 139 | 'title' => __('Shop', 'lsx-search'), |
||
| 140 | 'desc' => $description, |
||
| 141 | ); |
||
| 142 | break; |
||
| 143 | |||
| 144 | default: |
||
| 145 | if ( in_array($post_type_key, \lsx\sharing\includes\functions\get_restricted_post_types()) ) { |
||
| 146 | break; |
||
| 147 | } |
||
| 148 | $temp_post_type = get_post_type_object($post_type_key); |
||
| 149 | if ( ! is_wp_error($temp_post_type) ) { |
||
| 150 | $page_url = get_post_type_archive_link($temp_post_type->name); |
||
| 151 | $description = sprintf( |
||
| 152 | /* translators: %s: The subscription info */ |
||
| 153 | __('Control the sharing buttons which show on your <a target="_blank" href="%1$s">%2$s</a> singles.', 'lsx-search'), |
||
| 154 | $page_url, |
||
| 155 | $temp_post_type->label |
||
| 156 | ); |
||
| 157 | |||
| 158 | $archives[ $post_type_key ] = array( |
||
| 159 | 'title' => $temp_post_type->label, |
||
| 160 | 'desc' => $description, |
||
| 161 | ); |
||
| 162 | } |
||
| 163 | break; |
||
| 164 | } |
||
| 165 | } |
||
| 166 | } |
||
| 167 | if ( ! empty($archives) ) { |
||
| 168 | foreach ( $archives as $archive_key => $archive_args ) { |
||
| 169 | $this->get_fields($cmb, $archive_key, $archive_args); |
||
| 170 | } |
||
| 266 |