| Conditions | 6 |
| Paths | 8 |
| Total Lines | 77 |
| 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 |
||
| 169 | { |
||
| 170 | $φ1 = deg2rad($point1->getLat()); |
||
| 171 | $φ2 = deg2rad($point2->getLat()); |
||
| 172 | $λ1 = deg2rad($point1->getLng()); |
||
| 173 | $λ2 = deg2rad($point2->getLng()); |
||
| 174 | |||
| 175 | $a = $point1->getEllipsoid()->getA(); |
||
| 176 | $b = $point1->getEllipsoid()->getB(); |
||
| 177 | $f = 1 / $point1->getEllipsoid()->getF(); |
||
| 178 | |||
| 179 | $L = $λ2 - $λ1; |
||
| 180 | |||
| 181 | $tanU1 = (1 - $f) * tan($φ1); |
||
| 182 | $cosU1 = 1 / sqrt(1 + $tanU1 * $tanU1); |
||
| 183 | $sinU1 = $tanU1 * $cosU1; |
||
| 184 | $tanU2 = (1 - $f) * tan($φ2); |
||
| 185 | $cosU2 = 1 / sqrt(1 + $tanU2 * $tanU2); |
||
| 186 | $sinU2 = $tanU2 * $cosU2; |
||
| 187 | |||
| 188 | $λ = $L; |
||
| 189 | |||
| 190 | $iterations = 0; |
||
| 191 | |||
| 192 | do { |
||
| 193 | $sinλ = sin($λ); |
||
| 194 | $cosλ = cos($λ); |
||
| 195 | $sinSqσ = ($cosU2 * $sinλ) * ($cosU2 * $sinλ) |
||
| 196 | + ($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosλ) * ($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosλ); |
||
| 197 | $sinσ = sqrt($sinSqσ); |
||
| 198 | |||
| 199 | if ($sinσ == 0) { |
||
| 200 | new InverseVincentyBearing(0, 0, 0); |
||
| 201 | } |
||
| 202 | |||
| 203 | $cosσ = $sinU1 * $sinU2 + $cosU1 * $cosU2 * $cosλ; |
||
| 204 | $σ = atan2($sinσ, $cosσ); |
||
| 205 | $sinα = $cosU1 * $cosU2 * $sinλ / $sinσ; |
||
| 206 | $cosSqα = 1 - $sinα * $sinα; |
||
| 207 | |||
| 208 | $cos2σM = 0; |
||
| 209 | if ($cosSqα !== 0.0) { |
||
| 210 | $cos2σM = $cosσ - 2 * $sinU1 * $sinU2 / $cosSqα; |
||
| 211 | } |
||
| 212 | |||
| 213 | $C = $f / 16 * $cosSqα * (4 + $f * (4 - 3 * $cosSqα)); |
||
| 214 | $λp = $λ; |
||
| 215 | $λ = $L + (1 - $C) * $f * $sinα * ($σ + $C * $sinσ * ($cos2σM + $C * $cosσ * (-1 + 2 * $cos2σM * $cos2σM))); |
||
| 216 | } while (abs($λ - $λp) > 1e-12 && ++$iterations < 200); |
||
| 217 | |||
| 218 | if ($iterations >= 200) { |
||
| 219 | throw new NotConvergingException('Inverse Vincenty Formula did not converge'); |
||
| 220 | } |
||
| 221 | |||
| 222 | $uSq = $cosSqα * ($a * $a - $b * $b) / ($b * $b); |
||
| 223 | $A = 1 + $uSq / 16384 * (4096 + $uSq * (-768 + $uSq * (320 - 175 * $uSq))); |
||
| 224 | $B = $uSq / 1024 * (256 + $uSq * (-128 + $uSq * (74 - 47 * $uSq))); |
||
| 225 | $Δσ = $B * $sinσ |
||
| 226 | * ($cos2σM + $B / 4 |
||
| 227 | * ($cosσ * (-1 + 2 * $cos2σM * $cos2σM) - $B / 6 |
||
| 228 | * $cos2σM * (-3 + 4 * $sinσ * $sinσ) |
||
| 229 | * (-3 + 4 * $cos2σM * $cos2σM) |
||
| 230 | ) |
||
| 231 | ); |
||
| 232 | |||
| 233 | $s = $b * $A * ($σ - $Δσ); |
||
| 234 | |||
| 235 | $α1 = atan2($cosU2 * $sinλ, $cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosλ); |
||
| 236 | $α2 = atan2($cosU1 * $sinλ, -$sinU1 * $cosU2 + $cosU1 * $sinU2 * $cosλ); |
||
| 237 | |||
| 238 | $α1 = fmod($α1 + 2 * M_PI, 2 * M_PI); |
||
| 239 | $α2 = fmod($α2 + 2 * M_PI, 2 * M_PI); |
||
| 240 | |||
| 241 | $s = round($s, 3); |
||
| 242 | |||
| 243 | return new InverseVincentyBearing($s, rad2deg($α1), rad2deg($α2)); |
||
| 244 | } |
||
| 245 | } |
||
| 246 |