| Conditions | 4 |
| Paths | 8 |
| Total Lines | 55 |
| Code Lines | 37 |
| 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 | public static function Calculate_Obs($_time, Predict_Vector $pos, Predict_Vector $vel, Predict_Geodetic $geodetic, Predict_ObsSet $obs_set) |
||
| 101 | { |
||
| 102 | $obs_pos = new Predict_Vector(); |
||
| 103 | $obs_vel = new Predict_Vector(); |
||
| 104 | $range = new Predict_Vector(); |
||
| 105 | $rgvel = new Predict_Vector(); |
||
| 106 | |||
| 107 | self::Calculate_User_PosVel($_time, $geodetic, $obs_pos, $obs_vel); |
||
| 108 | |||
| 109 | $range->x = $pos->x - $obs_pos->x; |
||
| 110 | $range->y = $pos->y - $obs_pos->y; |
||
| 111 | $range->z = $pos->z - $obs_pos->z; |
||
| 112 | |||
| 113 | $rgvel->x = $vel->x - $obs_vel->x; |
||
| 114 | $rgvel->y = $vel->y - $obs_vel->y; |
||
| 115 | $rgvel->z = $vel->z - $obs_vel->z; |
||
| 116 | |||
| 117 | $range->w = sqrt($range->x * $range->x + $range->y * $range->y + $range->z * $range->z); |
||
| 118 | |||
| 119 | $sin_lat = sin($geodetic->lat); |
||
| 120 | $cos_lat = cos($geodetic->lat); |
||
| 121 | $sin_theta = sin($geodetic->theta); |
||
| 122 | $cos_theta = cos($geodetic->theta); |
||
| 123 | $top_s = $sin_lat * $cos_theta * $range->x |
||
| 124 | + $sin_lat * $sin_theta * $range->y |
||
| 125 | - $cos_lat * $range->z; |
||
| 126 | $top_e = -$sin_theta * $range->x |
||
| 127 | + $cos_theta * $range->y; |
||
| 128 | $top_z = $cos_lat * $cos_theta * $range->x |
||
| 129 | + $cos_lat * $sin_theta * $range->y |
||
| 130 | + $sin_lat * $range->z; |
||
| 131 | $azim = atan(-$top_e / $top_s); /*Azimuth*/ |
||
| 132 | if ($top_s > 0) { |
||
| 133 | $azim = $azim + Predict::pi; |
||
| 134 | } |
||
| 135 | if ($azim < 0 ) { |
||
| 136 | $azim = $azim + Predict::twopi; |
||
| 137 | } |
||
| 138 | $el = Predict_Math::ArcSin($top_z / $range->w); |
||
| 139 | $obs_set->az = $azim; /* Azimuth (radians) */ |
||
| 140 | $obs_set->el = $el; /* Elevation (radians)*/ |
||
| 141 | $obs_set->range = $range->w; /* Range (kilometers) */ |
||
| 142 | |||
| 143 | /* Range Rate (kilometers/second)*/ |
||
| 144 | $obs_set->range_rate = Predict_Math::Dot($range, $rgvel) / $range->w; |
||
| 145 | |||
| 146 | /* Corrections for atmospheric refraction */ |
||
| 147 | /* Reference: Astronomical Algorithms by Jean Meeus, pp. 101-104 */ |
||
| 148 | /* Correction is meaningless when apparent elevation is below horizon */ |
||
| 149 | // obs_set->el = obs_set->el + Radians((1.02/tan(Radians(Degrees(el)+ |
||
| 150 | // 10.3/(Degrees(el)+5.11))))/60); |
||
| 151 | if ($obs_set->el < 0) { |
||
| 152 | $obs_set->el = $el; /*Reset to true elevation*/ |
||
| 153 | } |
||
| 154 | } |
||
| 155 | } |
||
| 156 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.