Conditions | 20 |
Paths | 6937 |
Total Lines | 129 |
Code Lines | 73 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
119 | public function display_inline_notice( $name, $title, $message, $type = 'success', $is_dismissible = false, $args = array() ) { |
||
120 | /* Available/Planned $args options |
||
121 | * $args = array( |
||
122 | * 'primary' => array( |
||
123 | * 'text' => '', |
||
124 | * 'url' => '', |
||
125 | * 'target' => '', |
||
126 | * 'class' => 'button button-primary', |
||
127 | * ), |
||
128 | * 'secondary' => array( |
||
129 | * 'text' => '', |
||
130 | * 'url' => '', |
||
131 | * 'target' => '', |
||
132 | * 'class' => 'button button-secondary', |
||
133 | * ), |
||
134 | * 'skip_message_escape' => true // note: This param is for internal use only. Do not use as a developer. |
||
135 | * ); |
||
136 | */ |
||
137 | |||
138 | |||
139 | // Check if the notice is dismissible, and if so has been dismissed. |
||
140 | if ( $is_dismissible && $this->is_dismissed( $name ) ) { |
||
141 | // Nothing to show here, return! |
||
142 | return ''; |
||
143 | } |
||
144 | |||
145 | $dismissible = ( $is_dismissible ) ? ' is-dismissible' : ''; |
||
146 | |||
147 | // Display inline notice |
||
148 | ob_start(); |
||
149 | ?> |
||
150 | <div |
||
151 | class="monsterinsights-notice <?php echo 'monsterinsights-' . esc_attr( $type ) . '-notice' . esc_attr($dismissible); ?>" |
||
152 | data-notice="<?php echo esc_attr( $name ); ?>"> |
||
153 | <div |
||
154 | class="monsterinsights-notice-icon <?php echo 'monsterinsights-' . esc_attr( $type ) . '-notice-icon' ?>"> |
||
155 | </div> |
||
156 | <div |
||
157 | class="monsterinsights-notice-text <?php echo 'monsterinsights-' . esc_attr( $type ) . '-notice-text' ?>"> |
||
158 | <?php |
||
159 | // Title |
||
160 | if ( ! empty ( $title ) ) { |
||
161 | ?> |
||
162 | <p class="monsterinsights-notice-title"><?php echo esc_html( $title ); ?></p> |
||
163 | <?php |
||
164 | } |
||
165 | |||
166 | // Message |
||
167 | if ( ! empty( $message ) ) { |
||
168 | if ( empty( $args['skip_message_escape'] ) ) { |
||
169 | ?> |
||
170 | <p class="monsterinsights-notice-message"><?php echo esc_html( $message ); ?></p> |
||
171 | <?php |
||
172 | } else { |
||
173 | ?> |
||
174 | <p class="monsterinsights-notice-message"><?php echo $message; // phpcs:ignore ?></p> |
||
175 | <?php |
||
176 | } |
||
177 | } |
||
178 | |||
179 | // Primary Button |
||
180 | if ( ! empty( $args['primary']['text'] ) ) { |
||
181 | |||
182 | $text = ''; |
||
183 | if ( ! empty( $args['primary']['text'] ) ) { |
||
184 | $text = $args['primary']['text']; |
||
185 | } |
||
186 | |||
187 | $url = '#'; |
||
188 | if ( ! empty( $args['primary']['url'] ) ) { |
||
189 | $url = $args['primary']['url']; |
||
190 | } |
||
191 | |||
192 | $target = ''; |
||
193 | if ( ! empty( $args['primary']['target'] ) && $args['primary']['target'] === 'blank' ) { |
||
194 | $target = ' target="_blank" rel="noopener noreferrer"'; |
||
195 | } |
||
196 | |||
197 | $class = 'button button-primary'; |
||
198 | if ( ! empty( $args['primary']['class'] ) ) { |
||
199 | $class = ' class="' . $args['primary']['class'] . '"'; |
||
200 | } |
||
201 | ?> |
||
202 | <a href="<?php echo esc_url( $url ); ?>"<?php echo esc_attr($target); ?><?php echo esc_attr($class); ?>><?php echo esc_html( $text ); ?></a> |
||
203 | <?php |
||
204 | } |
||
205 | |||
206 | // Secondary Button |
||
207 | if ( ! empty( $args['secondary']['text'] ) ) { |
||
208 | |||
209 | $text = ''; |
||
210 | if ( ! empty( $args['secondary']['text'] ) ) { |
||
211 | $text = $args['secondary']['text']; |
||
212 | } |
||
213 | |||
214 | $url = '#'; |
||
215 | if ( ! empty( $args['secondary']['url'] ) ) { |
||
216 | $url = $args['secondary']['url']; |
||
217 | } |
||
218 | |||
219 | $target = ''; |
||
220 | if ( ! empty( $args['secondary']['target'] ) && $args['secondary']['target'] === 'blank' ) { |
||
221 | $target = ' target="_blank" rel="noopener noreferrer"'; |
||
222 | } |
||
223 | |||
224 | $class = 'button button-secondary'; |
||
225 | if ( ! empty( $args['secondary']['class'] ) ) { |
||
226 | $class = ' class="' . $args['secondary']['class'] . '"'; |
||
227 | } |
||
228 | ?> |
||
229 | <a href="<?php echo esc_url( $url ); ?>"<?php echo esc_attr($target); ?><?php echo esc_attr($class); ?>><?php echo esc_html( $text ); ?></a> |
||
230 | <?php |
||
231 | } |
||
232 | |||
233 | // Dismiss Button |
||
234 | if ( $is_dismissible ) { |
||
235 | ?> |
||
236 | <button type="button" class="notice-dismiss<?php echo esc_attr($dismissible); ?>"> |
||
237 | <span class="screen-reader-text"> |
||
238 | <?php esc_html_e( 'Dismiss this notice', 'google-analytics-for-wordpress' ); ?> |
||
239 | </span> |
||
240 | </button> |
||
241 | <?php |
||
242 | } |
||
243 | ?> |
||
244 | </div> |
||
245 | </div> |
||
246 | <?php |
||
247 | return ob_get_clean(); |
||
248 | } |
||
250 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.