Conditions | 11 |
Paths | 16 |
Total Lines | 52 |
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 |
||
18 | public function render() { |
||
19 | $post = get_post(); |
||
20 | $mydata = new MslsOptionsPost( $post->ID ); |
||
21 | $languages = MslsOptionsPost::instance()->get_available_languages(); |
||
22 | $current = MslsBlogCollection::get_blog_language( get_current_blog_id() ); |
||
23 | $languages = array_diff_key( $languages, array( $current => $current ) ); |
||
24 | $input_lang = isset( $_GET['msls_lang'] ) ? $_GET['msls_lang'] : null; |
||
25 | $input_id = isset( $_GET['msls_id'] ) ? $_GET['msls_id'] : null; |
||
26 | $has_input = null !== $input_lang && null !== $input_id; |
||
27 | $blogs = MslsBlogCollection::instance(); |
||
28 | $available = array_filter( array_map( function ( $lang ) use ( $mydata ) { |
||
29 | return $mydata->{$lang}; |
||
30 | }, array_keys( $languages ) ) ); |
||
31 | $has_translation = count( $available ) >= 1; |
||
32 | |||
33 | if ( $has_input || $has_translation ) { |
||
34 | add_thickbox(); |
||
35 | $label_template = __( 'Import content from %s', 'multisite-language-switcher' ); |
||
36 | $output = '<fieldset>'; |
||
37 | $output .= '<legend>' |
||
38 | . esc_html__( 'Warning! This will override and replace all the post content with the content from the source post!', |
||
39 | 'multisite-language-switcher' ) |
||
40 | . '</legend>'; |
||
41 | foreach ( $languages as $language => $label ) { |
||
42 | $id = $mydata->{$language}; |
||
43 | $blog = $blogs->get_blog_id( $language ); |
||
44 | $label = sprintf( $label_template, $label ); |
||
45 | if ( null === $id && $has_input && $input_lang === $language ) { |
||
46 | $id = $input_id; |
||
47 | $blog = $blogs->get_blog_id( $language ); |
||
48 | } |
||
49 | if ( null !== $id ) { |
||
50 | $this->data = [ |
||
51 | 'msls_import' => "{$blog}|{$id}", |
||
52 | ]; |
||
53 | $output .= sprintf( '<a class="button button-primary thickbox" href="%s" title="%s">%s</a>', |
||
54 | $this->inline_thickbox_url( $this->data ), |
||
55 | $label, |
||
56 | $label |
||
57 | ); |
||
58 | } |
||
59 | } |
||
60 | $output .= '</fieldset>'; |
||
61 | } else { |
||
62 | $output = '<p>' . |
||
63 | esc_html__( 'No translated versions linked to this post: import content functionality is disabled.', |
||
64 | 'multisite-language-switcher' ) |
||
65 | . '</p>'; |
||
66 | } |
||
67 | |||
68 | echo $output; |
||
69 | } |
||
70 | |||
157 |