Total Complexity | 43 |
Total Lines | 212 |
Duplicated Lines | 0 % |
Changes | 5 | ||
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 | // Sensei Integration. |
||
39 | add_action( 'sensei_pagination', array( $this, 'output_sharing' ), 20 ); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Return an instance of this class. |
||
44 | * |
||
45 | * @since 1.0.0 |
||
46 | * |
||
47 | * @return object \lsx\sharing\classes\frontend\Output() A single instance of this class. |
||
48 | */ |
||
49 | public static function get_instance() { |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Enques the assets. |
||
59 | */ |
||
60 | public function assets() { |
||
88 | } |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Display/return sharing buttons. |
||
93 | */ |
||
94 | public function sharing_buttons( $buttons = array( 'facebook', 'twitter', 'pinterest' ), $echo = false, $post_id = false ) { |
||
148 | } |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * Sharing buttons shortcode. |
||
153 | */ |
||
154 | public function sharing_buttons_shortcode( $atts ) { |
||
155 | $atts = shortcode_atts( array( |
||
156 | 'buttons' => '', |
||
157 | ), $atts, 'lsx_sharing_buttons' ); |
||
158 | |||
159 | if ( empty( $atts['buttons'] ) ) { |
||
160 | return ''; |
||
161 | } |
||
162 | |||
163 | $no_whitespaces = preg_replace( '/\s*,\s*/', ',', filter_var( $atts['buttons'], FILTER_SANITIZE_STRING ) ); |
||
164 | $buttons = explode( ',', $no_whitespaces ); |
||
165 | |||
166 | if ( is_array( $buttons ) && count( $buttons ) > 0 ) { |
||
167 | return $this->sharing_buttons( $buttons ); |
||
168 | } |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * Display buttons (template hook). |
||
173 | */ |
||
174 | public function sharing_buttons_template() { |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * Allow data params for Bootstrap modal. |
||
180 | */ |
||
181 | public function wp_kses_allowed_html( $allowedtags, $context ) { |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * Outputs the sharing to the templates. |
||
189 | * |
||
190 | * @return void |
||
191 | */ |
||
192 | public function output_sharing() { |
||
193 | if ( is_main_query() && is_single() && ! is_singular( array( 'post', 'page', 'product' ) ) ) { |
||
194 | |||
195 | if ( \lsx\sharing\includes\functions\is_disabled() || \lsx\sharing\includes\functions\is_pt_disabled( get_post_type() ) || in_array( get_post_type(), \lsx\sharing\includes\functions\get_restricted_post_types() ) || in_array( get_post_type(), \lsx\sharing\includes\functions\get_to_post_types() ) ) { |
||
196 | return ''; |
||
197 | } |
||
198 | ?> |
||
199 | <footer class="lsx-sharing-wrapper footer-meta clearfix"> |
||
200 | <div class="post-tags-wrapper"> |
||
201 | <?php $this->sharing_buttons_template(); ?> |
||
202 | </div> |
||
203 | </footer><!-- .footer-meta --> |
||
204 | <?php |
||
205 | } |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * Outputs the sharing below the events. |
||
210 | * |
||
211 | * @param string $ical_links |
||
212 | * @return string |
||
213 | */ |
||
214 | public function output_event_sharing( $ical_links = '' ) { |
||
221 | } |
||
222 | } |
||
223 |