| Total Complexity | 47 |
| Total Lines | 322 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Device_XML 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_XML, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 32 | abstract class Device_XML extends \core\DeviceConfig { |
||
| 33 | |||
| 34 | public function __construct() { |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * $lang_scope can be 'global' wheb all lang and all lang-specific information |
||
| 40 | * is dumped or 'single' when only the selected lang (and defaults) are passed |
||
| 41 | * NOTICE: 'global' is not yet supported |
||
| 42 | */ |
||
| 43 | public $langScope; |
||
| 44 | public $allEaps = FALSE; |
||
| 45 | public $VendorSpecific; |
||
| 46 | |||
| 47 | public function writeDeviceInfo() { |
||
| 51 | } |
||
| 52 | |||
| 53 | public function writeInstaller() { |
||
| 109 | } |
||
| 110 | |||
| 111 | private $AttributeNames = [ |
||
| 112 | 'support:email' => 'EmailAddress', |
||
| 113 | 'support:url' => 'WebAddress', |
||
| 114 | 'support:phone' => 'Phone', |
||
| 115 | 'profile:description' => 'Description', |
||
| 116 | 'support:info_file' => 'TermsOfUse', |
||
| 117 | 'general:logo_file' => 'ProviderLogo', |
||
| 118 | ]; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * |
||
| 122 | * @param string $attrName |
||
| 123 | * @return array of values for this attribute |
||
| 124 | */ |
||
| 125 | private function getSimpleMLAttribute($attrName) { |
||
| 150 | } |
||
| 151 | |||
| 152 | private function getDisplayName() { |
||
| 153 | $attr = $this->attributes; |
||
| 154 | $objs = []; |
||
| 155 | if ($this->langScope === 'global') { |
||
| 156 | $instNameLangs = $attr['general:instname']['langs']; |
||
| 157 | if ($attr['internal:profile_count'][0] > 1) { |
||
| 158 | $profileNameLangs = $attr['profile:name']['langs']; |
||
| 159 | } |
||
| 160 | foreach ($instNameLangs as $language => $value) { |
||
| 161 | $language = ($language === 'C' ? 'any' : $language); |
||
| 162 | $displayname = new DisplayName(); |
||
| 163 | if (isset($profileNameLangs)) { |
||
| 164 | $langOrC = isset($profileNameLangs[$language]) ? $profileNameLangs[$language] : $profileNameLangs['C']; |
||
| 165 | $value .= ' - ' . $langOrC; |
||
| 166 | } |
||
| 167 | $displayname->setValue($value); |
||
| 168 | $displayname->setAttributes(['lang' => $language]); |
||
| 169 | $objs[] = $displayname; |
||
| 170 | } |
||
| 171 | } else { |
||
| 172 | $displayname = new DisplayName(); |
||
| 173 | $value = $attr['general:instname'][0]; |
||
| 174 | if ($attr['internal:profile_count'][0] > 1) { |
||
| 175 | $value .= ' - ' . $attr['profile:name'][0]; |
||
| 176 | } |
||
| 177 | $displayname->setValue($value); |
||
| 178 | $objs[] = $displayname; |
||
| 179 | } |
||
| 180 | return $objs; |
||
| 181 | } |
||
| 182 | |||
| 183 | private function getProviderLogo() { |
||
| 184 | $attr = $this->attributes; |
||
| 185 | if (isset($attr['general:logo_file'][0])) { |
||
| 186 | $logoString = base64_encode($attr['general:logo_file'][0]); |
||
| 187 | $logoMime = 'image/' . $attr['internal:logo_file'][0]['mime']; |
||
| 188 | $providerlogo = new ProviderLogo(); |
||
| 189 | $providerlogo->setAttributes(['mime' => $logoMime, 'encoding' => 'base64']); |
||
| 190 | $providerlogo->setValue($logoString); |
||
| 191 | return $providerlogo; |
||
| 192 | } |
||
| 193 | } |
||
| 194 | |||
| 195 | private function getProviderInfo() { |
||
| 196 | $providerinfo = new ProviderInfo(); |
||
| 197 | $providerinfo->setProperty('DisplayName', $this->getDisplayName()); |
||
| 198 | $providerinfo->setProperty('Description', $this->getSimpleMLAttribute('profile:description')); |
||
| 199 | $providerinfo->setProperty('ProviderLocation', $this->getProvideLocation()); |
||
| 200 | $providerinfo->setProperty('ProviderLogo', $this->getProviderLogo()); |
||
| 201 | $providerinfo->setProperty('TermsOfUse', $this->getSimpleMLAttribute('support:info_file')); |
||
| 202 | $providerinfo->setProperty('Helpdesk', $this->getHelpdesk()); |
||
| 203 | return $providerinfo; |
||
| 204 | } |
||
| 205 | |||
| 206 | private function getProvideLocation() { |
||
| 207 | $attr = $this->attributes; |
||
| 208 | if (isset($attr['general:geo_coordinates'])) { |
||
| 209 | $attrCoordinates = $attr['general:geo_coordinates']; |
||
| 210 | if (count($attrCoordinates) > 1) { |
||
| 211 | $location = []; |
||
| 212 | foreach ($attrCoordinates as $a) { |
||
| 213 | $providerlocation = new ProviderLocation(); |
||
| 214 | $b = json_decode($a, true); |
||
| 215 | $providerlocation->setProperty('Longitude', $b['lon']); |
||
| 216 | $providerlocation->setProperty('Latitude', $b['lat']); |
||
| 217 | $location[] = $providerlocation; |
||
| 218 | } |
||
| 219 | } else { |
||
| 220 | $providerlocation = new ProviderLocation(); |
||
| 221 | $b = json_decode($attrCoordinates[0], true); |
||
| 222 | $providerlocation->setProperty('Longitude', $b['lon']); |
||
| 223 | $providerlocation->setProperty('Latitude', $b['lat']); |
||
| 224 | $location = $providerlocation; |
||
| 225 | } |
||
| 226 | return $location; |
||
| 227 | } |
||
| 228 | } |
||
| 229 | |||
| 230 | private function getHelpdesk() { |
||
| 231 | $helpdesk = new Helpdesk(); |
||
| 232 | $helpdesk->setProperty('EmailAddress', $this->getSimpleMLAttribute('support:email')); |
||
| 233 | $helpdesk->setProperty('WebAddress', $this->getSimpleMLAttribute('support:url')); |
||
| 234 | $helpdesk->setProperty('Phone', $this->getSimpleMLAttribute('support:phone')); |
||
| 235 | return $helpdesk; |
||
| 236 | } |
||
| 237 | |||
| 238 | /* This function is not currently used. |
||
| 239 | * |
||
| 240 | * private function getCompatibleUses() { |
||
| 241 | $ssids = $this->attributes['internal:SSID']; |
||
| 242 | $compatibleuses = new CompatibleUses(); |
||
| 243 | $ieee80211s = []; |
||
| 244 | foreach ($ssids as $ssid => $ciph) { |
||
| 245 | $ieee80211 = new IEEE80211(); |
||
| 246 | $ieee80211->setProperty('SSID', $ssid); |
||
| 247 | $ieee80211->setProperty('MinRSNProto', $ciph == 'AES' ? 'CCMP' : 'TKIP'); |
||
| 248 | $ieee80211s[] = $ieee80211; |
||
| 249 | } |
||
| 250 | $compatibleuses->setProperty('IEEE80211', $ieee80211s); |
||
| 251 | return($compatibleuses); |
||
| 252 | } |
||
| 253 | |||
| 254 | */ |
||
| 255 | private function getAuthenticationMethodParams($eap) { |
||
| 256 | $inner = \core\common\EAP::innerAuth($eap); |
||
| 257 | $outerMethod = $eap["OUTER"]; |
||
| 258 | |||
| 259 | if (isset($inner["METHOD"]) && $inner["METHOD"]) { |
||
| 260 | $innerauthmethod = new InnerAuthenticationMethod(); |
||
| 261 | $typeOfInner = "\devices\xml\\" . ($inner["EAP"] ? 'EAPMethod' : 'NonEAPAuthMethod'); |
||
| 262 | $eapmethod = new $typeOfInner(); |
||
| 263 | $eaptype = new Type(); |
||
| 264 | $eaptype->setValue($inner['METHOD']); |
||
| 265 | $eapmethod->setProperty('Type', $eaptype); |
||
| 266 | $innerauthmethod->setProperty($typeOfInner, $eapmethod); |
||
| 267 | return ['inner_method' => $innerauthmethod, 'methodID' => $outerMethod, 'inner_methodID' => $inner['METHOD']]; |
||
| 268 | } else { |
||
| 269 | return ['inner_method' => 0, 'methodID' => $outerMethod, 'inner_methodID' => 0]; |
||
| 270 | } |
||
| 271 | } |
||
| 272 | |||
| 273 | private function setServerSideCredentials($eaptype) { |
||
| 274 | $attr = $this->attributes; |
||
| 275 | $serversidecredential = new ServerSideCredential(); |
||
| 276 | // Certificates and server names |
||
| 277 | $cAlist = []; |
||
| 278 | $attrCaList = $attr['internal:CAs'][0]; |
||
| 279 | foreach ($attrCaList as $ca) { |
||
| 280 | $caObject = new CA(); |
||
| 281 | $caObject->setValue(base64_encode($ca['der'])); |
||
| 282 | $caObject->setAttributes(['format' => 'X.509', 'encoding' => 'base64']); |
||
| 283 | $cAlist[] = $caObject; |
||
| 284 | } |
||
| 285 | $serverids = []; |
||
| 286 | $servers = $attr['eap:server_name']; |
||
| 287 | foreach ($servers as $server) { |
||
| 288 | $serverid = new ServerID(); |
||
| 289 | $serverid->setValue($server); |
||
| 290 | $serverids[] = $serverid; |
||
| 291 | } |
||
| 292 | $serversidecredential->setProperty('EAPType', $eaptype->getValue()); |
||
| 293 | $serversidecredential->setProperty('CA', $cAlist); |
||
| 294 | $serversidecredential->setProperty('ServerID', $serverids); |
||
| 295 | return($serversidecredential); |
||
| 296 | } |
||
| 297 | |||
| 298 | private function setClientSideCredentials($eapParams) { |
||
| 315 | } |
||
| 316 | |||
| 317 | private function setEapMethod($eaptype) { |
||
| 333 | } |
||
| 334 | |||
| 335 | private function getAuthMethod($eap) { |
||
| 336 | // $attr = $this->attributes; |
||
| 337 | $authmethod = new AuthenticationMethod(); |
||
| 338 | $eapParams = $this->getAuthenticationMethodParams($eap); |
||
| 354 | |||
| 355 | |||
| 361 |