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