| Conditions | 8 |
| Paths | 16 |
| Total Lines | 53 |
| 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 |
||
| 73 | public function upload(ResponsiveImageInterface $image) |
||
| 74 | { |
||
| 75 | // Dispatch pre-upload event. |
||
| 76 | if (!empty($this->eventDispatcher)) { |
||
| 77 | $uploaderEvent = new UploaderEvent($this); |
||
| 78 | $this->eventDispatcher->dispatch(UploaderEvents::UPLOADER_PRE_UPLOAD, $uploaderEvent); |
||
| 79 | } |
||
| 80 | |||
| 81 | $this->file = $image->getFile(); |
||
| 82 | |||
| 83 | // Use UploadedFile's inbuilt validation and allow |
||
| 84 | // implementation specific custom checks on uploaded file |
||
| 85 | if ($this->file->isValid() && $this->isValid()) { |
||
| 86 | |||
| 87 | // Alter name for uniqueness |
||
| 88 | $path = $this->formatPath(); |
||
| 89 | |||
| 90 | $info = getimagesize($this->file); |
||
| 91 | list($length, $height) = $info; |
||
| 92 | |||
| 93 | // Save the actual file to the filesystem. |
||
| 94 | $stream = fopen($this->file->getRealPath(), 'r+'); |
||
| 95 | $this->fileSystem->writeStream($path, $stream); |
||
| 96 | fclose($stream); |
||
| 97 | |||
| 98 | $image->setPath($path); |
||
| 99 | $image->setHeight($length); |
||
| 100 | $image->setWidth($height); |
||
| 101 | |||
| 102 | // If the image has a setFileSystem method set the filesystem data. |
||
| 103 | if (method_exists($image, 'setFileSystem')) { |
||
| 104 | $storageData = $this->getStorageDataFormFileSystem(); |
||
| 105 | if (!empty($storageData)) { |
||
| 106 | $image->setFileSystem(serialize($storageData)); |
||
|
|
|||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | // Clean up the file property as you won't need it anymore. |
||
| 111 | $this->file = null; |
||
| 112 | $image->setFile(null); |
||
| 113 | |||
| 114 | // Dispatch uploaded event |
||
| 115 | if (!empty($uploaderEvent)) { |
||
| 116 | $this->eventDispatcher->dispatch(UploaderEvents::UPLOADER_UPLOADED, $uploaderEvent); |
||
| 117 | } |
||
| 118 | } |
||
| 119 | else { |
||
| 120 | $error = empty($this->error) ? $this->file->getErrorMessage() : $this->error; |
||
| 121 | throw new FileException( |
||
| 122 | $error |
||
| 123 | ); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 187 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.