Conditions | 8 |
Paths | 21 |
Total Lines | 60 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
170 | public function profileImageCreate($file) |
||
171 | { |
||
172 | if (!file_exists($file)) { |
||
173 | throw new Exceptions\Exception('Profile image creation file does not exist.'); |
||
174 | } |
||
175 | $f3 = \Base::instance(); |
||
176 | |||
177 | // read exif metadata |
||
178 | $reader = \PHPExif\Reader\Reader::factory(\PHPExif\Reader\Reader::TYPE_NATIVE); |
||
179 | $exif = $reader->read($file); |
||
180 | $metadata = $exif->getData(); |
||
181 | unset($exif); |
||
182 | |||
183 | // load image |
||
184 | $img = new \Image($file); |
||
185 | |||
186 | // make sure maximum width/height not exceeded |
||
187 | $max = $f3->get('assets.image.max'); |
||
188 | $height = $img->height(); |
||
189 | $width = $img->width(); |
||
190 | if ($width > $max['width'] || $height > $max['height']) { |
||
191 | $height = $height > $max['height'] ? $max['height'] : $height; |
||
192 | $width = $width > $max['width'] ? $max['width'] : $width; |
||
193 | $img->resize($width, $height); |
||
194 | } |
||
195 | |||
196 | // remove pre-existing cached-images |
||
197 | $dirPath = $this->profileImageDirPath(); |
||
198 | foreach (glob($dirPath . '/*.jpg') as $file) { |
||
199 | unlink($file); |
||
200 | } |
||
201 | |||
202 | // convert to .png, create new profile image file, overwrites existing |
||
203 | $profileImagePath = $this->profileImageFilePath(); |
||
204 | if (!$f3->write($profileImagePath, $img->dump('png', $f3->get('assets.image.default.quality.png')))) { |
||
205 | return false; |
||
206 | } |
||
207 | |||
208 | // create asset table entry |
||
209 | $asset = new Assets; |
||
210 | |||
211 | // load pre existing asset |
||
212 | $asset->load(['users_uuid = ? AND ' . $this->db->quoteKey('key') . ' = ?', $this->uuid, 'profile']); |
||
213 | |||
214 | // set values |
||
215 | $asset->users_uuid = $this->uuid; |
||
216 | $asset->filename = $profileImagePath; |
||
217 | $asset->name = $this->firstname . ' ' . $this->lastname; |
||
218 | $asset->description = $this->firstname . ' ' . $this->lastname . ' Profile Image'; |
||
219 | $asset->size = filesize($profileImagePath); |
||
220 | $asset->url = $this->url($this->profileImageUrl()); |
||
221 | $asset->type = 'image/png'; |
||
222 | $asset->key = 'profile'; |
||
223 | $asset->groups = 'users'; |
||
224 | $asset->categories = 'profile'; |
||
225 | $asset->tags = 'users,profile'; |
||
226 | $asset->metadata = json_encode($metadata, JSON_PRETTY_PRINT); |
||
227 | |||
228 | return $asset->save(); |
||
229 | } |
||
230 | } |
||
231 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.