| Conditions | 7 |
| Paths | 36 |
| Total Lines | 130 |
| 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 | $content_encoded = chunk_split(base64_encode($content), 76, "\n"); |
||
| 167 | // sigh... we need to construct a MIME envelope for the payload and the cert data |
||
| 168 | $content_encoded = 'Content-Type: multipart/mixed; boundary={boundary} |
||
| 169 | Content-Transfer-Encoding: base64 |
||
| 170 | |||
| 171 | --{boundary} |
||
| 172 | Content-Type: application/x-passpoint-profile |
||
| 173 | Content-Transfer-Encoding: base64 |
||
| 174 | |||
| 175 | '.$content_encoded.'--{boundary}'; |
||
| 176 | // then, another MIME body for each CA certificate we referenced earlier |
||
| 177 | // only leaves me to wonder what the "URL" for those is... |
||
| 178 | foreach ($this->attributes['internal:CAs'][0] as $oneCert) { |
||
| 179 | $content_encoded .= ' |
||
| 180 | Content-Type: application/x-x509-ca-cert |
||
| 181 | Content-Transfer-Encoding: base64 |
||
| 182 | |||
| 183 | '.chunk_split(base64_encode($oneCert['der']), 76, "\n"). |
||
| 184 | '--{boundary}'; |
||
| 185 | |||
| 186 | } |
||
| 187 | // and our own client cert - what about intermediates? |
||
| 188 | $content_encoded .= ' |
||
| 189 | Content-Type: application/x-pkcs12 |
||
| 190 | Content-Transfer-Encoding: base64 |
||
| 191 | |||
| 192 | '.chunk_split(base64_encode($this->clientCert['certdataclear']), 76, "\n"). // is PKCS#12, with encrypted key |
||
| 193 | '--{boundary}'; |
||
| 194 | |||
| 195 | // trail this with a double slash and a newline |
||
| 196 | $content_encoded .= "--\n"; |
||
| 197 | // strangely enough, now encode ALL OF THIS in base64 again. Whatever. |
||
| 198 | file_put_contents('installer_profile', chunk_split(base64_encode($content_encoded), 76, "\n")); |
||
| 199 | |||
| 200 | // $fileName = $this->installerBasename . '.bin'; |
||
| 201 | $fileName = "passpoint.config"; |
||
| 202 | |||
| 203 | if (!$this->sign) { |
||
| 204 | rename("installer_profile", $fileName); |
||
| 205 | return $fileName; |
||
| 206 | } |
||
| 207 | |||
| 208 | // still here? We are signing. That actually can't be - ONC does not |
||
| 209 | // have the notion of signing |
||
| 210 | // but if they ever change their mind, we are prepared |
||
| 211 | |||
| 212 | $outputFromSigning = system($this->sign . " installer_profile '$fileName' > /dev/null"); |
||
| 213 | if ($outputFromSigning === FALSE) { |
||
| 214 | $this->loggerInstance->debug(2, "Signing the ONC installer $fileName FAILED!\n"); |
||
| 215 | } |
||
| 216 | |||
| 217 | return $fileName; |
||
| 218 | } |
||
| 232 |