Conditions | 8 |
Paths | 8 |
Total Lines | 77 |
Code Lines | 41 |
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 |
||
81 | protected function task( $update ) { |
||
82 | if ( empty( $update ) ) { |
||
83 | return false; |
||
84 | } |
||
85 | |||
86 | /* @var Give_Updates $give_updates */ |
||
87 | $give_updates = Give_Updates::get_instance(); |
||
88 | $resume_update = get_option( |
||
89 | 'give_doing_upgrade', |
||
90 | |||
|
|||
91 | // Default update. |
||
92 | array( |
||
93 | 'update_info' => $update, |
||
94 | 'step' => 1, |
||
95 | 'update' => 1, |
||
96 | 'heading' => sprintf( 'Update %s of {update_count}', 1 ), |
||
97 | 'percentage' => $give_updates->percentage, |
||
98 | ) |
||
99 | ); |
||
100 | |||
101 | // Continuously skip update if previous update does not complete yet. |
||
102 | if( |
||
103 | $resume_update['update_info']['id'] !== $update['id'] && |
||
104 | ! give_has_upgrade_completed( $resume_update['update_info']['id'] ) |
||
105 | ) { |
||
106 | return $update; |
||
107 | } |
||
108 | |||
109 | // Set params. |
||
110 | $resume_update['update_info'] = $update; |
||
111 | $give_updates->step = absint( $resume_update['step'] ); |
||
112 | $give_updates->update = absint( $resume_update['update'] ); |
||
113 | $is_parent_update_completed = $give_updates->is_parent_updates_completed( $update ); |
||
114 | |||
115 | // Skip update if dependency update does not complete yet. |
||
116 | if ( empty( $is_parent_update_completed ) ) { |
||
117 | // @todo: set error when you have only one update with invalid dependency |
||
118 | if ( ! is_null( $is_parent_update_completed ) ) { |
||
119 | return $update; |
||
120 | } |
||
121 | |||
122 | return false; |
||
123 | } |
||
124 | |||
125 | // Disable cache. |
||
126 | Give_Cache::disable(); |
||
127 | |||
128 | // Run update. |
||
129 | if ( is_array( $update['callback'] ) ) { |
||
130 | $update['callback'][0]->$update['callback'][1](); |
||
131 | } else { |
||
132 | $update['callback'](); |
||
133 | } |
||
134 | |||
135 | // Set update info. |
||
136 | $doing_upgrade_args = array( |
||
137 | 'update_info' => $update, |
||
138 | 'step' => ++ $give_updates->step, |
||
139 | 'update' => $give_updates->update, |
||
140 | 'heading' => sprintf( 'Update %s of %s', $give_updates->update, get_option( 'give_db_update_count' ) ), |
||
141 | 'percentage' => $give_updates->percentage, |
||
142 | 'total_percentage' => $give_updates->get_db_update_processing_percentage(), |
||
143 | ); |
||
144 | |||
145 | // Cache upgrade. |
||
146 | update_option( 'give_doing_upgrade', $doing_upgrade_args ); |
||
147 | |||
148 | // Enable cache. |
||
149 | Give_Cache::enable(); |
||
150 | |||
151 | // Check if current update completed or not. |
||
152 | if ( give_has_upgrade_completed( $update['id'] ) ) { |
||
153 | return false; |
||
154 | } |
||
155 | |||
156 | return $update; |
||
157 | } |
||
158 | |||
194 |