Conditions | 4 |
Paths | 2 |
Total Lines | 67 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |
||
100 | private function directVincenty(Coordinate $point, float $bearing, float $distance): DirectVincentyBearing |
||
101 | { |
||
102 | $phi1 = deg2rad($point->getLat()); |
||
103 | $lambda1 = deg2rad($point->getLng()); |
||
104 | $alpha1 = deg2rad($bearing); |
||
105 | |||
106 | $a = $point->getEllipsoid()->getA(); |
||
107 | $b = $point->getEllipsoid()->getB(); |
||
108 | $f = 1 / $point->getEllipsoid()->getF(); |
||
109 | |||
110 | $sinAlpha1 = sin($alpha1); |
||
111 | $cosAlpha1 = cos($alpha1); |
||
112 | |||
113 | $tanU1 = (1 - $f) * tan($phi1); |
||
114 | $cosU1 = 1 / sqrt(1 + $tanU1 * $tanU1); |
||
115 | $sinU1 = $tanU1 * $cosU1; |
||
116 | $sigma1 = atan2($tanU1, $cosAlpha1); |
||
117 | $sinAlpha = $cosU1 * $sinAlpha1; |
||
118 | $cosSquAlpha = 1 - $sinAlpha * $sinAlpha; |
||
119 | $uSq = $cosSquAlpha * ($a * $a - $b * $b) / ($b * $b); |
||
120 | $A = 1 + $uSq / 16384 * (4096 + $uSq * (-768 + $uSq * (320 - 175 * $uSq))); |
||
121 | $B = $uSq / 1024 * (256 + $uSq * (-128 + $uSq * (74 - 47 * $uSq))); |
||
122 | |||
123 | $sigmaS = $distance / ($b * $A); |
||
124 | $sigma = $sigmaS; |
||
125 | $iterations = 0; |
||
126 | |||
127 | do { |
||
128 | $cos2SigmaM = cos(2 * $sigma1 + $sigma); |
||
129 | $sinSigma = sin($sigma); |
||
130 | $cosSigma = cos($sigma); |
||
131 | $deltaSigma = $B * $sinSigma |
||
132 | * ($cos2SigmaM + $B / 4 |
||
133 | * ($cosSigma |
||
134 | * (-1 + 2 * $cos2SigmaM * $cos2SigmaM) - $B / 6 |
||
135 | * $cos2SigmaM * (-3 + 4 * $sinSigma * $sinSigma) |
||
136 | * (-3 + 4 * $cos2SigmaM * $cos2SigmaM) |
||
137 | ) |
||
138 | ); |
||
139 | $sigmaS = $sigma; |
||
140 | $sigma = $distance / ($b * $A) + $deltaSigma; |
||
141 | } while (abs($sigma - $sigmaS) > 1e-12 && ++$iterations < 200); |
||
142 | |||
143 | if ($iterations >= 200) { |
||
144 | throw new NotConvergingException('Inverse Vincenty Formula did not converge'); |
||
145 | } |
||
146 | |||
147 | $tmp = $sinU1 * $sinSigma - $cosU1 * $cosSigma * $cosAlpha1; |
||
148 | $phi2 = atan2( |
||
149 | $sinU1 * $cosSigma + $cosU1 * $sinSigma * $cosAlpha1, |
||
150 | (1 - $f) * sqrt($sinAlpha * $sinAlpha + $tmp * $tmp) |
||
151 | ); |
||
152 | $lambda = atan2($sinSigma * $sinAlpha1, $cosU1 * $cosSigma - $sinU1 * $sinSigma * $cosAlpha1); |
||
153 | $C = $f / 16 * $cosSquAlpha * (4 + $f * (4 - 3 * $cosSquAlpha)); |
||
154 | $L = $lambda |
||
155 | - (1 - $C) * $f * $sinAlpha |
||
156 | * ($sigma + $C * $sinSigma * ($cos2SigmaM + $C * $cosSigma * (-1 + 2 * $cos2SigmaM ** 2))); |
||
157 | $lambda2 = fmod($lambda1 + $L + 3 * M_PI, 2 * M_PI) - M_PI; |
||
158 | |||
159 | $alpha2 = atan2($sinAlpha, -$tmp); |
||
160 | $alpha2 = fmod($alpha2 + 2 * M_PI, 2 * M_PI); |
||
161 | |||
162 | return new DirectVincentyBearing( |
||
163 | new Coordinate(rad2deg($phi2), rad2deg($lambda2), $point->getEllipsoid()), |
||
164 | rad2deg($alpha2) |
||
165 | ); |
||
166 | } |
||
167 | |||
255 |