@@ -84,6 +84,24 @@ function getLuck(): Luck
8484 return Luck::fromIndex ($ this ->index < 60 ? 0 : 1 );
8585 }
8686
87+ /**
88+ * 宜忌
89+ * @param string[] $data 数据
90+ * @param int $supIndex 主下标
91+ * @param int $subIndex 次下标
92+ * @param int $index 宜忌下标
93+ * @return Taboo[] 宜忌列表
94+ */
95+ private static function getTaboos (array $ data , int $ supIndex , int $ subIndex , int $ index ): array
96+ {
97+ $ l = array ();
98+ $ d = explode (', ' , explode ('; ' , $ data [$ supIndex ])[$ subIndex ])[$ index ];
99+ for ($ i = 0 , $ j = strlen ($ d ); $ i < $ j ; $ i += 2 ) {
100+ $ l [] = static ::fromIndex (hexdec (substr ($ d , $ i , 2 )));
101+ }
102+ return $ l ;
103+ }
104+
87105 /**
88106 * 日宜
89107 * @param SixtyCycle $month 月干支
@@ -92,12 +110,7 @@ function getLuck(): Luck
92110 */
93111 static function getDayRecommends (SixtyCycle $ month , SixtyCycle $ day ): array
94112 {
95- $ l = array ();
96- $ data = explode (', ' , explode ('; ' , static ::$ dayTaboo [$ month ->getEarthBranch ()->getIndex ()])[$ day ->getIndex ()])[0 ];
97- for ($ i = 0 , $ j = strlen ($ data ); $ i < $ j ; $ i += 2 ) {
98- $ l [] = static ::fromIndex (hexdec (substr ($ data , $ i , 2 )));
99- }
100- return $ l ;
113+ return self ::getTaboos (static ::$ dayTaboo , $ month ->getEarthBranch ()->getIndex (), $ day ->getIndex (), 0 );
101114 }
102115
103116 /**
@@ -108,12 +121,7 @@ static function getDayRecommends(SixtyCycle $month, SixtyCycle $day): array
108121 */
109122 static function getDayAvoids (SixtyCycle $ month , SixtyCycle $ day ): array
110123 {
111- $ l = array ();
112- $ data = explode (', ' , explode ('; ' , static ::$ dayTaboo [$ month ->getEarthBranch ()->getIndex ()])[$ day ->getIndex ()])[1 ];
113- for ($ i = 0 , $ j = strlen ($ data ); $ i < $ j ; $ i += 2 ) {
114- $ l [] = static ::fromIndex (hexdec (substr ($ data , $ i , 2 )));
115- }
116- return $ l ;
124+ return self ::getTaboos (static ::$ dayTaboo , $ month ->getEarthBranch ()->getIndex (), $ day ->getIndex (), 1 );
117125 }
118126
119127 /**
@@ -124,12 +132,7 @@ static function getDayAvoids(SixtyCycle $month, SixtyCycle $day): array
124132 */
125133 static function getHourRecommends (SixtyCycle $ day , SixtyCycle $ hour ): array
126134 {
127- $ l = array ();
128- $ data = explode (', ' , explode ('; ' , static ::$ hourTaboo [$ hour ->getEarthBranch ()->getIndex ()])[$ day ->getIndex ()])[0 ];
129- for ($ i = 0 , $ j = strlen ($ data ); $ i < $ j ; $ i += 2 ) {
130- $ l [] = static ::fromIndex (hexdec (substr ($ data , $ i , 2 )));
131- }
132- return $ l ;
135+ return self ::getTaboos (static ::$ hourTaboo , $ hour ->getEarthBranch ()->getIndex (), $ day ->getIndex (), 0 );
133136 }
134137
135138 /**
@@ -140,11 +143,6 @@ static function getHourRecommends(SixtyCycle $day, SixtyCycle $hour): array
140143 */
141144 static function getHourAvoids (SixtyCycle $ day , SixtyCycle $ hour ): array
142145 {
143- $ l = array ();
144- $ data = explode (', ' , explode ('; ' , static ::$ hourTaboo [$ hour ->getEarthBranch ()->getIndex ()])[$ day ->getIndex ()])[1 ];
145- for ($ i = 0 , $ j = strlen ($ data ); $ i < $ j ; $ i += 2 ) {
146- $ l [] = static ::fromIndex (hexdec (substr ($ data , $ i , 2 )));
147- }
148- return $ l ;
146+ return self ::getTaboos (static ::$ hourTaboo , $ hour ->getEarthBranch ()->getIndex (), $ day ->getIndex (), 1 );
149147 }
150148}
0 commit comments