| Conditions | 16 |
| Paths | 24 |
| Total Lines | 59 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 85 | public static function getCurrentBinding(ServerRequestInterface $request): Binding |
||
| 86 | { |
||
| 87 | $method = $request->getMethod(); |
||
| 88 | |||
| 89 | switch ($method) { |
||
| 90 | case 'GET': |
||
| 91 | $query = $request->getQueryParams(); |
||
| 92 | if (array_key_exists('SAMLRequest', $query) || array_key_exists('SAMLResponse', $query)) { |
||
| 93 | return new HTTPRedirect(); |
||
| 94 | } elseif (array_key_exists('SAMLart', $query)) { |
||
| 95 | return new HTTPArtifact(); |
||
| 96 | } |
||
| 97 | break; |
||
| 98 | |||
| 99 | case 'POST': |
||
| 100 | $contentType = null; |
||
| 101 | if ($request->hasHeader('Content-Type')) { |
||
| 102 | $contentType = $request->getHeader('Content-Type')[0]; |
||
| 103 | $contentType = explode(';', $contentType); |
||
| 104 | $contentType = $contentType[0]; /* Remove charset. */ |
||
| 105 | } |
||
| 106 | |||
| 107 | $query = $request->getParsedBody(); |
||
| 108 | if (array_key_exists('SAMLRequest', $query) || array_key_exists('SAMLResponse', $query)) { |
||
| 109 | return new HTTPPost(); |
||
| 110 | } elseif (array_key_exists('SAMLart', $query)) { |
||
| 111 | return new HTTPArtifact(); |
||
| 112 | } else { |
||
| 113 | /** |
||
| 114 | * The registration information for text/xml is in all respects the same |
||
| 115 | * as that given for application/xml (RFC 7303 - Section 9.1) |
||
| 116 | */ |
||
| 117 | if ( |
||
| 118 | ($contentType === 'text/xml' || $contentType === 'application/xml') |
||
| 119 | // See paragraph 3.2.3 of Binding for SAML2 (OASIS) |
||
| 120 | || ($request->hasHeader('SOAPAction') |
||
| 121 | && $request->getHeader('SOAPAction')[0] === 'http://www.oasis-open.org/committees/security') |
||
| 122 | ) { |
||
| 123 | return new SOAP(); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | break; |
||
| 127 | } |
||
| 128 | |||
| 129 | $logger = Utils::getContainer()->getLogger(); |
||
| 130 | $logger->warning('Unable to find the SAML 2 binding used for this request.'); |
||
| 131 | $logger->warning('Request method: ' . var_export($method, true)); |
||
| 132 | |||
| 133 | if (!empty($query)) { |
||
| 134 | $logger->warning( |
||
| 135 | $method . " parameters: '" . implode("', '", array_map('addslashes', array_keys($query))) . "'" |
||
| 136 | ); |
||
| 137 | } |
||
| 138 | |||
| 139 | if ($request->hasHeader('Content-Type')) { |
||
| 140 | $logger->warning('Content-Type: ' . var_export($request->getHeader('Content-Type')[0], true)); |
||
| 141 | } |
||
| 142 | |||
| 143 | throw new UnsupportedBindingException('Unable to find the SAML 2 binding used for this request.'); |
||
| 144 | } |
||
| 216 |