Conditions | 35 |
Paths | 85 |
Total Lines | 181 |
Code Lines | 83 |
Lines | 73 |
Ratio | 40.33 % |
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 |
||
100 | private function prepareEapConfig($attr) { |
||
101 | $eap = $this->selectedEap; |
||
102 | $w8Ext = ''; |
||
103 | if ($eap != \core\common\EAP::EAPTYPE_TLS && $eap != \core\common\EAP::EAPTYPE_PEAP_MSCHAP2 && $eap != \core\common\EAP::EAPTYPE_PWD && $eap != \core\common\EAP::EAPTYPE_TTLS_PAP && $eap != \core\common\EAP::EAPTYPE_TTLS_MSCHAP2 && $eap != \core\common\EAP::EAPTYPE_SILVERBULLET) { |
||
104 | $this->loggerInstance->debug(2, "this method only allows TLS, PEAP, TTLS-PAP, TTLS-MSCHAPv2 or EAP-pwd"); |
||
105 | error("this method only allows TLS, PEAP, TTLS-PAP, TTLS-MSCHAPv2 or EAP-pwd"); |
||
106 | return; |
||
107 | } |
||
108 | $useAnon = $attr['internal:use_anon_outer'] [0]; |
||
109 | View Code Duplication | if ($useAnon) { |
|
110 | $outerUser = $attr['internal:anon_local_value'][0]; |
||
111 | $outerId = $outerUser . '@' . $attr['internal:realm'][0]; |
||
112 | } |
||
113 | // $servers = preg_quote(implode(';',$attr['eap:server_name'])); |
||
114 | $servers = implode(';', $attr['eap:server_name']); |
||
115 | |||
116 | $caArray = $attr['internal:CAs'][0]; |
||
117 | |||
118 | |||
119 | $profileFileCont = '<EAPConfig><EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig"> |
||
120 | <EapMethod> |
||
121 | '; |
||
122 | |||
123 | $profileFileCont .= '<Type xmlns="http://www.microsoft.com/provisioning/EapCommon">' . |
||
124 | $this->selectedEap["OUTER"] . '</Type> |
||
125 | <VendorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorId> |
||
126 | <VendorType xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorType> |
||
127 | '; |
||
128 | if ($eap == \core\common\EAP::EAPTYPE_TLS || $eap == \core\common\EAP::EAPTYPE_SILVERBULLET) { |
||
129 | $profileFileCont .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId> |
||
130 | </EapMethod> |
||
131 | '; |
||
132 | $profileFileCont .= ' |
||
133 | |||
134 | <Config xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1" |
||
135 | xmlns:eapTls="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV1"> |
||
136 | <baseEap:Eap> |
||
137 | <baseEap:Type>13</baseEap:Type> |
||
138 | <eapTls:EapType> |
||
139 | <eapTls:CredentialsSource> |
||
140 | <eapTls:CertificateStore /> |
||
141 | </eapTls:CredentialsSource> |
||
142 | <eapTls:ServerValidation> |
||
143 | <eapTls:DisableUserPromptForServerValidation>true</eapTls:DisableUserPromptForServerValidation> |
||
144 | <eapTls:ServerNames>' . $servers . '</eapTls:ServerNames>'; |
||
145 | View Code Duplication | if ($caArray) { |
|
146 | foreach ($caArray as $certAuthority) { |
||
147 | if ($certAuthority['root']) { |
||
148 | $profileFileCont .= "<eapTls:TrustedRootCA>" . $certAuthority['sha1'] . "</eapTls:TrustedRootCA>\n"; |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | $profileFileCont .= '</eapTls:ServerValidation> |
||
153 | '; |
||
154 | View Code Duplication | if (isset($attr['eap-specific:tls_use_other_id']) && $attr['eap-specific:tls_use_other_id'][0] == 'on') { |
|
155 | $profileFileCont .= '<eapTls:DifferentUsername>true</eapTls:DifferentUsername>'; |
||
156 | $this->tlsOtherUsername = 1; |
||
157 | } else { |
||
158 | $profileFileCont .= '<eapTls:DifferentUsername>false</eapTls:DifferentUsername>'; |
||
159 | } |
||
160 | $profileFileCont .= ' |
||
161 | </eapTls:EapType> |
||
162 | </baseEap:Eap> |
||
163 | </Config> |
||
164 | '; |
||
165 | View Code Duplication | } elseif ($eap == \core\common\EAP::EAPTYPE_PEAP_MSCHAP2) { |
|
166 | if (isset($attr['eap:enable_nea']) && $attr['eap:enable_nea'][0] == 'on') { |
||
167 | $nea = 'true'; |
||
168 | } else { |
||
169 | $nea = 'false'; |
||
170 | } |
||
171 | $profileFileCont .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId> |
||
172 | </EapMethod> |
||
173 | '; |
||
174 | $w8Ext = '<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig"> |
||
175 | <Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1"> |
||
176 | <Type>25</Type> |
||
177 | <EapType xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV1"> |
||
178 | <ServerValidation> |
||
179 | <DisableUserPromptForServerValidation>true</DisableUserPromptForServerValidation> |
||
180 | <ServerNames>' . $servers . '</ServerNames>'; |
||
181 | if ($caArray) { |
||
182 | foreach ($caArray as $certAuthority) { |
||
183 | if ($certAuthority['root']) { |
||
184 | $w8Ext .= "<TrustedRootCA>" . $certAuthority['sha1'] . "</TrustedRootCA>\n"; |
||
185 | } |
||
186 | } |
||
187 | } |
||
188 | $w8Ext .= '</ServerValidation> |
||
189 | <FastReconnect>true</FastReconnect> |
||
190 | <InnerEapOptional>false</InnerEapOptional> |
||
191 | <Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1"> |
||
192 | <Type>26</Type> |
||
193 | <EapType xmlns="http://www.microsoft.com/provisioning/MsChapV2ConnectionPropertiesV1"> |
||
194 | <UseWinLogonCredentials>false</UseWinLogonCredentials> |
||
195 | </EapType> |
||
196 | </Eap> |
||
197 | <EnableQuarantineChecks>' . $nea . '</EnableQuarantineChecks> |
||
198 | <RequireCryptoBinding>false</RequireCryptoBinding> |
||
199 | '; |
||
200 | if ($useAnon == 1) { |
||
201 | $w8Ext .= '<PeapExtensions> |
||
202 | <IdentityPrivacy xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2"> |
||
203 | <EnableIdentityPrivacy>true</EnableIdentityPrivacy> |
||
204 | '; |
||
205 | if (isset($outerUser) && $outerUser) { |
||
206 | $w8Ext .= '<AnonymousUserName>' . $outerUser . '</AnonymousUserName> |
||
207 | '; |
||
208 | } else { |
||
209 | $w8Ext .= '<AnonymousUserName/> |
||
210 | '; |
||
211 | } |
||
212 | $w8Ext .= '</IdentityPrivacy> |
||
213 | </PeapExtensions> |
||
214 | '; |
||
215 | } |
||
216 | $w8Ext .= '</EapType> |
||
217 | </Eap> |
||
218 | </Config> |
||
219 | '; |
||
220 | } elseif ($eap == \core\common\EAP::EAPTYPE_TTLS_PAP || $eap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2) { |
||
221 | $profileFileCont .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">311</AuthorId> |
||
222 | </EapMethod> |
||
223 | '; |
||
224 | $w8Ext = '<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig"> |
||
225 | <EapTtls xmlns="http://www.microsoft.com/provisioning/EapTtlsConnectionPropertiesV1"> |
||
226 | <ServerValidation> |
||
227 | <ServerNames>' . $servers . '</ServerNames> '; |
||
228 | if ($caArray) { |
||
229 | foreach ($caArray as $certAuthority) { |
||
230 | if ($certAuthority['root']) { |
||
231 | $w8Ext .= "<TrustedRootCAHash>" . chunk_split($certAuthority['sha1'], 2, ' ') . "</TrustedRootCAHash>\n"; |
||
232 | } |
||
233 | } |
||
234 | } |
||
235 | $w8Ext .= '<DisablePrompt>true</DisablePrompt> |
||
236 | </ServerValidation> |
||
237 | <Phase2Authentication> |
||
238 | '; |
||
239 | if ($eap == \core\common\EAP::EAPTYPE_TTLS_PAP) { |
||
240 | $w8Ext .= '<PAPAuthentication /> '; |
||
241 | } |
||
242 | if ($eap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2) { |
||
243 | $w8Ext .= '<MSCHAPv2Authentication> |
||
244 | <UseWinlogonCredentials>false</UseWinlogonCredentials> |
||
245 | </MSCHAPv2Authentication> |
||
246 | '; |
||
247 | } |
||
248 | $w8Ext .= '</Phase2Authentication> |
||
249 | <Phase1Identity> |
||
250 | '; |
||
251 | if ($useAnon == 1) { |
||
252 | $w8Ext .= '<IdentityPrivacy>true</IdentityPrivacy> |
||
253 | '; |
||
254 | if (isset($outerId) && $outerId) { |
||
255 | $w8Ext .= '<AnonymousIdentity>' . $outerId . '</AnonymousIdentity> |
||
256 | '; |
||
257 | } else { |
||
258 | $w8Ext .= '<AnonymousIdentity/> |
||
259 | '; |
||
260 | } |
||
261 | } else { |
||
262 | $w8Ext .= '<IdentityPrivacy>false</IdentityPrivacy> |
||
263 | '; |
||
264 | } |
||
265 | $w8Ext .= '</Phase1Identity> |
||
266 | </EapTtls> |
||
267 | </Config> |
||
268 | '; |
||
269 | } elseif ($eap == \core\common\EAP::EAPTYPE_PWD) { |
||
270 | $profileFileCont .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId> |
||
271 | </EapMethod> |
||
272 | '; |
||
273 | $profileFileCont .= '<ConfigBlob></ConfigBlob>'; |
||
274 | } |
||
275 | |||
276 | $profileFileContEnd = '</EapHostConfig></EAPConfig>'; |
||
277 | $returnArray = []; |
||
278 | $returnArray['w8'] = $profileFileCont . $w8Ext . $profileFileContEnd; |
||
279 | return $returnArray; |
||
280 | } |
||
281 | |||
487 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.