| Conditions | 7 |
| Paths | 36 |
| Total Lines | 131 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 88 | public function writeInstaller() { |
||
| 89 | $this->loggerInstance->debug(4, "HS20 PerProviderSubscription Managed Object Installer start\n"); |
||
| 90 | $now = new \DateTime(); |
||
| 91 | $content = '<MgmtTree xmlns="syncml:dmddf1.2"> |
||
| 92 | <VerDTD>1.2</VerDTD> |
||
| 93 | <Node> |
||
| 94 | <NodeName>PerProviderSubscription</NodeName> |
||
| 95 | <RTProperties> |
||
| 96 | <Type> |
||
| 97 | <DDFName>urn:wfa:mo:hotspot2dot0-perprovidersubscription:1.0</DDFName> |
||
| 98 | </Type> |
||
| 99 | </RTProperties> |
||
| 100 | <Node> |
||
| 101 | <NodeName>CATPasspointSetting</NodeName> |
||
| 102 | <Node> |
||
| 103 | <NodeName>AAAServerTrustRoot</NodeName>'; |
||
| 104 | foreach ($this->attributes['internal:CAs'][0] as $oneCert) { |
||
| 105 | $content .= '<Node> |
||
| 106 | <NodeName>'.$oneCert['uuid'].'</NodeName> |
||
| 107 | <Node> |
||
| 108 | <NodeName>CertSHA256Fingerprint</NodeName> |
||
| 109 | <Value>'.$oneCert['sha256'].'</Value> |
||
| 110 | </Node> |
||
| 111 | </Node> |
||
| 112 | '; |
||
| 113 | } |
||
| 114 | $content .= '</Node> |
||
| 115 | <Node> |
||
| 116 | <NodeName>Credential</NodeName> |
||
| 117 | <Node> |
||
| 118 | <NodeName>CreationDate</NodeName> |
||
| 119 | <Value>'.$now->format("Y-m-d") . "T" . $now->format("H:i:s") . "Z".'</Value> |
||
| 120 | </Node> |
||
| 121 | <Node> |
||
| 122 | <NodeName>DigitalCertificate</NodeName> |
||
| 123 | <Node> |
||
| 124 | <NodeName>CertificateType</NodeName> |
||
| 125 | <Value>x509v3</Value> |
||
| 126 | </Node> |
||
| 127 | <Node> |
||
| 128 | <NodeName>CertSHA256Fingerprint</NodeName> |
||
| 129 | <Value>'.$this->clientCert["sha256"] /* the actual cert has to go... where? */.'</Value> |
||
| 130 | </Node> |
||
| 131 | </Node> |
||
| 132 | <Node> |
||
| 133 | <NodeName>Realm</NodeName> |
||
| 134 | <Value>'.$this->attributes['internal:realm'][0].'</Value> |
||
| 135 | </Node> |
||
| 136 | </Node> |
||
| 137 | <Node> |
||
| 138 | <NodeName>HomeSP</NodeName> |
||
| 139 | <Node> |
||
| 140 | <NodeName>FriendlyName</NodeName> |
||
| 141 | <Value>'.sprintf(_("%s via Passpoint"),CONFIG_CONFASSISTANT['CONSORTIUM']['display_name']).'</Value> |
||
| 142 | </Node> |
||
| 143 | <Node> |
||
| 144 | <NodeName>FQDN</NodeName> |
||
| 145 | <Value>'.$this->attributes['eap:server_name'][0] /* what, only one FQDN allowed? */.'</Value> |
||
| 146 | </Node> |
||
| 147 | <Node> |
||
| 148 | <NodeName>RoamingConsortiumOI</NodeName> |
||
| 149 | <Value>'; |
||
| 150 | $oiList = ""; |
||
| 151 | $numberOfOi = count(CONFIG_CONFASSISTANT['CONSORTIUM']['interworking-consortium-oi']); |
||
| 152 | foreach (CONFIG_CONFASSISTANT['CONSORTIUM']['interworking-consortium-oi'] as $index => $oneOi) { |
||
| 153 | // according to spec, must be lowercase ASCII without dashes |
||
| 154 | $oiList .= str_replace("-","",trim(strtolower($oneOi))); |
||
| 155 | if ($index < $numberOfOi - 1) { |
||
| 156 | // according to spec, comma-separated |
||
| 157 | $oiList .= ","; |
||
| 158 | } |
||
| 159 | } |
||
| 160 | $content .= $oiList.'</Value> |
||
| 161 | </Node> |
||
| 162 | </Node> |
||
| 163 | </Node> |
||
| 164 | </Node> |
||
| 165 | </MgmtTree> |
||
| 166 | '; |
||
| 167 | $content_encoded = base64_encode($content); |
||
| 168 | // sigh... we need to construct a MIME envelope for the payload and the cert data |
||
| 169 | $content_encoded = 'Content-Type: multipart/mixed; boundary={boundary} |
||
| 170 | Content-Transfer-Encoding: base64 |
||
| 171 | |||
| 172 | --{boundary} |
||
| 173 | Content-Type: application/x-passpoint-profile |
||
| 174 | Content-Transfer-Encoding: base64 |
||
| 175 | |||
| 176 | '.$content_encoded.' |
||
| 177 | --{boundary}'; |
||
| 178 | // then, another MIME body for each CA certificate we referenced earlier |
||
| 179 | // only leaves me to wonder what the "URL" for those is... |
||
| 180 | foreach ($this->attributes['internal:CAs'][0] as $oneCert) { |
||
| 181 | $content_encoded .= ' |
||
| 182 | Content-Type: application/x-x509-ca-cert |
||
| 183 | Content-Transfer-Encoding: base64 |
||
| 184 | |||
| 185 | '.base64_encode($oneCert['der']). |
||
| 186 | '--{boundary}'; |
||
| 187 | |||
| 188 | } |
||
| 189 | // and our own client cert - what about intermediates? |
||
| 190 | $content_encoded .= ' |
||
| 191 | Content-Type: application/x-pkcs12 |
||
| 192 | Content-Transfer-Encoding: base64 |
||
| 193 | |||
| 194 | '.base64_encode($this->clientCert['certdata']). // is PKCS#12, with encrypted key |
||
| 195 | '--{boundary}'; |
||
| 196 | |||
| 197 | // trail this with a double slash |
||
| 198 | $content_encoded .= "--"; |
||
| 199 | // strangely enough, now encode ALL OF THIS in base64 again. Whatever. |
||
| 200 | file_put_contents('installer_profile', base64_encode($content_encoded)); |
||
| 201 | |||
| 202 | $fileName = $this->installerBasename . '.bin'; |
||
| 203 | |||
| 204 | if (!$this->sign) { |
||
| 205 | rename("installer_profile", $fileName); |
||
| 206 | return $fileName; |
||
| 207 | } |
||
| 208 | |||
| 209 | // still here? We are signing. That actually can't be - ONC does not |
||
| 210 | // have the notion of signing |
||
| 211 | // but if they ever change their mind, we are prepared |
||
| 212 | |||
| 213 | $outputFromSigning = system($this->sign . " installer_profile '$fileName' > /dev/null"); |
||
| 214 | if ($outputFromSigning === FALSE) { |
||
| 215 | $this->loggerInstance->debug(2, "Signing the ONC installer $fileName FAILED!\n"); |
||
| 216 | } |
||
| 217 | |||
| 218 | return $fileName; |
||
| 219 | } |
||
| 233 |