| Total Complexity | 70 |
| Total Lines | 512 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
Complex classes like DeviceXML 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 DeviceXML, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 46 | abstract class DeviceXML extends \core\DeviceConfig { |
||
| 47 | |||
| 48 | /** |
||
| 49 | * construct the device |
||
| 50 | */ |
||
| 51 | public function __construct() { |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * $langScope can be 'global' when all lang and all lang-specific information |
||
| 57 | * is dumped or 'single' when only the selected lang (and defaults) are passed |
||
| 58 | * NOTICE: 'global' is not yet supported |
||
| 59 | * |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | public $langScope; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * whether all EAP types should be included in the file or only the |
||
| 66 | * preferred one |
||
| 67 | * |
||
| 68 | * @var boolean |
||
| 69 | */ |
||
| 70 | public $allEaps = FALSE; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * vendor-specific additional information |
||
| 74 | * |
||
| 75 | * @var array |
||
| 76 | */ |
||
| 77 | public $VendorSpecific; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * create HTML code explaining the installer |
||
| 81 | * |
||
| 82 | * @return string |
||
| 83 | */ |
||
| 84 | public function writeDeviceInfo() { |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * create the actual XML file |
||
| 94 | * |
||
| 95 | * @return string filename of the generated installer |
||
| 96 | * @throws Exception |
||
| 97 | * |
||
| 98 | */ |
||
| 99 | public function writeInstaller() { |
||
| 155 | } |
||
| 156 | |||
| 157 | private const ATTRIBUTENAMES = [ |
||
| 158 | 'support:email' => 'EmailAddress', |
||
| 159 | 'support:url' => 'WebAddress', |
||
| 160 | 'support:phone' => 'Phone', |
||
| 161 | 'profile:description' => 'Description', |
||
| 162 | 'support:info_file' => 'TermsOfUse', |
||
| 163 | 'general:logo_file' => 'ProviderLogo', |
||
| 164 | ]; |
||
| 165 | |||
| 166 | /** |
||
| 167 | * determines the inner authentication. Is it EAP, and which mechanism is used to convey actual auth data |
||
| 168 | * @param array $eap the EAP type for which we want to get the inner auth |
||
| 169 | * @return array |
||
| 170 | */ |
||
| 171 | private function innerAuth($eap) |
||
| 172 | { |
||
| 173 | $out = []; |
||
| 174 | $out['METHOD'] = $eap["INNER"]; |
||
| 175 | $out['EAP'] = 0; |
||
| 176 | // override if there is an inner EAP |
||
| 177 | if ($eap["INNER"] > 0) { // there is an inner EAP method |
||
| 178 | $out['EAP'] = 1; |
||
| 179 | } |
||
| 180 | return $out; |
||
| 181 | } |
||
| 182 | |||
| 183 | /** |
||
| 184 | * |
||
| 185 | * @param string $attrName the attribute name |
||
| 186 | * @return array of values for this attribute |
||
| 187 | */ |
||
| 188 | private function getSimpleMLAttribute($attrName) { |
||
| 189 | if (empty($this->attributes[$attrName][0])) { |
||
| 190 | return([]); |
||
| 191 | } |
||
| 192 | $attributeList = $this->attributes[$attrName]; |
||
| 193 | if (!isset(self::ATTRIBUTENAMES[$attrName])) { |
||
| 194 | $this->loggerInstance->debug(4, "Missing class definition for $attrName\n"); |
||
| 195 | return([]); |
||
| 196 | } |
||
| 197 | $className = "\devices\xml\\" . self::ATTRIBUTENAMES[$attrName]; |
||
| 198 | $objs = []; |
||
| 199 | if ($this->langScope === 'global') { |
||
| 200 | foreach ($attributeList['langs'] as $language => $value) { |
||
| 201 | $language = ($language === 'C' ? 'any' : $language); |
||
| 202 | $obj = new $className(); |
||
| 203 | $obj->setValue($value); |
||
| 204 | $obj->setAttributes(['lang' => $language]); |
||
| 205 | $objs[] = $obj; |
||
| 206 | } |
||
| 207 | } else { |
||
| 208 | $obj = new $className(); |
||
| 209 | $obj->setValue($attributeList[0]); |
||
| 210 | $objs[] = $obj; |
||
| 211 | } |
||
| 212 | return($objs); |
||
| 213 | } |
||
| 214 | |||
| 215 | /** |
||
| 216 | * constructs the name of the institution and puts it into the XML. |
||
| 217 | * consists of the best-language-match inst name, and if the inst has more |
||
| 218 | * than one profile also the best-language-match profile name |
||
| 219 | * |
||
| 220 | * @return \devices\xml\DisplayName[] |
||
| 221 | */ |
||
| 222 | private function getDisplayName() { |
||
| 223 | $attr = $this->attributes; |
||
| 224 | $objs = []; |
||
| 225 | if ($this->langScope === 'global') { |
||
| 226 | $instNameLangs = $attr['general:instname']['langs']; |
||
| 227 | if ($attr['internal:profile_count'][0] > 1) { |
||
| 228 | $profileNameLangs = $attr['profile:name']['langs']; |
||
| 229 | } |
||
| 230 | foreach ($instNameLangs as $language => $value) { |
||
| 231 | $language = ($language === 'C' ? 'any' : $language); |
||
| 232 | $displayname = new DisplayName(); |
||
| 233 | if (isset($profileNameLangs)) { |
||
| 234 | $langOrC = isset($profileNameLangs[$language]) ? $profileNameLangs[$language] : $profileNameLangs['C']; |
||
| 235 | $value .= ' - ' . $langOrC; |
||
| 236 | } |
||
| 237 | $displayname->setValue($value); |
||
| 238 | $displayname->setAttributes(['lang' => $language]); |
||
| 239 | $objs[] = $displayname; |
||
| 240 | } |
||
| 241 | } else { |
||
| 242 | $displayname = new DisplayName(); |
||
| 243 | $value = $attr['general:instname'][0]; |
||
| 244 | if ($attr['internal:profile_count'][0] > 1) { |
||
| 245 | $value .= ' - ' . $attr['profile:name'][0]; |
||
| 246 | } |
||
| 247 | $displayname->setValue($value); |
||
| 248 | $objs[] = $displayname; |
||
| 249 | } |
||
| 250 | return $objs; |
||
| 251 | } |
||
| 252 | |||
| 253 | /** |
||
| 254 | * retrieves the provider logo and puts it into the XML structure |
||
| 255 | * |
||
| 256 | * @return \devices\xml\ProviderLogo |
||
| 257 | */ |
||
| 258 | private function getProviderLogo() { |
||
| 267 | } |
||
| 268 | } |
||
| 269 | |||
| 270 | /** |
||
| 271 | * retrieves provider information and puts it into the XML structure. |
||
| 272 | * contains the profile description and the ToU file, if any |
||
| 273 | * |
||
| 274 | * @return \devices\xml\ProviderInfo |
||
| 275 | */ |
||
| 276 | private function getProviderInfo() { |
||
| 277 | $providerinfo = new ProviderInfo(); |
||
| 278 | $providerinfo->setProperty('DisplayName', $this->getDisplayName()); |
||
| 279 | $providerinfo->setProperty('Description', $this->getSimpleMLAttribute('profile:description')); |
||
| 280 | $providerinfo->setProperty('ProviderLocation', $this->getProviderLocation()); |
||
| 281 | $providerinfo->setProperty('ProviderLogo', $this->getProviderLogo()); |
||
| 282 | $providerinfo->setProperty('TermsOfUse', $this->getSimpleMLAttribute('support:info_file')); |
||
| 283 | $providerinfo->setProperty('Helpdesk', $this->getHelpdesk()); |
||
| 284 | return $providerinfo; |
||
| 285 | } |
||
| 286 | |||
| 287 | /** |
||
| 288 | * retrieves the location information and puts it into the XML structure |
||
| 289 | * |
||
| 290 | * @return \devices\xml\ProviderLocation|\devices\xml\ProviderLocation[] |
||
| 291 | */ |
||
| 292 | private function getProviderLocation() { |
||
| 313 | } |
||
| 314 | } |
||
| 315 | |||
| 316 | /** |
||
| 317 | * retrieves helpdesk contact information and puts it into the XML structure |
||
| 318 | * |
||
| 319 | * @return \devices\xml\Helpdesk |
||
| 320 | */ |
||
| 321 | private function getHelpdesk() { |
||
| 327 | } |
||
| 328 | |||
| 329 | /** |
||
| 330 | * determine where this credential should be applicable |
||
| 331 | * |
||
| 332 | * @return \devices\xml\CredentialApplicability |
||
| 333 | */ |
||
| 334 | private function getCredentialApplicability() { |
||
| 335 | $ssids = $this->attributes['internal:SSID']; |
||
| 336 | $oids = $this->attributes['internal:consortia']; |
||
| 337 | $credentialapplicability = new CredentialApplicability(); |
||
| 338 | $ieee80211s = []; |
||
| 339 | foreach ($ssids as $ssid => $ciph) { |
||
| 340 | $ieee80211 = new IEEE80211(); |
||
| 341 | $ieee80211->setProperty('SSID', $ssid); |
||
| 342 | $ieee80211->setProperty('MinRSNProto', $ciph == 'AES' ? 'CCMP' : 'TKIP'); |
||
| 343 | $ieee80211s[] = $ieee80211; |
||
| 344 | } |
||
| 345 | foreach ($oids as $oid) { |
||
| 346 | $ieee80211 = new IEEE80211(); |
||
| 347 | $ieee80211->setProperty('ConsortiumOID', $oid); |
||
| 348 | $ieee80211s[] = $ieee80211; |
||
| 349 | } |
||
| 350 | $credentialapplicability->setProperty('IEEE80211', $ieee80211s); |
||
| 351 | return $credentialapplicability; |
||
| 352 | } |
||
| 353 | |||
| 354 | /** |
||
| 355 | * retrieves the parameters needed for the given EAP method and creates |
||
| 356 | * appropriate nodes in the XML structure for them |
||
| 357 | * |
||
| 358 | * @param array $eap the EAP type in question |
||
| 359 | * @return array a recap of the findings |
||
| 360 | */ |
||
| 361 | private function getAuthenticationMethodParams($eap) { |
||
| 362 | $inner = $this->innerAuth($eap); |
||
| 363 | $outerMethod = $eap["OUTER"]; |
||
| 364 | |||
| 365 | if (isset($inner["METHOD"]) && $inner["METHOD"]) { |
||
| 366 | $innerauthmethod = new InnerAuthenticationMethod(); |
||
| 367 | $typeOfInner = "\devices\xml\\" . ($inner["EAP"] ? 'EAPMethod' : 'NonEAPAuthMethod'); |
||
| 368 | $eapmethod = new $typeOfInner(); |
||
| 369 | $eaptype = new Type(); |
||
| 370 | $eaptype->setValue(abs($inner['METHOD'])); |
||
| 371 | $eapmethod->setProperty('Type', $eaptype); |
||
| 372 | $innerauthmethod->setProperty($typeOfInner, $eapmethod); |
||
| 373 | return ['inner_method' => $innerauthmethod, 'methodID' => $outerMethod, 'inner_methodID' => $inner['METHOD']]; |
||
| 374 | } else { |
||
| 375 | return ['inner_method' => 0, 'methodID' => $outerMethod, 'inner_methodID' => 0]; |
||
| 376 | } |
||
| 377 | } |
||
| 378 | |||
| 379 | /** |
||
| 380 | * sets the server-side credentials for a given EAP type |
||
| 381 | * |
||
| 382 | * @param \devices\XML\Type $eaptype the EAP type |
||
| 383 | * @return \devices\XML\ServerSideCredential |
||
| 384 | */ |
||
| 385 | private function setServerSideCredentials($eaptype) { |
||
| 408 | } |
||
| 409 | |||
| 410 | /** |
||
| 411 | * sets the realm information for the client-side credential |
||
| 412 | * |
||
| 413 | * @param \devices\XML\ClientSideCredential $clientsidecredential the ClientSideCredential to which the realm info is to be added |
||
| 414 | * @return void |
||
| 415 | */ |
||
| 416 | private function setClientSideRealm($clientsidecredential) { |
||
| 428 | } |
||
| 429 | } |
||
| 430 | |||
| 431 | /** |
||
| 432 | * sets the client certificate |
||
| 433 | * |
||
| 434 | * @return \devices\XML\ClientCertificate |
||
| 435 | */ |
||
| 436 | private function setClientCertificate() { |
||
| 441 | } |
||
| 442 | |||
| 443 | /** |
||
| 444 | * sets the client-side credentials for the given EAP type |
||
| 445 | * |
||
| 446 | * @param array $eapParams the EAP parameters |
||
| 447 | * @return \devices\XML\ClientSideCredential |
||
| 448 | */ |
||
| 449 | private function setClientSideCredentials($eapParams) { |
||
| 463 | } |
||
| 464 | |||
| 465 | /** |
||
| 466 | * sets the EAP method |
||
| 467 | * |
||
| 468 | * @param \devices\XML\Type $eaptype the EAP type XMLObject |
||
| 469 | * @return \devices\XML\EAPMethod |
||
| 470 | */ |
||
| 471 | private function setEapMethod($eaptype) { |
||
| 472 | $eapmethod = new EAPMethod(); |
||
| 473 | $eapmethod->setProperty('Type', $eaptype); |
||
| 474 | if (isset($this->VendorSpecific)) { |
||
| 475 | $vendorspecifics = []; |
||
| 476 | foreach ($this->VendorSpecific as $vs) { |
||
| 477 | $vendorspecific = new VendorSpecific(); |
||
| 478 | $vs['value']->addAttribute('xsi:noNamespaceSchemaLocation', "xxx.xsd"); |
||
| 479 | $vendorspecific->setValue($vs['value']); |
||
| 480 | $vendorspecific->setAttributes(['vendor' => $vs['vendor']]); |
||
| 481 | $vendorspecifics[] = $vendorspecific; |
||
| 482 | } |
||
| 483 | $eapmethod->setProperty('VendorSpecific', $vendorspecifics); |
||
| 484 | } |
||
| 485 | return($eapmethod); |
||
| 486 | } |
||
| 487 | |||
| 488 | /** |
||
| 489 | * determines the authentication method to use |
||
| 490 | * |
||
| 491 | * @param array $eap the EAP methods, in array representation |
||
| 492 | * @return \devices\xml\AuthenticationMethod |
||
| 493 | */ |
||
| 494 | private function getAuthMethod($eap) { |
||
| 513 | } |
||
| 514 | |||
| 515 | /** |
||
| 516 | * |
||
| 517 | * @param \SimpleXMLElement $node the XML node to marshal |
||
| 518 | * @param EAPIdentityProvider $object the Object |
||
| 519 | * @return void |
||
| 520 | */ |
||
| 521 | private function marshalObject($node, $object) { |
||
| 558 | } |
||
| 559 | } |
||
| 563 |