| Conditions | 7 |
| Paths | 25 |
| Total Lines | 55 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 3 | 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 |
||
| 39 | public function uploadProcess( UploadEvent $event ) |
||
| 40 | { |
||
| 41 | $file = $event->getFile()->all(); |
||
| 42 | $fileUploaded = $file['file']; |
||
| 43 | $model = $event->getMediableModel(); |
||
| 44 | $model_id = $event->getMediableId(); |
||
| 45 | $resize_option = $event->getContainer()->getParameter('mykees.media.resize'); |
||
| 46 | $extension = pathinfo($fileUploaded->getClientOriginalName(), PATHINFO_EXTENSION); |
||
| 47 | $DS = DIRECTORY_SEPARATOR; |
||
| 48 | |||
| 49 | |||
| 50 | if( $this->isValidExtension($extension,$event) ) |
||
| 51 | { |
||
| 52 | //create dir |
||
| 53 | $webroot = $event->getRootDir().'/../web'; |
||
| 54 | $dir = $webroot.'/img'; |
||
| 55 | |||
| 56 | if(!file_exists($dir)){mkdir($dir,0777);} |
||
| 57 | |||
| 58 | $dir .= $DS.date('Y'); |
||
| 59 | if(!file_exists($dir)){mkdir($dir,0777);} |
||
| 60 | |||
| 61 | $dir .= $DS.date('m'); |
||
| 62 | if(!file_exists($dir)){mkdir($dir,0777);} |
||
| 63 | |||
| 64 | //clean and define path filename |
||
| 65 | $filename = $this->cleanFilename( $fileUploaded->getClientOriginalName(), $extension ); |
||
| 66 | //test duplicate |
||
| 67 | $name = $this->mediaExist( $filename,$webroot ); |
||
| 68 | |||
| 69 | $filePath = date('Y').'/'.date('m').'/'.$name; |
||
| 70 | $save_media = $this->saveMedia($filePath, $name, $model, $model_id); |
||
| 71 | |||
| 72 | if($save_media) |
||
| 73 | { |
||
| 74 | //upload |
||
| 75 | $fileUploaded->move($dir,$name); |
||
| 76 | $event->setMedia($save_media); |
||
| 77 | |||
| 78 | if(!empty($resize_option[$model])) |
||
| 79 | { |
||
| 80 | $resize = new ResizeHelper($resize_option[$model], $webroot); |
||
| 81 | $resize->resize($save_media->getFile()); |
||
| 82 | } |
||
| 83 | |||
| 84 | return true; |
||
| 85 | }else{ |
||
| 86 | |||
| 87 | return new Response(); |
||
| 88 | } |
||
| 89 | }else{ |
||
| 90 | |||
| 91 | return new Response(); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 177 |