Conditions | 9 |
Paths | 8 |
Total Lines | 84 |
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 |
||
107 | public function sideload() |
||
108 | { |
||
109 | // setup temp dir |
||
110 | $temp_file = wp_tempnam($this->_upload_from); |
||
111 | |||
112 | if (!$temp_file) { |
||
113 | EE_Error::add_error( |
||
114 | esc_html__('Something went wrong with the upload. Unable to create a tmp file for the uploaded file on the server', 'event_espresso'), |
||
115 | __FILE__, |
||
116 | __FUNCTION__, |
||
117 | __LINE__ |
||
118 | ); |
||
119 | return false; |
||
120 | } |
||
121 | |||
122 | do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file); |
||
123 | |||
124 | $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file); |
||
125 | |||
126 | $response = wp_safe_remote_get($this->_upload_from, $wp_remote_args); |
||
127 | |||
128 | if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) { |
||
129 | unlink($temp_file); |
||
130 | if (defined('WP_DEBUG') && WP_DEBUG) { |
||
131 | EE_Error::add_error( |
||
132 | sprintf( |
||
133 | esc_html__('Unable to upload the file. Either the path given to upload from is incorrect, or something else happened. Here is the path given: %s', 'event_espresso'), |
||
134 | $this->_upload_from |
||
135 | ), |
||
136 | __FILE__, |
||
137 | __FUNCTION__, |
||
138 | __LINE__ |
||
139 | ); |
||
140 | } |
||
141 | return false; |
||
142 | } |
||
143 | |||
144 | // possible md5 check |
||
145 | $content_md5 = wp_remote_retrieve_header($response, 'content-md5'); |
||
146 | if ($content_md5) { |
||
147 | $md5_check = verify_file_md5($temp_file, $content_md5); |
||
148 | if (is_wp_error($md5_check)) { |
||
149 | unlink($temp_file); |
||
150 | EE_Error::add_error( |
||
151 | $md5_check->get_error_message(), |
||
152 | __FILE__, |
||
153 | __FUNCTION__, |
||
154 | __LINE__ |
||
155 | ); |
||
156 | return false; |
||
157 | } |
||
158 | } |
||
159 | |||
160 | $file = $temp_file; |
||
161 | |||
162 | // now we have the file, let's get it in the right directory with the right name. |
||
163 | $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this); |
||
164 | |||
165 | // move file in |
||
166 | if (false === @ rename($file, $path)) { |
||
167 | unlink($temp_file); |
||
168 | EE_Error::add_error( |
||
169 | sprintf( |
||
170 | esc_html__('Unable to move the file to new location (possible permissions errors). This is the path the class attempted to move the file to: %s', 'event_espresso'), |
||
171 | $path |
||
172 | ), |
||
173 | __FILE__, |
||
174 | __FUNCTION__, |
||
175 | __LINE__ |
||
176 | ); |
||
177 | return false; |
||
178 | } |
||
179 | |||
180 | // set permissions |
||
181 | $permissions = apply_filters('FHEE__EEH_Sideloader__sideload__permissions_applied', $this->_permissions, $this); |
||
182 | chmod($path, $permissions); |
||
183 | |||
184 | // that's it. let's allow for actions after file uploaded. |
||
185 | do_action('AHEE__EE_Sideloader__sideload_after', $this, $path); |
||
186 | |||
187 | // unlink tempfile |
||
188 | @unlink($temp_file); |
||
189 | return true; |
||
190 | } |
||
191 | } //end EEH_Template class |
||
192 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.