| Conditions | 4 |
| Paths | 8 |
| Total Lines | 74 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 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 |
||
| 38 | public function asArray() |
||
| 39 | { |
||
| 40 | $conf = array(); |
||
| 41 | |||
| 42 | $conf['strict'] = $this->config()->get('strict'); |
||
| 43 | $conf['debug'] = $this->config()->get('debug'); |
||
| 44 | |||
| 45 | // SERVICE PROVIDER SECTION |
||
| 46 | $sp = $this->config()->get('SP'); |
||
| 47 | $certPath = Director::is_absolute($sp['x509cert']) ? $sp['x509cert'] : sprintf('%s/%s', BASE_PATH, $sp['x509cert']); |
||
| 48 | $keyPath = Director::is_absolute($sp['privateKey']) ? $sp['privateKey'] : sprintf('%s/%s', BASE_PATH, $sp['privateKey']); |
||
| 49 | $conf['sp']['entityId'] = $sp['entityId']; |
||
| 50 | $conf['sp']['assertionConsumerService'] = array( |
||
| 51 | 'url' => $sp['entityId'] . '/saml/acs', |
||
| 52 | 'binding' => OneLogin_Saml2_Constants::BINDING_HTTP_POST |
||
| 53 | ); |
||
| 54 | $conf['sp']['NameIDFormat'] = OneLogin_Saml2_Constants::NAMEID_TRANSIENT; |
||
| 55 | $conf['sp']['x509cert'] = file_get_contents($certPath); |
||
| 56 | $conf['sp']['privateKey'] = file_get_contents($keyPath); |
||
| 57 | |||
| 58 | // IDENTITY PROVIDER SECTION |
||
| 59 | $idp = $this->config()->get('IdP'); |
||
| 60 | $conf['idp']['entityId'] = $idp['entityId']; |
||
| 61 | $conf['idp']['singleSignOnService'] = array( |
||
| 62 | 'url' => $idp['singleSignOnService'], |
||
| 63 | 'binding' => OneLogin_Saml2_Constants::BINDING_HTTP_REDIRECT, |
||
| 64 | ); |
||
| 65 | if (isset($idp['singleLogoutService'])) { |
||
| 66 | $conf['idp']['singleLogoutService'] = array( |
||
| 67 | 'url' => $idp['singleLogoutService'], |
||
| 68 | 'binding' => OneLogin_Saml2_Constants::BINDING_HTTP_REDIRECT, |
||
| 69 | ); |
||
| 70 | } |
||
| 71 | |||
| 72 | $conf['idp']['x509cert'] = file_get_contents($certPath); |
||
| 73 | |||
| 74 | // SECURITY SECTION |
||
| 75 | $conf['security'] = array( |
||
| 76 | /** signatures and encryptions offered */ |
||
| 77 | // Indicates that the nameID of the <samlp:logoutRequest> sent by this SP will be encrypted. |
||
| 78 | 'nameIdEncrypted' => true, |
||
| 79 | // Indicates whether the <samlp:AuthnRequest> messages sent by this SP will be signed. [Metadata of the SP will offer this info] |
||
| 80 | 'authnRequestsSigned' => true, |
||
| 81 | // Indicates whether the <samlp:logoutRequest> messages sent by this SP will be signed. |
||
| 82 | 'logoutRequestSigned' => true, |
||
| 83 | // Indicates whether the <samlp:logoutResponse> messages sent by this SP will be signed. |
||
| 84 | 'logoutResponseSigned' => true, |
||
| 85 | 'signMetadata' => false, |
||
| 86 | /** signatures and encryptions required **/ |
||
| 87 | // Indicates a requirement for the <samlp:Response>, <samlp:LogoutRequest> |
||
| 88 | // and <samlp:LogoutResponse> elements received by this SP to be signed. |
||
| 89 | 'wantMessagesSigned' => false, |
||
| 90 | // Indicates a requirement for the <saml:Assertion> elements received by |
||
| 91 | // this SP to be signed. [Metadata of the SP will offer this info] |
||
| 92 | 'wantAssertionsSigned' => true, |
||
| 93 | // Indicates a requirement for the NameID received by |
||
| 94 | // this SP to be encrypted. |
||
| 95 | 'wantNameIdEncrypted' => false, |
||
| 96 | // Authentication context. |
||
| 97 | // Set to false and no AuthContext will be sent in the AuthNRequest, |
||
| 98 | // Set true or don't present thi parameter and you will get an AuthContext 'exact' 'urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport' |
||
| 99 | // Set an array with the possible auth context values: array ('urn:oasis:names:tc:SAML:2.0:ac:classes:Password', 'urn:oasis:names:tc:SAML:2.0:ac:classes:X509'), |
||
| 100 | 'requestedAuthnContext' => array( |
||
| 101 | 'urn:federation:authentication:windows', |
||
| 102 | 'urn:oasis:names:tc:SAML:2.0:ac:classes:Password', |
||
| 103 | 'urn:oasis:names:tc:SAML:2.0:ac:classes:X509', |
||
| 104 | ), |
||
| 105 | // Indicates if the SP will validate all received xmls. |
||
| 106 | // (In order to validate the xml, 'strict' and 'wantXMLValidation' must be true). |
||
| 107 | 'wantXMLValidation' => true, |
||
| 108 | ); |
||
| 109 | |||
| 110 | return $conf; |
||
| 111 | } |
||
| 112 | } |
||
| 113 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.