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