Conditions | 37 |
Paths | 288 |
Total Lines | 237 |
Code Lines | 110 |
Lines | 76 |
Ratio | 32.07 % |
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 |
||
105 | private function prepareEapConfig($attr) { |
||
106 | $eap = $this->selectedEap; |
||
107 | $w10Ext = ''; |
||
108 | // there is only one caller to this function, and it will always call |
||
109 | // with exactly one of exactly the EAP types below. Let's assert() that |
||
110 | // rather than returning void, otherwise this is a condition that needs |
||
111 | // to be caught later on. |
||
112 | assert(in_array($eap, [\core\common\EAP::EAPTYPE_TLS, |
||
113 | \core\common\EAP::EAPTYPE_PEAP_MSCHAP2, |
||
114 | \core\common\EAP::EAPTYPE_PWD, |
||
115 | \core\common\EAP::EAPTYPE_TTLS_PAP, |
||
116 | \core\common\EAP::EAPTYPE_TTLS_MSCHAP2, |
||
117 | \core\common\EAP::EAPTYPE_SILVERBULLET]), new Exception("prepareEapConfig called for an EAP type it cannot handle!")); |
||
118 | |||
119 | $useAnon = $attr['internal:use_anon_outer'] [0]; |
||
120 | View Code Duplication | if ($useAnon) { |
|
121 | $outerUser = $attr['internal:anon_local_value'][0]; |
||
122 | $outerId = $outerUser . '@' . $attr['internal:realm'][0]; |
||
123 | } |
||
124 | // $servers = preg_quote(implode(';',$attr['eap:server_name'])); |
||
125 | $servers = implode(';', $attr['eap:server_name']); |
||
126 | $caArray = $attr['internal:CAs'][0]; |
||
127 | $authorId = "0"; |
||
128 | if ($eap == \core\common\EAP::EAPTYPE_TTLS_PAP || $eap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2) { |
||
129 | if ($this->useGeantLink) { |
||
130 | $authorId = "67532"; |
||
131 | $servers = implode('</ServerName><ServerName>', $attr['eap:server_name']); |
||
132 | } else { |
||
133 | $authorId = "311"; |
||
134 | } |
||
135 | } |
||
136 | |||
137 | $profileFileCont = '<EAPConfig><EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig"> |
||
138 | <EapMethod> |
||
139 | '; |
||
140 | |||
141 | $profileFileCont .= '<Type xmlns="http://www.microsoft.com/provisioning/EapCommon">' . |
||
142 | $this->selectedEap["OUTER"] . '</Type> |
||
143 | <VendorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorId> |
||
144 | <VendorType xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorType> |
||
145 | <AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">' . $authorId . '</AuthorId> |
||
146 | </EapMethod> |
||
147 | '; |
||
148 | if ($eap == \core\common\EAP::EAPTYPE_TLS || $eap == \core\common\EAP::EAPTYPE_SILVERBULLET) { |
||
149 | $profileFileCont .= ' |
||
150 | |||
151 | <Config xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1" |
||
152 | xmlns:eapTls="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV1"> |
||
153 | <baseEap:Eap> |
||
154 | <baseEap:Type>13</baseEap:Type> |
||
155 | <eapTls:EapType> |
||
156 | <eapTls:CredentialsSource> |
||
157 | <eapTls:CertificateStore /> |
||
158 | </eapTls:CredentialsSource> |
||
159 | <eapTls:ServerValidation> |
||
160 | <eapTls:DisableUserPromptForServerValidation>true</eapTls:DisableUserPromptForServerValidation> |
||
161 | <eapTls:ServerNames>' . $servers . '</eapTls:ServerNames>'; |
||
162 | View Code Duplication | if ($caArray) { |
|
163 | foreach ($caArray as $certAuthority) { |
||
164 | if ($certAuthority['root']) { |
||
165 | $profileFileCont .= "<eapTls:TrustedRootCA>" . $certAuthority['sha1'] . "</eapTls:TrustedRootCA>\n"; |
||
166 | } |
||
167 | } |
||
168 | } |
||
169 | $profileFileCont .= '</eapTls:ServerValidation> |
||
170 | '; |
||
171 | View Code Duplication | if (isset($attr['eap-specific:tls_use_other_id']) && $attr['eap-specific:tls_use_other_id'][0] == 'on') { |
|
172 | $profileFileCont .= '<eapTls:DifferentUsername>true</eapTls:DifferentUsername>'; |
||
173 | $this->tlsOtherUsername = 1; |
||
174 | } else { |
||
175 | $profileFileCont .= '<eapTls:DifferentUsername>false</eapTls:DifferentUsername>'; |
||
176 | } |
||
177 | $profileFileCont .= ' |
||
178 | </eapTls:EapType> |
||
179 | </baseEap:Eap> |
||
180 | </Config> |
||
181 | '; |
||
182 | View Code Duplication | } elseif ($eap == \core\common\EAP::EAPTYPE_PEAP_MSCHAP2) { |
|
183 | if (isset($attr['eap:enable_nea']) && $attr['eap:enable_nea'][0] == 'on') { |
||
184 | $nea = 'true'; |
||
185 | } else { |
||
186 | $nea = 'false'; |
||
187 | } |
||
188 | $w10Ext = '<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig"> |
||
189 | <Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1"> |
||
190 | <Type>25</Type> |
||
191 | <EapType xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV1"> |
||
192 | <ServerValidation> |
||
193 | <DisableUserPromptForServerValidation>true</DisableUserPromptForServerValidation> |
||
194 | <ServerNames>' . $servers . '</ServerNames>'; |
||
195 | if ($caArray) { |
||
196 | foreach ($caArray as $certAuthority) { |
||
197 | if ($certAuthority['root']) { |
||
198 | $w10Ext .= "<TrustedRootCA>" . $certAuthority['sha1'] . "</TrustedRootCA>\n"; |
||
199 | } |
||
200 | } |
||
201 | } |
||
202 | $w10Ext .= '</ServerValidation> |
||
203 | <FastReconnect>true</FastReconnect> |
||
204 | <InnerEapOptional>false</InnerEapOptional> |
||
205 | <Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1"> |
||
206 | <Type>26</Type> |
||
207 | <EapType xmlns="http://www.microsoft.com/provisioning/MsChapV2ConnectionPropertiesV1"> |
||
208 | <UseWinLogonCredentials>false</UseWinLogonCredentials> |
||
209 | </EapType> |
||
210 | </Eap> |
||
211 | <EnableQuarantineChecks>' . $nea . '</EnableQuarantineChecks> |
||
212 | <RequireCryptoBinding>false</RequireCryptoBinding> |
||
213 | '; |
||
214 | if ($useAnon == 1) { |
||
215 | $w10Ext .= '<PeapExtensions> |
||
216 | <IdentityPrivacy xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2"> |
||
217 | <EnableIdentityPrivacy>true</EnableIdentityPrivacy> |
||
218 | '; |
||
219 | if (isset($outerUser) && $outerUser) { |
||
220 | $w10Ext .= '<AnonymousUserName>' . $outerUser . '</AnonymousUserName> |
||
221 | '; |
||
222 | } else { |
||
223 | $w10Ext .= '<AnonymousUserName/> |
||
224 | '; |
||
225 | } |
||
226 | $w10Ext .= '</IdentityPrivacy> |
||
227 | </PeapExtensions> |
||
228 | '; |
||
229 | } |
||
230 | $w10Ext .= '</EapType> |
||
231 | </Eap> |
||
232 | </Config> |
||
233 | '; |
||
234 | } elseif ($eap == \core\common\EAP::EAPTYPE_TTLS_PAP || $eap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2) { |
||
235 | if ($this->useGeantLink) { |
||
236 | $innerMethod = 'MSCHAPv2'; |
||
237 | if ($eap == \core\common\EAP::EAPTYPE_TTLS_PAP) { |
||
238 | $innerMethod = 'PAP'; |
||
239 | } |
||
240 | $profileFileCont .= ' |
||
241 | <Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig"> |
||
242 | <EAPIdentityProviderList xmlns="urn:ietf:params:xml:ns:yang:ietf-eap-metadata"> |
||
243 | <EAPIdentityProvider ID="' . $this->deviceUUID . '" namespace="urn:UUID"> |
||
244 | |||
245 | <ProviderInfo> |
||
246 | <DisplayName>' . $this->translateString($attr['general:instname'][0], $this->code_page) . '</DisplayName> |
||
247 | </ProviderInfo> |
||
248 | <AuthenticationMethods> |
||
249 | <AuthenticationMethod> |
||
250 | <EAPMethod>21</EAPMethod> |
||
251 | <ClientSideCredential> |
||
252 | <allow-save>true</allow-save> |
||
253 | '; |
||
254 | if ($use_anon == 1) { |
||
255 | if ($outer_user == '') |
||
256 | $profileFileCont .= '<AnonymousIdentity>@</AnonymousIdentity>'; |
||
257 | else |
||
258 | $profileFileCont .= '<AnonymousIdentity>' . $outer_id . '</AnonymousIdentity>'; |
||
259 | } |
||
260 | $profileFileCont .= '</ClientSideCredential> |
||
261 | <ServerSideCredential> |
||
262 | '; |
||
263 | |||
264 | View Code Duplication | foreach ($caArray as $ca) { |
|
265 | $profileFileCont .= '<CA><format>PEM</format><cert-data>'; |
||
266 | $profileFileCont .= base64_encode($ca['der']); |
||
267 | $profileFileCont .= '</cert-data></CA> |
||
268 | '; |
||
269 | } |
||
270 | $profileFileCont .= "<ServerName>$servers</ServerName>\n"; |
||
271 | |||
272 | $profileFileCont .= ' |
||
273 | </ServerSideCredential> |
||
274 | <InnerAuthenticationMethod> |
||
275 | <NonEAPAuthMethod>' . $innerMethod . '</NonEAPAuthMethod> |
||
276 | </InnerAuthenticationMethod> |
||
277 | <VendorSpecific> |
||
278 | <SessionResumption>false</SessionResumption> |
||
279 | </VendorSpecific> |
||
280 | </AuthenticationMethod> |
||
281 | </AuthenticationMethods> |
||
282 | </EAPIdentityProvider> |
||
283 | </EAPIdentityProviderList> |
||
284 | </Config> |
||
285 | '; |
||
286 | } else { |
||
287 | $w10Ext = '<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig"> |
||
288 | <EapTtls xmlns="http://www.microsoft.com/provisioning/EapTtlsConnectionPropertiesV1"> |
||
289 | <ServerValidation> |
||
290 | <ServerNames>' . $servers . '</ServerNames> '; |
||
291 | if ($caArray) { |
||
292 | foreach ($caArray as $certAuthority) { |
||
293 | if ($certAuthority['root']) { |
||
294 | $w10Ext .= "<TrustedRootCAHash>" . chunk_split($certAuthority['sha1'], 2, ' ') . "</TrustedRootCAHash>\n"; |
||
295 | } |
||
296 | } |
||
297 | } |
||
298 | $w10Ext .= '<DisablePrompt>true</DisablePrompt> |
||
299 | </ServerValidation> |
||
300 | <Phase2Authentication> |
||
301 | '; |
||
302 | if ($eap == \core\common\EAP::EAPTYPE_TTLS_PAP) { |
||
303 | $w10Ext .= '<PAPAuthentication /> '; |
||
304 | } |
||
305 | if ($eap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2) { |
||
306 | $w10Ext .= '<MSCHAPv2Authentication> |
||
307 | <UseWinlogonCredentials>false</UseWinlogonCredentials> |
||
308 | </MSCHAPv2Authentication> |
||
309 | '; |
||
310 | } |
||
311 | $w10Ext .= '</Phase2Authentication> |
||
312 | <Phase1Identity> |
||
313 | '; |
||
314 | if ($useAnon == 1) { |
||
315 | $w10Ext .= '<IdentityPrivacy>true</IdentityPrivacy> |
||
316 | '; |
||
317 | if (isset($outerId) && $outerId) { |
||
318 | $w10Ext .= '<AnonymousIdentity>' . $outerId . '</AnonymousIdentity> |
||
319 | '; |
||
320 | } else { |
||
321 | $w10Ext .= '<AnonymousIdentity/> |
||
322 | '; |
||
323 | } |
||
324 | } else { |
||
325 | $w10Ext .= '<IdentityPrivacy>false</IdentityPrivacy> |
||
326 | '; |
||
327 | } |
||
328 | $w10Ext .= '</Phase1Identity> |
||
329 | </EapTtls> |
||
330 | </Config> |
||
331 | '; |
||
332 | } |
||
333 | } elseif ($eap == \core\common\EAP::EAPTYPE_PWD) { |
||
334 | $profileFileCont .= '<ConfigBlob></ConfigBlob>'; |
||
335 | } |
||
336 | |||
337 | $profileFileContEnd = '</EapHostConfig></EAPConfig>'; |
||
338 | $returnArray = []; |
||
339 | $returnArray['w10'] = $profileFileCont . $w10Ext . $profileFileContEnd; |
||
340 | return $returnArray; |
||
341 | } |
||
342 | |||
558 |
This check looks for calls to
isset(...)
orempty()
on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.