Conditions | 11 |
Paths | 164 |
Total Lines | 54 |
Code Lines | 27 |
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 |
||
158 | protected function validate(UploadFile $file) |
||
159 | { |
||
160 | if (parent::validate($file)) { |
||
161 | |||
162 | $info = getimagesize($file->getFileTemp()); |
||
163 | $width = $info[ 0 ]; |
||
164 | $height = $info[ 1 ]; |
||
165 | |||
166 | /* Validate width min size */ |
||
167 | if ($this->allowedImageSize[ 'width' ][ 'min' ] > 0) { |
||
168 | if ($width < $this->allowedImageSize[ 'width' ][ 'min' ]) { |
||
169 | $this->errors[] = language()->getLine( |
||
170 | 'IMAGE_E_ALLOWED_MIN_WIDTH_SIZE', |
||
171 | [$this->allowedFileSize[ 'min' ], $width] |
||
172 | ); |
||
173 | } |
||
174 | } |
||
175 | |||
176 | /* Validate width max size */ |
||
177 | if ($this->allowedImageSize[ 'width' ][ 'max' ] > 0) { |
||
178 | if ($width > $this->allowedImageSize[ 'width' ][ 'max' ]) { |
||
179 | $this->errors[] = language()->getLine( |
||
180 | 'IMAGE_E_ALLOWED_MAX_WIDTH_SIZE', |
||
181 | [$this->allowedFileSize[ 'max' ], $width] |
||
182 | ); |
||
183 | } |
||
184 | } |
||
185 | |||
186 | /* Validate height min size */ |
||
187 | if ($this->allowedImageSize[ 'height' ][ 'min' ] > 0) { |
||
188 | if ($height < $this->allowedImageSize[ 'width' ][ 'min' ]) { |
||
189 | $this->errors[] = language()->getLine( |
||
190 | 'IMAGE_E_ALLOWED_MIN_HEIGHT_SIZE', |
||
191 | [$this->allowedFileSize[ 'min' ], $height] |
||
192 | ); |
||
193 | } |
||
194 | } |
||
195 | |||
196 | /* Validate height max size */ |
||
197 | if ($this->allowedImageSize[ 'height' ][ 'max' ] > 0) { |
||
198 | if ($height > $this->allowedImageSize[ 'width' ][ 'max' ]) { |
||
199 | $this->errors[] = language()->getLine( |
||
200 | 'IMAGE_E_ALLOWED_MAX_HEIGHT_SIZE', |
||
201 | [$this->allowedFileSize[ 'max' ], $height] |
||
202 | ); |
||
203 | } |
||
204 | } |
||
205 | } |
||
206 | |||
207 | if (count($this->errors) == 0) { |
||
208 | return true; |
||
209 | } |
||
210 | |||
211 | return false; |
||
212 | } |
||
213 | } |