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 |
||
83 | public function upload(ResponsiveImageInterface $image) |
||
84 | { |
||
85 | // Dispatch pre-upload event. |
||
86 | if (!empty($this->eventDispatcher)) { |
||
87 | $uploaderEvent = new UploaderEvent($this); |
||
88 | $this->eventDispatcher->dispatch(UploaderEvents::UPLOADER_PRE_UPLOAD, $uploaderEvent); |
||
89 | } |
||
90 | |||
91 | $this->file = $image->getFile(); |
||
92 | |||
93 | // Use UploadedFile's inbuilt validation and allow |
||
94 | // implementation specific custom checks on uploaded file |
||
95 | if ($this->file->isValid() && $this->isValid()) { |
||
96 | |||
97 | // Alter name for uniqueness |
||
98 | $path = $this->formatPath(); |
||
99 | |||
100 | $info = getimagesize($this->file); |
||
101 | list($length, $height) = $info; |
||
102 | |||
103 | // Save the actual file to the filesystem. |
||
104 | $stream = fopen($this->file->getRealPath(), 'r+'); |
||
105 | $this->fileSystem->writeStream($path, $stream); |
||
106 | fclose($stream); |
||
107 | |||
108 | $image->setPath($path); |
||
109 | $image->setHeight($length); |
||
110 | $image->setWidth($height); |
||
111 | |||
112 | // If the image has a setFileSystem method set the filesystem data. |
||
113 | if (method_exists($image, 'setFileSystem')) { |
||
114 | $storageData = $this->getStorageDataFormFileSystem(); |
||
115 | if (!empty($storageData)) { |
||
116 | $image->setFileSystem(serialize($storageData)); |
||
|
|||
117 | } |
||
118 | } |
||
119 | |||
120 | // Clean up the file property as you won't need it anymore. |
||
121 | $this->file = null; |
||
122 | $image->setFile(null); |
||
123 | |||
124 | // Dispatch uploaded event |
||
125 | if (!empty($uploaderEvent)) { |
||
126 | $this->eventDispatcher->dispatch(UploaderEvents::UPLOADER_UPLOADED, $uploaderEvent); |
||
127 | } |
||
128 | } |
||
129 | else { |
||
130 | $error = empty($this->error) ? $this->file->getErrorMessage() : $this->error; |
||
131 | throw new FileException( |
||
132 | $error |
||
133 | ); |
||
134 | } |
||
135 | } |
||
136 | |||
197 |
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.