Completed
Push — master ( b0c99e...a2c34e )
by Doug
02:39
created

IrishGridRef::getOriginNorthing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * PHPCoord
4
 * @package PHPCoord
5
 * @author Doug Wright
6
 */
7
namespace PHPCoord;
8
9
/**
10
 * Irish grid reference (pre-ITM)
11
 * References are accurate to 1m
12
 * @author Doug Wright
13
 * @package PHPCoord
14
 */
15
class IrishGridRef extends TransverseMercator
16
{
17
18
    const GRID_LETTERS = "VWXYZQRSTULMNOPFGHJKABCDE";
19
20 1
    public function getReferenceEllipsoid()
21
    {
22 1
        return RefEll::airyModified();
23
    }
24
25 1
    public function getScaleFactor()
26
    {
27 1
        return 1.000035;
28
    }
29
30 1
    public function getOriginNorthing()
31
    {
32 1
        return 250000;
33
    }
34
35 1
    public function getOriginEasting()
36
    {
37 1
        return 200000;
38
    }
39
40 1
    public function getOriginLatitude()
41
    {
42 1
        return 53.5;
43
    }
44
45 1
    public function getOriginLongitude()
46
    {
47 1
        return -8;
48
    }
49
50
    /**
51
     * @param int $x
52
     * @param int $y
53
     */
54 6
    public function __construct($x, $y)
55
    {
56 6
        parent::__construct($x, $y, 0, RefEll::airyModified());
57 6
    }
58
59
    /**
60
     * Take a string formatted as a six-figure grid reference (e.g.
61
     * "T514131") and return a reference to an IrishGridRef object that represents
62
     * that grid reference.
63
     *
64
     * @param string $ref
65
     * @return OSRef
0 ignored issues
show
Documentation introduced by
Should the return type not be IrishGridRef?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
66
     */
67 3
    public static function fromSixFigureReference($ref)
68
    {
69
70 3
        $easting = strpos(self::GRID_LETTERS, $ref[0]) % 5  * 100000 + (substr($ref, 1, 3) * 100);
71 3
        $northing = (floor(strpos(self::GRID_LETTERS, $ref[0]) / 5)) * 100000 + (substr($ref, 4, 3) * 100);
72
73 3
        return new IrishGridRef($easting, $northing);
74
    }
75
76
    /**
77
     * Convert this grid reference into a string using a standard six-figure
78
     * grid reference including the character designation for the 100km
79
     * square. e.g. T514131.
80
     * @return string
81
     */
82 1
    public function toSixFigureReference()
83
    {
84
85 1
        $easting = str_pad($this->x, 6, 0, STR_PAD_LEFT);
86 1
        $northing = str_pad($this->y, 6, 0, STR_PAD_LEFT);
87
88
        //100km grid sq, origin at 0,0
89 1
        $minorSquaresEast = $easting[0] % 5;
90 1
        $minorSquaresNorth = $northing[0] % 5;
91 1
        $minorLetterIndex = (int)(5 * $minorSquaresNorth + $minorSquaresEast);
92 1
        $minorLetter = substr(self::GRID_LETTERS, $minorLetterIndex, 1);
93
94 1
        return $minorLetter . substr($easting, 1, 3) . substr($northing, 1, 3);
95
    }
96
97
    /**
98
     * Convert this grid reference into a latitude and longitude
99
     * @return LatLng
100
     */
101 1 View Code Duplication
    public function toLatLng()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
102
    {
103 1
        $N = $this->y;
104 1
        $E = $this->x;
105 1
        $N0 = $this->getOriginNorthing();
106 1
        $E0 = $this->getOriginEasting();
107 1
        $phi0 = $this->getOriginLatitude();
108 1
        $lambda0 = $this->getOriginLongitude();
109
110 1
        return $this->convertToLatitudeLongitude($N, $E, $N0, $E0, $phi0, $lambda0);
111
    }
112
113
    /**
114
     * String version of coordinate.
115
     * @return string
116
     */
117 4
    public function __toString()
118
    {
119 4
        return "({$this->x}, {$this->y})";
120
    }
121
}
122