Completed
Push — master ( ef1b0f...4b6367 )
by Gordon
17:36
created

ImageMetaDataExtension::getMappableLatitude()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
class ImageMetaDataExtension extends MapExtension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    public static $db = array(
6
        'ExifRead' => 'Boolean',
7
        'Aperture' => 'Varchar',
8
        'ShutterSpeed' => 'Varchar',
9
        'TakenAt' => 'Datetime',
10
        'ISO' => 'Int',
11
        'Orientation' => 'Int',
12
    );
13
14
    public function processExifData()
15
    {
16
        $filename = BASE_PATH.'/'.$this->owner->Image()->Filename;
17
18
        // when the image is first saved, the file will still be a temp file
19
        if (file_exists($filename)) {
20
            try {
21
            $exif = exif_read_data($filename, 0, true);
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 16 spaces, but found 12).
Loading history...
22
23
            $aperture = $exif['COMPUTED']['ApertureFNumber'];
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 16 spaces, but found 12).
Loading history...
24
25
            $aperture = str_replace('f/', '', $aperture);
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 16 spaces, but found 12).
Loading history...
26
            error_log('APERTURE:'.$aperture);
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 16 spaces, but found 12).
Loading history...
27
28
            $this->owner->Aperture = $aperture;
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 16 spaces, but found 12).
Loading history...
29
30
            $shutterspeed = '';
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 16 spaces, but found 12).
Loading history...
31
            if (isset($exif['ExposureTime'])) {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 12
Loading history...
32
                $shutterspeed = $exif['ExposureTime'];
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 20 spaces, but found 16).
Loading history...
33
            } else {
34
                $shutterspeed = $exif['EXIF']['ExposureTime'];
35
            }
36
37
            error_log('EXPOSURE:'.$shutterspeed);
38
            $this->owner->ShutterSpeed = $shutterspeed;
39
            if (isset($exif['DateTimeOriginal'])) {
40
                $this->owner->TakenAt = $exif['DateTimeOriginal'];
41
            } else {
42
                $this->owner->TakenAt = $exif['EXIF']['DateTimeOriginal'];
43
            }
44
45
            $iso = '';
46
            if (isset($exif['ISOSpeedRatings'])) {
47
                $iso = $exif['ISOSpeedRatings'];
48
            } else {
49
                $iso = $exif['EXIF']['ISOSpeedRatings'];
50
            }
51
52
            $this->owner->ISO = $iso;
53
            error_log('ISO:'.$iso);
54
55
            // coors
56
            if (isset($exif['GPS'])) {
57
                $gps = $exif['GPS'];
58
                $latarray = $gps['GPSLatitude'];
59
                $degrees = $latarray[0];
60
                $parts = explode('/', $degrees);
61
                $degrees = $parts[0] / $parts[1];
62
                $minutes = $latarray[1];
63
                $parts = explode('/', $minutes);
64
                $minutes = $parts[0] / $parts[1];
65
                $seconds = $latarray[2];
66
                $parts = explode('/', $seconds);
67
                $seconds = $parts[0] / $parts[1];
68
69
                error_log('LATITUDE: DMS='.$degrees.','.$minutes.','.$seconds);
70
                $latitude = $degrees + $minutes / 60 + $seconds / 3600;
71
                error_log('LAT:'.$latitude);
72
73
                error_log('LATITUDE:'.$latitude);
74
75
                $lonarray = $gps['GPSLongitude'];
76
                $degrees = $lonarray[0];
77
                $parts = explode('/', $degrees);
78
                $degrees = $parts[0] / $parts[1];
79
                $minutes = $lonarray[1];
80
                $parts = explode('/', $minutes);
81
                $minutes = $parts[0] / $parts[1];
82
                $seconds = $lonarray[2];
83
                $parts = explode('/', $seconds);
84
                $seconds = $parts[0] / $parts[1];
85
86
                $longitude = $degrees + $minutes / 60 + $seconds / 3600;
87
                $this->owner->Lat = $latitude;
88
                $this->owner->Lon = $longitude;
89
                } // else no gps data
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
Coding Style introduced by
Closing brace indented incorrectly; expected 12 spaces, found 16
Loading history...
90
91
                $image = $this->owner->Image();
92
                if ($image->Height > $image->Width) {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
93
                    $this->owner->Orientation = 90;
94
                }
95
96
                $this->owner->ExifRead = true;
97
                $this->owner->write();
98
            } catch (Exception $e) {
99
                error_log($e);
100
            }
101
        }
102
    }
103
104
    public function onAfterWriteNOT()
105
    {
106
        parent::onAfterWrite();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (onAfterWrite() instead of onAfterWriteNOT()). Are you sure this is correct? If so, you might want to change this to $this->onAfterWrite().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
107
108
        if (!($this->owner->ExifRead)) {
109
            $this->processExifData();
110
        }
111
    }
112
113
    public function requireDefaultRecordsNOT()
114
    {
115
        parent::requireDefaultRecords();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (requireDefaultRecords() instead of requireDefaultRecordsNOT()). Are you sure this is correct? If so, you might want to change this to $this->requireDefaultRecords().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
116
        $imagesToProcess = GalleryImage::get()->filter('ExifRead', false);
117
        foreach ($imagesToProcess->getIterator() as $image) {
118
            $image->processExifData();
119
        }
120
    }
121
122
}
123