Conditions | 7 |
Paths | 6 |
Total Lines | 64 |
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 |
||
65 | public function admin_notice() { |
||
66 | if ( get_option( 'mo_dismiss_adnotice', 'false' ) == 'true' ) { |
||
67 | return; |
||
68 | } |
||
69 | |||
70 | if ( $this->is_plugin_installed( 'mailoptin' ) && $this->is_plugin_active( 'mailoptin' ) ) { |
||
71 | return; |
||
72 | } |
||
73 | |||
74 | $dismiss_url = esc_url_raw( |
||
75 | add_query_arg( |
||
76 | array( |
||
77 | 'mo-adaction' => 'mo_dismiss_adnotice', |
||
78 | ), |
||
79 | admin_url() |
||
80 | ) |
||
81 | ); |
||
82 | |||
83 | $this->notice_css(); |
||
|
|||
84 | |||
85 | $install_url = wp_nonce_url( |
||
86 | admin_url( 'update.php?action=install-plugin&plugin=mailoptin' ), |
||
87 | 'install-plugin_mailoptin' |
||
88 | ); |
||
89 | |||
90 | $activate_url = wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=mailoptin%2Fmailoptin.php' ), |
||
91 | 'activate-plugin_mailoptin/mailoptin.php' ); |
||
92 | ?> |
||
93 | <div class="mo-admin-notice notice notice-success"> |
||
94 | <div class="mo-notice-first-half"> |
||
95 | <p> |
||
96 | <?php |
||
97 | printf( |
||
98 | __( 'Free optin form plugin that will %1$sincrease your email list subscribers%2$s and keep them engaged with %1$sautomated and schedule newsletters%2$s.' ), |
||
99 | '<span class="mo-stylize"><strong>', '</strong></span>' ); |
||
100 | ?> |
||
101 | </p> |
||
102 | <p style="text-decoration: underline;font-size: 12px;">Recommended by Dynamic Featured Image plugin</p> |
||
103 | </div> |
||
104 | <div class="mo-notice-other-half"> |
||
105 | <?php if ( ! $this->is_plugin_installed( 'mailoptin' ) ) : ?> |
||
106 | <a class="button button-primary button-hero" id="mo-install-mailoptin-plugin" |
||
107 | href="<?php echo $install_url; ?>"> |
||
108 | <?php _e( 'Install MailOptin Now for Free!' ); ?> |
||
109 | </a> |
||
110 | <?php endif; ?> |
||
111 | <?php if ( $this->is_plugin_installed( 'mailoptin' ) && ! $this->is_plugin_active( 'mailoptin' ) ) : ?> |
||
112 | <a class="button button-primary button-hero" id="mo-activate-mailoptin-plugin" |
||
113 | href="<?php echo $activate_url; ?>"> |
||
114 | <?php _e( 'Activate MailOptin Now!' ); ?> |
||
115 | </a> |
||
116 | <?php endif; ?> |
||
117 | <div class="mo-notice-learn-more"> |
||
118 | <a target="_blank" href="https://mailoptin.io">Learn more</a> |
||
119 | </div> |
||
120 | </div> |
||
121 | <a href="<?php echo $dismiss_url; ?>"> |
||
122 | <button type="button" class="notice-dismiss"> |
||
123 | <span class="screen-reader-text"><?php _e( 'Dismiss this notice' ); ?>.</span> |
||
124 | </button> |
||
125 | </a> |
||
126 | </div> |
||
127 | <?php |
||
128 | } |
||
129 | |||
213 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: