Total Complexity | 41 |
Total Lines | 208 |
Duplicated Lines | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
Complex classes like Output often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Output, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
9 | class Output { |
||
10 | |||
11 | /** |
||
12 | * Holds class instance |
||
13 | * |
||
14 | * @since 1.0.0 |
||
15 | * |
||
16 | * @var object \lsx\sharing\classes\frontend\Output() |
||
17 | */ |
||
18 | protected static $instance = null; |
||
19 | |||
20 | /** |
||
21 | * Contructor |
||
22 | */ |
||
23 | public function __construct() { |
||
24 | add_action( 'wp_enqueue_scripts', array( $this, 'assets' ), 5 ); |
||
|
|||
25 | add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses_allowed_html' ), 10, 2 ); |
||
26 | add_shortcode( 'lsx_sharing_buttons', array( $this, 'sharing_buttons_shortcode' ) ); |
||
27 | // Storefront (storefront_loop_post, storefront_single_post). |
||
28 | add_action( 'storefront_post_content_before', array( $this, 'sharing_buttons_template' ), 20 ); |
||
29 | // WooCommerce. |
||
30 | add_action( 'woocommerce_share', array( $this, 'sharing_buttons_template' ) ); |
||
31 | |||
32 | // General Post Types. |
||
33 | add_action( 'lsx_entry_after', array( $this, 'output_sharing' ) ); |
||
34 | |||
35 | // Tribe Events. |
||
36 | add_filter( 'tribe_events_ical_single_event_links', array( $this, 'output_event_sharing' ), 10, 1 ); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Return an instance of this class. |
||
41 | * |
||
42 | * @since 1.0.0 |
||
43 | * |
||
44 | * @return object \lsx\sharing\classes\frontend\Output() A single instance of this class. |
||
45 | */ |
||
46 | public static function get_instance() { |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Enques the assets. |
||
56 | */ |
||
57 | public function assets() { |
||
85 | } |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Display/return sharing buttons. |
||
90 | */ |
||
91 | public function sharing_buttons( $buttons = array( 'facebook', 'twitter', 'pinterest' ), $echo = false, $post_id = false ) { |
||
145 | } |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * Sharing buttons shortcode. |
||
150 | */ |
||
151 | public function sharing_buttons_shortcode( $atts ) { |
||
152 | $atts = shortcode_atts( array( |
||
153 | 'buttons' => '', |
||
154 | ), $atts, 'lsx_sharing_buttons' ); |
||
155 | |||
156 | if ( empty( $atts['buttons'] ) ) { |
||
157 | return ''; |
||
158 | } |
||
159 | |||
160 | $no_whitespaces = preg_replace( '/\s*,\s*/', ',', filter_var( $atts['buttons'], FILTER_SANITIZE_STRING ) ); |
||
161 | $buttons = explode( ',', $no_whitespaces ); |
||
162 | |||
163 | if ( is_array( $buttons ) && count( $buttons ) > 0 ) { |
||
164 | return $this->sharing_buttons( $buttons ); |
||
165 | } |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * Display buttons (template hook). |
||
170 | */ |
||
171 | public function sharing_buttons_template() { |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * Allow data params for Bootstrap modal. |
||
177 | */ |
||
178 | public function wp_kses_allowed_html( $allowedtags, $context ) { |
||
179 | $allowedtags['a']['data-toggle'] = true; |
||
180 | $allowedtags['a']['data-link'] = true; |
||
181 | return $allowedtags; |
||
182 | } |
||
183 | |||
184 | /** |
||
185 | * Outputs the sharing to the templates. |
||
186 | * |
||
187 | * @return void |
||
188 | */ |
||
189 | public function output_sharing() { |
||
190 | if ( is_main_query() && is_single() && ! is_singular( array( 'post', 'page', 'product' ) ) ) { |
||
191 | if ( \lsx\sharing\includes\functions\is_disabled() || \lsx\sharing\includes\functions\is_pt_disabled( get_post_type() ) ) { |
||
192 | return ''; |
||
193 | } |
||
194 | ?> |
||
195 | <footer class="footer-meta clearfix"> |
||
196 | <div class="post-tags-wrapper"> |
||
197 | <?php $this->sharing_buttons_template(); ?> |
||
198 | </div> |
||
199 | </footer><!-- .footer-meta --> |
||
200 | <?php |
||
201 | } |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * Outputs the sharing below the events. |
||
206 | * |
||
207 | * @param string $ical_links |
||
208 | * @return string |
||
209 | */ |
||
210 | public function output_event_sharing( $ical_links = '' ) { |
||
217 | } |
||
218 | } |
||
219 |