| Conditions | 7 |
| Paths | 250 |
| Total Lines | 76 |
| Code Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 52 |
| CRAP Score | 7.0817 |
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 |
||
| 17 | 1 | public function processExifData() |
|
| 18 | { |
||
| 19 | 1 | $image = $this->owner->Image(); |
|
| 20 | 1 | $filename = BASE_PATH . '/' . $image->Filename; |
|
| 21 | |||
| 22 | // when the image is first saved, the file will still be a temp file |
||
| 23 | 1 | if ($image->exists()) { |
|
| 24 | try { |
||
| 25 | 1 | $exif = exif_read_data($filename, null, true); |
|
| 26 | 1 | $aperture = $exif['COMPUTED']['ApertureFNumber']; |
|
| 27 | 1 | $aperture = str_replace('f/', '', $aperture); |
|
| 28 | 1 | $this->owner->Aperture = $aperture; |
|
| 29 | |||
| 30 | 1 | $shutterspeed = ''; |
|
| 31 | 1 | if (isset($exif['ExposureTime'])) { |
|
| 32 | $shutterspeed = $exif['ExposureTime']; |
||
| 33 | } else { |
||
| 34 | 1 | $shutterspeed = $exif['EXIF']['ExposureTime']; |
|
| 35 | } |
||
| 36 | |||
| 37 | 1 | $this->owner->ShutterSpeed = $shutterspeed; |
|
| 38 | 1 | if (isset($exif['DateTimeOriginal'])) { |
|
| 39 | $this->owner->TakenAt = $exif['DateTimeOriginal']; |
||
| 40 | } else { |
||
| 41 | 1 | $this->owner->TakenAt = $exif['EXIF']['DateTimeOriginal']; |
|
| 42 | } |
||
| 43 | |||
| 44 | 1 | $iso = ''; |
|
| 45 | 1 | if (isset($exif['ISOSpeedRatings'])) { |
|
| 46 | $iso = $exif['ISOSpeedRatings']; |
||
| 47 | } else { |
||
| 48 | 1 | $iso = $exif['EXIF']['ISOSpeedRatings']; |
|
| 49 | } |
||
| 50 | |||
| 51 | 1 | $this->owner->ISO = $iso; |
|
| 52 | |||
| 53 | 1 | if (isset($exif['GPS'])) { |
|
| 54 | 1 | $gps = $exif['GPS']; |
|
| 55 | 1 | $latarray = $gps['GPSLatitude']; |
|
| 56 | 1 | $degrees = $latarray[0]; |
|
| 57 | 1 | $parts = explode('/', $degrees); |
|
| 58 | 1 | $degrees = $parts[0] / $parts[1]; |
|
| 59 | 1 | $minutes = $latarray[1]; |
|
| 60 | 1 | $parts = explode('/', $minutes); |
|
| 61 | 1 | $minutes = $parts[0] / $parts[1]; |
|
| 62 | 1 | $seconds = $latarray[2]; |
|
| 63 | 1 | $parts = explode('/', $seconds); |
|
| 64 | 1 | $seconds = $parts[0] / $parts[1]; |
|
| 65 | 1 | $latitude = $degrees + $minutes / 60 + $seconds / 3600; |
|
| 66 | 1 | $lonarray = $gps['GPSLongitude']; |
|
| 67 | 1 | $degrees = $lonarray[0]; |
|
| 68 | 1 | $parts = explode('/', $degrees); |
|
| 69 | 1 | $degrees = $parts[0] / $parts[1]; |
|
| 70 | 1 | $minutes = $lonarray[1]; |
|
| 71 | 1 | $parts = explode('/', $minutes); |
|
| 72 | 1 | $minutes = $parts[0] / $parts[1]; |
|
| 73 | 1 | $seconds = $lonarray[2]; |
|
| 74 | 1 | $parts = explode('/', $seconds); |
|
| 75 | 1 | $seconds = $parts[0] / $parts[1]; |
|
| 76 | |||
| 77 | 1 | $longitude = $degrees + $minutes / 60 + $seconds / 3600; |
|
| 78 | 1 | $this->owner->Lat = $latitude; |
|
| 79 | 1 | $this->owner->Lon = $longitude; |
|
| 80 | 1 | } |
|
| 81 | |||
| 82 | 1 | $image = $this->owner->Image(); |
|
| 83 | |||
| 84 | 1 | $this->owner->ExifRead = true; |
|
| 85 | 1 | $this->owner->Orientation = $this->owner->Image()->getOrientation(); |
|
| 86 | 1 | $this->owner->write(); |
|
| 87 | } |
||
| 88 | 1 | catch (Exception $e) { |
|
| 89 | error_log($e->getMessage()); |
||
| 90 | } |
||
| 91 | 1 | } |
|
| 92 | 1 | } |
|
| 93 | |||
| 115 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.