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