| Conditions | 6 |
| Paths | 32 |
| Total Lines | 97 |
| Code Lines | 49 |
| 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 |
||
| 47 | public function asArray() |
||
| 48 | { |
||
| 49 | $conf = []; |
||
| 50 | |||
| 51 | $conf['strict'] = $this->config()->get('strict'); |
||
| 52 | $conf['debug'] = $this->config()->get('debug'); |
||
| 53 | |||
| 54 | // SERVICE PROVIDER SECTION |
||
| 55 | $sp = $this->config()->get('SP'); |
||
| 56 | $spCertPath = Director::is_absolute($sp['x509cert']) |
||
| 57 | ? $sp['x509cert'] |
||
| 58 | : sprintf('%s/%s', BASE_PATH, $sp['x509cert']); |
||
| 59 | $spKeyPath = Director::is_absolute($sp['privateKey']) |
||
| 60 | ? $sp['privateKey'] |
||
| 61 | : sprintf('%s/%s', BASE_PATH, $sp['privateKey']); |
||
| 62 | |||
| 63 | $conf['sp']['entityId'] = $sp['entityId']; |
||
| 64 | $conf['sp']['assertionConsumerService'] = [ |
||
| 65 | 'url' => $sp['entityId'] . '/saml/acs', |
||
| 66 | 'binding' => OneLogin_Saml2_Constants::BINDING_HTTP_POST |
||
| 67 | ]; |
||
| 68 | $conf['sp']['NameIDFormat'] = isset($sp['nameIdFormat']) ? $sp['nameIdFormat'] : OneLogin_Saml2_Constants::NAMEID_TRANSIENT; |
||
| 69 | $conf['sp']['x509cert'] = file_get_contents($spCertPath); |
||
| 70 | $conf['sp']['privateKey'] = file_get_contents($spKeyPath); |
||
| 71 | |||
| 72 | // IDENTITY PROVIDER SECTION |
||
| 73 | $idp = $this->config()->get('IdP'); |
||
| 74 | $conf['idp']['entityId'] = $idp['entityId']; |
||
| 75 | $conf['idp']['singleSignOnService'] = [ |
||
| 76 | 'url' => $idp['singleSignOnService'], |
||
| 77 | 'binding' => OneLogin_Saml2_Constants::BINDING_HTTP_REDIRECT, |
||
| 78 | ]; |
||
| 79 | if (isset($idp['singleLogoutService'])) { |
||
| 80 | $conf['idp']['singleLogoutService'] = [ |
||
| 81 | 'url' => $idp['singleLogoutService'], |
||
| 82 | 'binding' => OneLogin_Saml2_Constants::BINDING_HTTP_REDIRECT, |
||
| 83 | ]; |
||
| 84 | } |
||
| 85 | |||
| 86 | $idpCertPath = Director::is_absolute($idp['x509cert']) |
||
| 87 | ? $idp['x509cert'] |
||
| 88 | : sprintf('%s/%s', BASE_PATH, $idp['x509cert']); |
||
| 89 | $conf['idp']['x509cert'] = file_get_contents($idpCertPath); |
||
| 90 | |||
| 91 | // SECURITY SECTION |
||
| 92 | $security = $this->config()->get('Security'); |
||
| 93 | $signatureAlgorithm = $security['signatureAlgorithm']; |
||
| 94 | |||
| 95 | $conf['security'] = [ |
||
| 96 | /** signatures and encryptions offered */ |
||
| 97 | // Indicates that the nameID of the <samlp:logoutRequest> sent by this SP will be encrypted. |
||
| 98 | 'nameIdEncrypted' => true, |
||
| 99 | // Indicates whether the <samlp:AuthnRequest> messages sent by this SP will be signed. [Metadata of the |
||
| 100 | // SP will offer this info] |
||
| 101 | 'authnRequestsSigned' => true, |
||
| 102 | // Indicates whether the <samlp:logoutRequest> messages sent by this SP will be signed. |
||
| 103 | 'logoutRequestSigned' => true, |
||
| 104 | // Indicates whether the <samlp:logoutResponse> messages sent by this SP will be signed. |
||
| 105 | 'logoutResponseSigned' => true, |
||
| 106 | 'signMetadata' => false, |
||
| 107 | /** signatures and encryptions required **/ |
||
| 108 | // Indicates a requirement for the <samlp:Response>, <samlp:LogoutRequest> |
||
| 109 | // and <samlp:LogoutResponse> elements received by this SP to be signed. |
||
| 110 | 'wantMessagesSigned' => false, |
||
| 111 | // Indicates a requirement for the <saml:Assertion> elements received by |
||
| 112 | // this SP to be signed. [Metadata of the SP will offer this info] |
||
| 113 | 'wantAssertionsSigned' => true, |
||
| 114 | // Indicates a requirement for the NameID received by |
||
| 115 | // this SP to be encrypted. |
||
| 116 | 'wantNameIdEncrypted' => false, |
||
| 117 | |||
| 118 | // Algorithm that the toolkit will use on signing process. Options: |
||
| 119 | // - 'http://www.w3.org/2000/09/xmldsig#rsa-sha1' |
||
| 120 | // - 'http://www.w3.org/2000/09/xmldsig#dsa-sha1' |
||
| 121 | // - 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256' |
||
| 122 | // - 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha384' |
||
| 123 | // - 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512' |
||
| 124 | 'signatureAlgorithm' => $signatureAlgorithm, |
||
| 125 | |||
| 126 | // Authentication context. |
||
| 127 | // Set to false and no AuthContext will be sent in the AuthNRequest, |
||
| 128 | // Set true or don't present thi parameter and you will get an AuthContext |
||
| 129 | // 'exact' 'urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport' |
||
| 130 | // Set an array with the possible auth context values: |
||
| 131 | // array ('urn:oasis:names:tc:SAML:2.0:ac:classes:Password', 'urn:oasis:names:tc:SAML:2.0:ac:classes:X509'), |
||
| 132 | 'requestedAuthnContext' => [ |
||
| 133 | 'urn:federation:authentication:windows', |
||
| 134 | 'urn:oasis:names:tc:SAML:2.0:ac:classes:Password', |
||
| 135 | 'urn:oasis:names:tc:SAML:2.0:ac:classes:X509', |
||
| 136 | ], |
||
| 137 | // Indicates if the SP will validate all received xmls. |
||
| 138 | // (In order to validate the xml, 'strict' and 'wantXMLValidation' must be true). |
||
| 139 | 'wantXMLValidation' => true, |
||
| 140 | ]; |
||
| 141 | |||
| 142 | return $conf; |
||
| 143 | } |
||
| 144 | } |
||
| 145 |
This check marks private properties in classes that are never used. Those properties can be removed.