| Conditions | 14 |
| Paths | 374 |
| Total Lines | 61 |
| Code Lines | 44 |
| 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 |
||
| 17 | public function write( array $data ) { |
||
| 18 | $message = '<h3>' . esc_html__( 'Multisite Language Switcher last import report', 'multisite-language-switcher' ) . '</h3>'; |
||
| 19 | $message .= '<b>' . sprintf( |
||
| 20 | esc_html__( 'From post %d on site %d to post %d on site %d', 'multisite-language-switcher' ), |
||
|
|
|||
| 21 | $this->import_coordinates->source_post_id, |
||
| 22 | $this->import_coordinates->source_blog_id, |
||
| 23 | $this->import_coordinates->dest_post_id, |
||
| 24 | $this->import_coordinates->dest_blog_id |
||
| 25 | ) . '</b>'; |
||
| 26 | if ( ! empty( $data['info'] ) ) { |
||
| 27 | $section_title = esc_html__( 'General information', 'multisite-language-switcher' ); |
||
| 28 | $entries = $data['info']; |
||
| 29 | $message .= $this->get_section_html( $section_title, $entries ); |
||
| 30 | } |
||
| 31 | |||
| 32 | if ( ! empty( $data['success'] ) ) { |
||
| 33 | $section_title = esc_html__( 'Details', 'multisite-language-switcher' ); |
||
| 34 | $success_data = $data['success']; |
||
| 35 | $success_entries = []; |
||
| 36 | |||
| 37 | if ( isset( $success_data['post-field']['added'] ) ) { |
||
| 38 | $success_entries[] = esc_html__( 'The following post fields have been set: ', 'multisite-language-switcher' ) . |
||
| 39 | '<code>' . implode( '</code>, <code>', array_keys( $success_data['post-field']['added'] ) ) . '</code>.'; |
||
| 40 | } |
||
| 41 | if ( isset( $success_data['meta']['added'] ) ) { |
||
| 42 | $success_entries[] = esc_html__( 'The following post meta have been set: ', 'multisite-language-switcher' ) . |
||
| 43 | '<code>' . implode( '</code>, <code>', array_keys( $success_data['meta']['added'] ) ) . '</code>.'; |
||
| 44 | } |
||
| 45 | if ( isset( $success_data['term']['added'] ) ) { |
||
| 46 | $success_entries[] = esc_html__( 'Terms have been assigned to the post for the following taxonomies: ', 'multisite-language-switcher' ) . |
||
| 47 | '<code>' . implode( '</code>, <code>', array_keys( $success_data['term']['added'] ) ) . '</code>.'; |
||
| 48 | } |
||
| 49 | if ( isset( $success_data['post-thumbnail']['set'] ) ) { |
||
| 50 | $success_entries[] = esc_html__( 'The post thumbnail has been set.', 'multisite-language-switcher' ); |
||
| 51 | } |
||
| 52 | |||
| 53 | $message .= $this->get_section_html( $section_title, $success_entries, false ); |
||
| 54 | } |
||
| 55 | |||
| 56 | if ( ! empty( $data['error'] ) ) { |
||
| 57 | $section_title = esc_html__( 'Errors:', 'multisite-language-switcher' ); |
||
| 58 | $error_data = $data['error']; |
||
| 59 | $error_entries = []; |
||
| 60 | if ( isset( $error_data['term']['added'] ) || isset( $error_data['term']['created'] ) ) { |
||
| 61 | $taxonomies = isset( $error_data['term']['added'] ) ? array_keys( $error_data['term']['added'] ) : []; |
||
| 62 | $taxonomies = isset( $error_data['term']['created'] ) ? array_merge( $taxonomies, array_keys( $error_data['term']['created'] ) ) : $taxonomies; |
||
| 63 | $error_entries[] = esc_html__( 'There were issues creating or assigning terms for the following taxonomies: ', 'multisite-language-switcher' ) . |
||
| 64 | '<code>' . implode( '</code>, <code>', $taxonomies ) . '</code>.'; |
||
| 65 | } |
||
| 66 | if ( isset( $error_data['post-thumbnail']['set'] ) || isset( $error_data['post-thumbnail']['created'] ) ) { |
||
| 67 | $error_entries[] = esc_html__( 'The post thumbnail could not be created or set.', 'multisite-language-switcher' ); |
||
| 68 | } |
||
| 69 | $message .= $this->get_section_html( $section_title, $error_entries, false ); |
||
| 70 | } |
||
| 71 | |||
| 72 | $html = '<div class="notice notice-success is-dismissible"><p>' . $message . '</p></div>'; |
||
| 73 | |||
| 74 | switch_to_blog( $this->import_coordinates->dest_blog_id ); |
||
| 75 | |||
| 76 | set_transient( $this->transient, $html, HOUR_IN_SECONDS ); |
||
| 77 | } |
||
| 78 | |||
| 121 | } |