Complex classes like Predict often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Predict, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
53 | class Predict |
||
54 | { |
||
55 | const de2ra = 1.74532925E-2; /* Degrees to Radians */ |
||
56 | const pi = 3.1415926535898; /* Pi */ |
||
57 | const pio2 = 1.5707963267949; /* Pi/2 */ |
||
58 | const x3pio2 = 4.71238898; /* 3*Pi/2 */ |
||
59 | const twopi = 6.2831853071796; /* 2*Pi */ |
||
60 | const e6a = 1.0E-6; |
||
61 | const tothrd = 6.6666667E-1; /* 2/3 */ |
||
62 | const xj2 = 1.0826158E-3; /* J2 Harmonic */ |
||
63 | const xj3 = -2.53881E-6; /* J3 Harmonic */ |
||
64 | const xj4 = -1.65597E-6; /* J4 Harmonic */ |
||
65 | const xke = 7.43669161E-2; |
||
66 | const xkmper = 6.378135E3; /* Earth radius km */ |
||
67 | const xmnpda = 1.44E3; /* Minutes per day */ |
||
68 | const km2mi = 0.621371; /* Kilometers per Mile */ |
||
69 | const ae = 1.0; |
||
70 | const ck2 = 5.413079E-4; |
||
71 | const ck4 = 6.209887E-7; |
||
72 | const __f = 3.352779E-3; |
||
73 | const ge = 3.986008E5; |
||
74 | const __s__ = 1.012229; |
||
75 | const qoms2t = 1.880279E-09; |
||
76 | const secday = 8.6400E4; /* Seconds per day */ |
||
77 | const omega_E = 1.0027379; |
||
78 | const omega_ER = 6.3003879; |
||
79 | const zns = 1.19459E-5; |
||
80 | const c1ss = 2.9864797E-6; |
||
81 | const zes = 1.675E-2; |
||
82 | const znl = 1.5835218E-4; |
||
83 | const c1l = 4.7968065E-7; |
||
84 | const zel = 5.490E-2; |
||
85 | const zcosis = 9.1744867E-1; |
||
86 | const zsinis = 3.9785416E-1; |
||
87 | const zsings = -9.8088458E-1; |
||
88 | const zcosgs = 1.945905E-1; |
||
89 | const zcoshs = 1; |
||
90 | const zsinhs = 0; |
||
91 | const q22 = 1.7891679E-6; |
||
92 | const q31 = 2.1460748E-6; |
||
93 | const q33 = 2.2123015E-7; |
||
94 | const g22 = 5.7686396; |
||
95 | const g32 = 9.5240898E-1; |
||
96 | const g44 = 1.8014998; |
||
97 | const g52 = 1.0508330; |
||
98 | const g54 = 4.4108898; |
||
99 | const root22 = 1.7891679E-6; |
||
100 | const root32 = 3.7393792E-7; |
||
101 | const root44 = 7.3636953E-9; |
||
102 | const root52 = 1.1428639E-7; |
||
103 | const root54 = 2.1765803E-9; |
||
104 | const thdt = 4.3752691E-3; |
||
105 | const rho = 1.5696615E-1; |
||
106 | const mfactor = 7.292115E-5; |
||
107 | const __sr__ = 6.96000E5; /*Solar radius - kilometers (IAU 76)*/ |
||
108 | const AU = 1.49597870E8; /*Astronomical unit - kilometers (IAU 76)*/ |
||
109 | |||
110 | /* visibility constants */ |
||
111 | const SAT_VIS_NONE = 0; |
||
112 | const SAT_VIS_VISIBLE = 1; |
||
113 | const SAT_VIS_DAYLIGHT = 2; |
||
114 | const SAT_VIS_ECLIPSED = 3; |
||
115 | |||
116 | /* preferences */ |
||
117 | public $minEle = 10; // Minimum elevation |
||
118 | public $timeRes = 10; // Pass details: time resolution |
||
119 | public $numEntries = 20; // Pass details: number of entries |
||
120 | public $threshold = -6; // Twilight threshold |
||
121 | |||
122 | /** |
||
123 | * Predict the next pass. |
||
124 | * |
||
125 | * This function simply wraps the get_pass function using the current time |
||
126 | * as parameter. |
||
127 | * |
||
128 | * Note: the data in sat will be corrupt (future) and must be refreshed |
||
129 | * by the caller, if the caller will need it later on (eg. if the caller |
||
130 | * is GtkSatList). |
||
131 | * |
||
132 | * @param Predict_Sat $sat The satellite data. |
||
133 | * @param Predict_QTH $qth The observer data. |
||
134 | * @param int $maxdt The maximum number of days to look ahead. |
||
135 | * |
||
136 | * @return Predict_Pass Pointer instance or NULL if no pass can be |
||
137 | * found. |
||
138 | */ |
||
139 | public function get_next_pass(Predict_Sat $sat, Predict_QTH $qth, $maxdt) |
||
146 | |||
147 | /** Predict first pass after a certain time. |
||
148 | * |
||
149 | * @param Predict_Sat $sat The satellite data. |
||
|
|||
150 | * @param Predict_QTH $qth The observer's location data. |
||
151 | * @param float $start Starting time. |
||
152 | * @param int $maxdt The maximum number of days to look ahead (0 for no limit). |
||
153 | * |
||
154 | * @return Predict_Pass or NULL if there was an error. |
||
155 | * |
||
156 | * This function will find the first upcoming pass with AOS no earlier than |
||
157 | * t = start and no later than t = (start+maxdt). |
||
158 | * |
||
159 | * note For no time limit use maxdt = 0.0 |
||
160 | * |
||
161 | * note the data in sat will be corrupt (future) and must be refreshed |
||
162 | * by the caller, if the caller will need it later on |
||
163 | */ |
||
164 | public function get_pass(Predict_Sat $sat_in, Predict_QTH $qth, $start, $maxdt) |
||
343 | |||
344 | /** |
||
345 | * Calculate satellite visibility. |
||
346 | * |
||
347 | * @param Predict_Sat $sat The satellite structure. |
||
348 | * @param Predict_QTH $qth The QTH |
||
349 | * @param float $jul_utc The time at which the visibility should be calculated. |
||
350 | * |
||
351 | * @return int The visiblity constant, 0, 1, 2, or 3 (see above) |
||
352 | */ |
||
353 | public function get_sat_vis(Predict_Sat $sat, Predict_QTH $qth, $jul_utc) |
||
402 | |||
403 | /** Find the AOS time of the next pass. |
||
404 | * @author Alexandru Csete, OZ9AEC |
||
405 | * @author John A. Magliacane, KD2BD |
||
406 | * @param Predict_Sat $sat The satellite data. |
||
407 | * @param Predict_QTH $qth The observer's location (QTH) data. |
||
408 | * @param float $start The julian date where calculation should start. |
||
409 | * @param int $maxdt The upper time limit in days (0.0 = no limit) |
||
410 | * @return The julain date of the next AOS or 0.0 if the satellite has no AOS. |
||
411 | * |
||
412 | * This function finds the time of AOS for the first coming pass taking place |
||
413 | * no earlier that start. |
||
414 | * If the satellite is currently within range, the function first calls |
||
415 | * find_los to get the next LOS time. Then the calculations are done using |
||
416 | * the new start time. |
||
417 | * |
||
418 | */ |
||
419 | public function find_aos(Predict_Sat $sat, Predict_QTH $qth, $start, $maxdt) |
||
494 | |||
495 | /** SGP4SDP4 driver for doing AOS/LOS calculations. |
||
496 | * @param Predict_Sat $sat The satellite data. |
||
497 | * @param Predict_QTH $qth The QTH observer location data. |
||
498 | * @param float $t The time for calculation (Julian Date) |
||
499 | * |
||
500 | */ |
||
501 | public function predict_calc(Predict_Sat $sat, Predict_QTH $qth, $t) |
||
558 | |||
559 | /** Find the LOS time of the next pass. |
||
560 | * @author Alexandru Csete, OZ9AEC |
||
561 | * @author John A. Magliacane, KD2BD |
||
562 | * @param Predict_Sat $sat The satellite data. |
||
563 | * @param Predict_QTH $qth The QTH observer location data. |
||
564 | * @param float $start The time where calculation should start. (Julian Date) |
||
565 | * @param int $maxdt The upper time limit in days (0.0 = no limit) |
||
566 | * @return The time (julian date) of the next LOS or 0.0 if the satellite has no LOS. |
||
567 | * |
||
568 | * This function finds the time of LOS for the first coming pass taking place |
||
569 | * no earlier that start. |
||
570 | * If the satellite is currently out of range, the function first calls |
||
571 | * find_aos to get the next AOS time. Then the calculations are done using |
||
572 | * the new start time. |
||
573 | * The function has a built-in watchdog to ensure that we don't end up in |
||
574 | * lengthy loops. |
||
575 | * |
||
576 | */ |
||
577 | public function find_los(Predict_Sat $sat, Predict_QTH $qth, $start, $maxdt) |
||
646 | |||
647 | /** Find AOS time of current pass. |
||
648 | * @param Predict_Sat $sat The satellite to find AOS for. |
||
649 | * @param Predict_QTH $qth The ground station. |
||
650 | * @param float $start Start time, prefereably now. |
||
651 | * @return The time of the previous AOS or 0.0 if the satellite has no AOS. |
||
652 | * |
||
653 | * This function can be used to find the AOS time in the past of the |
||
654 | * current pass. |
||
655 | */ |
||
656 | public function find_prev_aos(Predict_Sat $sat, Predict_QTH $qth, $start) |
||
680 | |||
681 | /** Determine whether satellite ever reaches AOS. |
||
682 | * @author John A. Magliacane, KD2BD |
||
683 | * @author Alexandru Csete, OZ9AEC |
||
684 | * @param Predict_Sat $sat The satellite data. |
||
685 | * @param Predict_QTH $qth The observer's location data |
||
686 | * @return bool true if the satellite will reach AOS, false otherwise. |
||
687 | * |
||
688 | */ |
||
689 | public function has_aos(Predict_Sat $sat, Predict_QTH $qth) |
||
716 | |||
717 | /** Predict passes after a certain time. |
||
718 | * |
||
719 | * |
||
720 | * This function calculates num upcoming passes with AOS no earlier |
||
721 | * than t = start and not later that t = (start+maxdt). The function will |
||
722 | * repeatedly call get_pass until |
||
723 | * the number of predicted passes is equal to num, the time has reached |
||
724 | * limit or the get_pass function returns NULL. |
||
725 | * |
||
726 | * note For no time limit use maxdt = 0.0 |
||
727 | * |
||
728 | * note the data in sat will be corrupt (future) and must be refreshed |
||
729 | * by the caller, if the caller will need it later on (eg. if the caller |
||
730 | * is GtkSatList). |
||
731 | * |
||
732 | * note Prepending to a singly linked list is much faster than appending. |
||
733 | * Therefore, the elements are prepended whereafter the GSList is |
||
734 | * reversed |
||
735 | * |
||
736 | * |
||
737 | * @param Predict_Sat $sat The satellite data |
||
738 | * @param Predict_QTH $qth The observer's location data |
||
739 | * @param float $start The start julian date |
||
740 | * @param int $maxdt The max # of days to look |
||
741 | * @param int $num The max # of passes to get |
||
742 | * @return array of Predict_Pass instances if found, empty array otherwise |
||
743 | */ |
||
744 | public function get_passes(Predict_Sat $sat, Predict_QTH $qth, $start, $maxdt, $num = 0) |
||
777 | |||
778 | /** |
||
779 | * Filters out visible passes and adds the visible aos, tca, los, and |
||
780 | * corresponding az and ele for each. |
||
781 | * |
||
782 | * @param array $passes The passes returned from get_passes() |
||
783 | * |
||
784 | * @author Bill Shupp |
||
785 | * @return array |
||
786 | */ |
||
787 | public function filterVisiblePasses(array $passes) |
||
855 | |||
856 | /** |
||
857 | * Translates aziumuth degrees to compass direction: |
||
858 | * |
||
859 | * N (0°), NNE (22.5°), NE (45°), ENE (67.5°), E (90°), ESE (112.5°), |
||
860 | * SE (135°), SSE (157.5°), S (180°), SSW (202.5°), SW (225°), |
||
861 | * WSW (247.5°), W (270°), WNW (292.5°), NW (315°), NNW (337.5°) |
||
862 | * |
||
863 | * @param int $az The azimuth in degrees, defaults to 0 |
||
864 | * |
||
865 | * @return string |
||
866 | */ |
||
867 | public function azDegreesToDirection($az = 0) |
||
875 | } |
||
876 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.