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