| Conditions | 9 | 
| Paths | 16 | 
| Total Lines | 83 | 
| Code Lines | 43 | 
| 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  | 
            ||
| 93 | 	protected function task( $update ) { | 
            ||
| 94 | // Pause upgrade immediately if admin pausing upgrades.  | 
            ||
| 95 | 		if( $this->is_paused_process() ) { | 
            ||
| 96 | wp_die();  | 
            ||
| 97 | }  | 
            ||
| 98 | |||
| 99 | 		if ( empty( $update ) ) { | 
            ||
| 100 | return false;  | 
            ||
| 101 | }  | 
            ||
| 102 | |||
| 103 | /* @var Give_Updates $give_updates */  | 
            ||
| 104 | $give_updates = Give_Updates::get_instance();  | 
            ||
| 105 | $resume_update = get_option(  | 
            ||
| 106 | 'give_doing_upgrade',  | 
            ||
| 107 | |||
| 108 | // Default update.  | 
            ||
| 109 | array(  | 
            ||
| 110 | 'update_info' => $update,  | 
            ||
| 111 | 'step' => 1,  | 
            ||
| 112 | 'update' => 1,  | 
            ||
| 113 | 				'heading'     => sprintf( 'Update %s of {update_count}', 1 ), | 
            ||
| 114 | 'percentage' => $give_updates->percentage,  | 
            ||
| 115 | )  | 
            ||
| 116 | );  | 
            ||
| 117 | |||
| 118 | // Continuously skip update if previous update does not complete yet.  | 
            ||
| 119 | if (  | 
            ||
| 120 | $resume_update['update_info']['id'] !== $update['id'] &&  | 
            ||
| 121 | ! give_has_upgrade_completed( $resume_update['update_info']['id'] )  | 
            ||
| 122 | 		) { | 
            ||
| 123 | return $update;  | 
            ||
| 124 | }  | 
            ||
| 125 | |||
| 126 | // Set params.  | 
            ||
| 127 | $resume_update['update_info'] = $update;  | 
            ||
| 128 | $give_updates->step = absint( $resume_update['step'] );  | 
            ||
| 129 | $give_updates->update = absint( $resume_update['update'] );  | 
            ||
| 130 | $is_parent_update_completed = $give_updates->is_parent_updates_completed( $update );  | 
            ||
| 131 | |||
| 132 | |||
| 133 | // Skip update if dependency update does not complete yet.  | 
            ||
| 134 | 		if ( empty( $is_parent_update_completed ) ) { | 
            ||
| 135 | // @todo: set error when you have only one update with invalid dependency  | 
            ||
| 136 | 			if ( ! is_null( $is_parent_update_completed ) ) { | 
            ||
| 137 | return $update;  | 
            ||
| 138 | }  | 
            ||
| 139 | |||
| 140 | return false;  | 
            ||
| 141 | }  | 
            ||
| 142 | |||
| 143 | // Disable cache.  | 
            ||
| 144 | Give_Cache::disable();  | 
            ||
| 145 | |||
| 146 | // Run update.  | 
            ||
| 147 | 		if ( is_array( $update['callback'] ) ) { | 
            ||
| 148 | $update['callback'][0]->$update['callback'][1]();  | 
            ||
| 149 | 		} else { | 
            ||
| 150 | $update['callback']();  | 
            ||
| 151 | }  | 
            ||
| 152 | |||
| 153 | // Set update info.  | 
            ||
| 154 | $doing_upgrade_args = array(  | 
            ||
| 155 | 'update_info' => $update,  | 
            ||
| 156 | 'step' => ++ $give_updates->step,  | 
            ||
| 157 | 'update' => $give_updates->update,  | 
            ||
| 158 | 'heading' => sprintf( 'Update %s of %s', $give_updates->update, get_option( 'give_db_update_count' ) ),  | 
            ||
| 159 | 'percentage' => $give_updates->percentage,  | 
            ||
| 160 | 'total_percentage' => $give_updates->get_db_update_processing_percentage(),  | 
            ||
| 161 | );  | 
            ||
| 162 | |||
| 163 | // Cache upgrade.  | 
            ||
| 164 | update_option( 'give_doing_upgrade', $doing_upgrade_args );  | 
            ||
| 165 | |||
| 166 | // Enable cache.  | 
            ||
| 167 | Give_Cache::enable();  | 
            ||
| 168 | |||
| 169 | // Check if current update completed or not.  | 
            ||
| 170 | 		if ( give_has_upgrade_completed( $update['id'] ) ) { | 
            ||
| 171 | return false;  | 
            ||
| 172 | }  | 
            ||
| 173 | |||
| 174 | return $update;  | 
            ||
| 175 | }  | 
            ||
| 176 | |||
| 290 | 
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.