GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CoordinatesFieldMapper   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 3
dl 0
loc 78
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSupportedFields() 0 6 1
C mapField() 0 24 7
A extractGpsCoordinate() 0 12 1
A normalizeCoordinatePartData() 0 10 2
1
<?php
2
/**
3
 * Mapper for mapping data between raw input and a Height VO
4
 *
5
 * @link        http://github.com/PHPExif/php-exif-native for the canonical source repository
6
 * @copyright   Copyright (c) 2016 Tom Van Herreweghe <[email protected]>
7
 * @license     http://github.com/PHPExif/php-exif-native/blob/master/LICENSE MIT License
8
 * @category    PHPExif
9
 * @package     Native
10
 */
11
12
namespace PHPExif\Adapter\Native\Reader\Mapper\Exif;
13
14
use PHPExif\Common\Data\ExifInterface;
15
use PHPExif\Common\Data\ValueObject\Coordinates;
16
use PHPExif\Common\Data\ValueObject\DigitalDegrees;
17
use PHPExif\Common\Mapper\FieldMapper;
18
use PHPExif\Common\Mapper\GuardInvalidArgumentsForExifTrait;
19
20
/**
21
 * Mapper
22
 *
23
 * @category    PHPExif
24
 * @package     Native
25
 */
26
class CoordinatesFieldMapper implements FieldMapper
27
{
28
    use GuardInvalidArgumentsForExifTrait;
29
30
    /**
31
     * {@inheritDoc}
32
     */
33
    public function getSupportedFields()
34
    {
35
        return array(
36
            Coordinates::class,
37
        );
38
    }
39
40
    /**
41
     * {@inheritDoc}
42
     */
43
    public function mapField($field, array $input, &$output)
44
    {
45
        $this->guardInvalidArguments($field, $input, $output);
46
47
        if (!(array_key_exists('gpslatitude', $input) && array_key_exists('gpslongitude', $input))) {
48
            return;
49
        }
50
51
        $latitude = $this->extractGpsCoordinate($input['gpslatitude']);
52
        $longitude = $this->extractGpsCoordinate($input['gpslongitude']);
53
        $latitudeRef = empty($input['gpslatituderef'][0]) ? 'N' : $input['gpslatituderef'][0];
54
        $longitudeRef = empty($input['gpslongituderef'][0]) ? 'E' : $input['gpslongituderef'][0];
55
56
        $coordinates = new Coordinates(
57
            new DigitalDegrees(
58
                round((strtoupper($latitudeRef) === 'S' ? -1 : 1) * $latitude, 6)
59
            ),
60
            new DigitalDegrees(
61
                round((strtoupper($longitudeRef) === 'W' ? -1 : 1) * $longitude, 6)
62
            )
63
        );
64
65
        $output = $output->withCoordinates($coordinates);
66
    }
67
68
    /**
69
     * Extract & convert GPS coordinate to digital degrees
70
     *
71
     * @param array $data
72
     *
73
     * @return float
74
     */
75
    protected function extractGpsCoordinate(array $data)
76
    {
77
        // make sure we always have 3 components
78
        $default = [0, 0, 0];
79
        $data = array_replace($default, $data);
80
81
        // normalize the components
82
        array_walk($data, array($this, 'normalizeCoordinatePartData'));
83
84
        // convert to digital degrees
85
        return floatval($data[0]) + floatval($data[1]/60) + floatval($data[2]/3600);
86
    }
87
88
    /**
89
     * Converts notations like 5610/100 to 56.1
90
     *
91
     * @param mixed $data
92
     */
93
    protected function normalizeCoordinatePartData(&$data)
94
    {
95
        $parts = explode('/', $data);
96
97
        if (count($parts) == 1) {
98
            return $parts[0];
99
        }
100
101
        $data = floatval($parts[0]) / floatval($parts[1]);
102
    }
103
}
104