Conditions | 10 |
Paths | 20 |
Total Lines | 51 |
Code Lines | 28 |
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 |
||
85 | public function run_updates() { |
||
86 | |||
87 | do_action( 'simcal_before_update', $this->installed_ver ); |
||
88 | |||
89 | if ( ! is_null( $this->installed_ver ) ) { |
||
90 | |||
91 | if ( version_compare( $this->installed_ver, $this->new_ver ) === -1 ) { |
||
92 | |||
93 | $post_type = version_compare( $this->installed_ver, '3.0.0' ) === -1 ? 'gce_feed' : 'calendar'; |
||
94 | $this->posts = $this->get_posts( $post_type ); |
||
95 | |||
96 | foreach ( $this->update_path as $update_to ) { |
||
97 | if ( version_compare( $this->installed_ver, $update_to, '<' ) ) { |
||
98 | $this->update( $update_to ); |
||
99 | } |
||
100 | } |
||
101 | |||
102 | } |
||
103 | |||
104 | simcal_delete_feed_transients(); |
||
105 | |||
106 | } else { |
||
107 | |||
108 | new Post_Types(); |
||
109 | flush_rewrite_rules(); |
||
110 | |||
111 | } |
||
112 | |||
113 | do_action( 'simcal_updated', $this->new_ver ); |
||
114 | |||
115 | // Redirect to a welcome page if new install or major update. |
||
116 | if ( is_null( $this->installed_ver ) ) { |
||
117 | set_transient( '_simple-calendar_activation_redirect', 'fresh', 60 ); |
||
118 | } else { |
||
119 | $major_new = substr( $this->new_ver, 0, strrpos( $this->new_ver, '.' ) ); |
||
120 | $major_old = substr( $this->installed_ver, 0, strrpos( $this->installed_ver, '.' ) ); |
||
121 | if ( version_compare( $major_new, $major_old, '>' ) ) { |
||
122 | set_transient( '_simple-calendar_activation_redirect', 'update', 60 ); |
||
123 | } elseif ( $major_old == $major_new ) { |
||
124 | $version = explode( '.', $this->new_ver ); |
||
125 | end( $version ); |
||
126 | if ( 0 === intval( current( $version ) ) ) { |
||
127 | set_transient( '_simple-calendar_activation_redirect', 'update', 60 ); |
||
128 | } |
||
129 | } |
||
130 | } |
||
131 | |||
132 | $this->admin_redirects(); |
||
133 | |||
134 | update_option( 'simple-calendar_version', $this->new_ver ); |
||
135 | } |
||
136 | |||
222 |
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: