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