| Total Complexity | 48 |
| Total Lines | 232 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Device_Linux 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.
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 Device_Linux, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class Device_Linux extends \core\DeviceConfig { |
||
| 28 | |||
| 29 | final public function __construct() { |
||
| 30 | parent::__construct(); |
||
| 31 | $this->setSupportedEapMethods([\core\common\EAP::EAPTYPE_PEAP_MSCHAP2, \core\common\EAP::EAPTYPE_TTLS_PAP, \core\common\EAP::EAPTYPE_TTLS_MSCHAP2, \core\common\EAP::EAPTYPE_TLS, \core\common\EAP::EAPTYPE_SILVERBULLET]); |
||
| 32 | } |
||
| 33 | |||
| 34 | public function writeInstaller() { |
||
| 46 | } |
||
| 47 | |||
| 48 | public function writeDeviceInfo() { |
||
| 83 | } |
||
| 84 | |||
| 85 | private function writeMessages() { |
||
| 114 | } |
||
| 115 | |||
| 116 | private function writeConfigVars() { |
||
| 117 | $eapMethod = \core\common\EAP::eapDisplayName($this->selectedEap); |
||
| 118 | $out = ''; |
||
| 119 | $out .= 'Config.instname = "' . $this->attributes['general:instname'][0] . '"' . "\n"; |
||
| 120 | $out .= 'Config.profilename = "' . $this->attributes['profile:name'][0] . '"' . "\n"; |
||
| 121 | $contacts = $this->mkSupportContacts(); |
||
| 122 | $out .= 'Config.url = "' . $contacts['url'] . '"' . "\n"; |
||
| 123 | $out .= 'Config.email = "' . $contacts['email'] . '"' . "\n"; |
||
| 124 | $out .= 'Config.title = "' . "eduroam CAT" . "\"\n"; |
||
| 125 | $out .= 'Config.servers = ' . $this->mkSubjectAltNameList() . "\n"; |
||
| 126 | $out .= 'Config.ssids = ' . $this->mkSsidList() . "\n"; |
||
| 127 | $out .= 'Config.del_ssids = ' . $this->mkDelSsidList() . "\n"; |
||
| 128 | $out .= "Config.server_match = '" . $this->glueServerNames() . "'\n"; |
||
| 129 | $out .= "Config.eap_outer = '" . $eapMethod['OUTER'] . "'\n"; |
||
| 130 | $out .= "Config.eap_inner = '" . $eapMethod['INNER'] . "'\n"; |
||
| 131 | if ($this->selectedEap == \core\common\EAP::EAPTYPE_TLS && isset($this->attributes['eap-specific:tls_use_other_id']) && $this->attributes['eap-specific:tls_use_other_id'][0] == 'on') { |
||
| 132 | $out .= "Config.use_other_tls_id = True\n"; |
||
| 133 | } |
||
| 134 | else { |
||
| 135 | $out .= "Config.use_other_tls_id = False\n"; |
||
| 136 | } |
||
| 137 | $tou = $this->mkUserConsent(); |
||
| 138 | $out .= 'Config.tou = ' . ( $tou ? '"""' . $tou . '"""' : 'None' ) . "\n"; |
||
| 139 | $out .= 'Config.CA = """' . $this->mkCAfile() . '"""' . "\n"; |
||
| 140 | $outerId = $this->determineOuterIdString(); |
||
| 141 | if ($outerId !== NULL) { |
||
| 142 | $out .= "Config.anonymous_identity = '$outerId'\n"; |
||
| 143 | } |
||
| 144 | $out .= 'Config.init_info = """' . $this->mkIntro() . '"""' . "\n"; |
||
| 145 | $out .= 'Config.init_confirmation = "' . $this->mkProfileConfirmation() . "\"\n"; |
||
| 146 | |||
| 147 | $out .= 'Config.sb_user_file = """' . $this->mkSbUserFile() . '"""' . "\n"; |
||
| 148 | if (!empty($this->attributes['internal:realm'][0])) { |
||
| 149 | $out .= 'Config.user_realm = "' . $this->attributes['internal:realm'][0] . "\"\n"; |
||
| 150 | } |
||
| 151 | if(!empty($this->attributes['internal:hint_userinput_suffix'][0]) && $this->attributes['internal:hint_userinput_suffix'][0] == 1) { |
||
| 152 | $out .= "Config.hint_user_input = True\n"; |
||
| 153 | } |
||
| 154 | if(!empty($this->attributes['internal:verify_userinput_suffix'][0]) && $this->attributes['internal:verify_userinput_suffix'][0] == 1) { |
||
| 155 | $out .= "Config.verify_user_realm_input = True\n"; |
||
| 156 | } |
||
| 157 | return $out; |
||
| 158 | } |
||
| 159 | |||
| 160 | |||
| 161 | private function glueServerNames() { |
||
| 162 | $serverList = $this->attributes['eap:server_name']; |
||
| 163 | if (!$serverList) { |
||
| 164 | return ''; |
||
| 165 | } |
||
| 166 | $A0 = array_reverse(explode('.', array_shift($serverList))); |
||
| 167 | $B = $A0; |
||
| 168 | foreach ($serverList as $oneServer) { |
||
| 169 | $A = array_reverse(explode('.', $oneServer)); |
||
| 170 | $B = array_intersect_assoc($A0, $A); |
||
| 171 | $A0 = $B; |
||
| 172 | } |
||
| 173 | return(implode('.', array_reverse($B))); |
||
| 174 | } |
||
| 175 | |||
| 176 | private function mkSupportContacts() { |
||
| 177 | $url = (!empty($this->attributes['support:url'][0])) ? $this->attributes['support:url'][0] : $this->support_url_substitute; |
||
| 178 | $email = (!empty($this->attributes['support:email'][0])) ? $this->attributes['support:email'][0] : $this->support_email_substitute; |
||
| 179 | return(['url'=>$url, 'email'=>$email]); |
||
| 180 | } |
||
| 181 | |||
| 182 | private function mkSubjectAltNameList() { |
||
| 183 | $serverList = $this->attributes['eap:server_name']; |
||
| 184 | if (!$serverList) { |
||
| 185 | return ''; |
||
| 186 | } |
||
| 187 | $out = ''; |
||
| 188 | foreach ($serverList as $oneServer) { |
||
| 189 | if ($out) { |
||
| 190 | $out .= ','; |
||
| 191 | } |
||
| 192 | $out .= "'DNS:$oneServer'"; |
||
| 193 | } |
||
| 194 | return "[" . $out. "]"; |
||
| 195 | } |
||
| 196 | |||
| 197 | |||
| 198 | private function mkSsidList() { |
||
| 199 | $ssids = $this->attributes['internal:SSID']; |
||
| 200 | $outArray = []; |
||
| 201 | foreach ($ssids as $ssid => $cipher) { |
||
| 202 | $outArray[] = "'$ssid'"; |
||
| 203 | } |
||
| 204 | return '[' . implode(', ', $outArray) . ']'; |
||
| 205 | } |
||
| 206 | |||
| 207 | private function mkDelSsidList() { |
||
| 208 | $outArray = []; |
||
| 209 | $delSSIDs = $this->attributes['internal:remove_SSID']; |
||
| 210 | foreach ($delSSIDs as $ssid => $cipher) { |
||
| 211 | if ($cipher == 'DEL') { |
||
| 212 | $outArray[] = "'$ssid'"; |
||
| 213 | } |
||
| 214 | } |
||
| 215 | return '[' . implode(', ', $outArray) . ']'; |
||
| 216 | } |
||
| 217 | |||
| 218 | private function mkCAfile(){ |
||
| 225 | } |
||
| 226 | |||
| 227 | private function mkIntro() { |
||
| 231 | } |
||
| 232 | |||
| 233 | private function mkUserConsent() { |
||
| 234 | $out = ''; |
||
| 235 | if (isset($this->attributes['support:info_file'])) { |
||
| 236 | if ($this->attributes['internal:info_file'][0]['mime'] == 'txt') { |
||
| 237 | $out = $this->attributes['support:info_file'][0]; |
||
| 238 | } |
||
| 239 | } |
||
| 240 | return $out; |
||
| 241 | } |
||
| 242 | |||
| 243 | private function mkProfileConfirmation() { |
||
| 250 | } |
||
| 251 | |||
| 252 | |||
| 253 | |||
| 254 | private function mkSbUserFile() { |
||
| 259 | } |
||
| 260 | |||
| 261 | } |
||
| 262 |