Conditions | 7 |
Paths | 13 |
Total Lines | 68 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
87 | protected function inline_thickbox_html( $echo = true, array $data = [] ) { |
||
88 | if ( ! isset( $data['msls_import'] ) ) { |
||
89 | return ''; |
||
90 | } |
||
91 | |||
92 | $slug = str_replace( '|', '-', $data['msls_import'] ); |
||
93 | |||
94 | ob_start(); |
||
95 | ?> |
||
96 | <div style="display: none;" id="msls-import-dialog-<?php echo esc_attr( $slug ) ?>"> |
||
97 | <h3><?php esc_html_e( 'Select what should be imported and how', 'multisite-language-switcher' ) ?></h3> |
||
98 | |||
99 | <form action="<?php echo add_query_arg( [] ) ?>" method="post"> |
||
100 | |||
101 | <?php wp_nonce_field( MSLS_PLUGIN_PATH, 'msls_noncename' ); ?> |
||
102 | |||
103 | <?php foreach ( $data as $key => $value ) : ?> |
||
104 | <input type="hidden" name="<?php echo esc_attr( $key ) ?>" value="<?php echo esc_attr( $value ) ?>"> |
||
105 | <?php endforeach; ?> |
||
106 | |||
107 | <?php /** @var ImportersFactory $factory */ |
||
108 | foreach ( Map::instance()->factories() as $slug => $factory ) : ?> |
||
109 | <?php $details = $factory->details() ?> |
||
110 | <h4><?php echo esc_html( $details->name ) ?></h4> |
||
111 | <?php if ( empty( $details->importers ) ) : ?> |
||
112 | <p><?php esc_html_e( 'No importers available for this type of content.', 'multisite-language-switcher' ) ?></p> |
||
113 | <?php else: ?> |
||
114 | <ul> |
||
115 | <li> |
||
116 | <label> |
||
117 | <input type="radio" name="msls_importers[<?php echo esc_attr( $details->slug ) ?>]"> |
||
118 | <?php esc_html_e( 'Off - Do not import this type of content in the destination post.', 'multisite-language-switcher' ) ?> |
||
119 | </label> |
||
120 | </li> |
||
121 | <?php foreach ( $details->importers as $importer_slug => $importer_info ) : ?> |
||
122 | <li> |
||
123 | <label> |
||
124 | <input type="radio" name="msls_importers[<?php echo esc_attr( $details->slug ) ?>]" |
||
125 | value="<?php echo esc_attr( $importer_slug ) ?>" |
||
126 | <?php checked( $details->selected, $importer_slug ) ?> |
||
127 | > |
||
128 | <?php echo( esc_html( sprintf( '%s - %s', $importer_info->name, $importer_info->description ) ) ) ?> |
||
129 | </label> |
||
130 | </li> |
||
131 | <?php endforeach; ?> |
||
132 | </ul> |
||
133 | <?php endif; ?> |
||
134 | <?php endforeach; ?> |
||
135 | |||
136 | <div> |
||
137 | <input |
||
138 | type="submit" |
||
139 | class="button-primary" |
||
140 | value="<?php esc_html_e( 'Import Content', 'multisite-language-switcher' ) ?>" |
||
141 | > |
||
142 | </div> |
||
143 | </form> |
||
144 | </div> |
||
145 | |||
146 | <?php |
||
147 | $html = ob_get_clean(); |
||
148 | |||
149 | if ( $echo ) { |
||
150 | echo $html; |
||
151 | } |
||
152 | |||
153 | return $html; |
||
154 | } |
||
155 | } |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: