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