Conditions | 12 |
Paths | 7 |
Total Lines | 37 |
Code Lines | 26 |
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 |
||
18 | function getAllHeaders_xmlrpc($req) |
||
|
|||
19 | { |
||
20 | if (function_exists('getallheaders')) { |
||
21 | $headers = getallheaders(); |
||
22 | } else { |
||
23 | // poor man's version of getallheaders. Thanks ralouphie/getallheaders |
||
24 | $headers = array(); |
||
25 | $copy_server = array( |
||
26 | 'CONTENT_TYPE' => 'Content-Type', |
||
27 | 'CONTENT_LENGTH' => 'Content-Length', |
||
28 | 'CONTENT_MD5' => 'Content-Md5', |
||
29 | ); |
||
30 | foreach ($_SERVER as $key => $value) { |
||
31 | if (substr($key, 0, 5) === 'HTTP_') { |
||
32 | $key = substr($key, 5); |
||
33 | if (!isset($copy_server[$key]) || !isset($_SERVER[$key])) { |
||
34 | $key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', $key)))); |
||
35 | $headers[$key] = $value; |
||
36 | } |
||
37 | } elseif (isset($copy_server[$key])) { |
||
38 | $headers[$copy_server[$key]] = $value; |
||
39 | } |
||
40 | } |
||
41 | if (!isset($headers['Authorization'])) { |
||
42 | if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) { |
||
43 | $headers['Authorization'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION']; |
||
44 | } elseif (isset($_SERVER['PHP_AUTH_USER'])) { |
||
45 | $basic_pass = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : ''; |
||
46 | $headers['Authorization'] = 'Basic ' . base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . $basic_pass); |
||
47 | } elseif (isset($_SERVER['PHP_AUTH_DIGEST'])) { |
||
48 | $headers['Authorization'] = $_SERVER['PHP_AUTH_DIGEST']; |
||
49 | } |
||
50 | } |
||
51 | } |
||
52 | |||
53 | $encoder = new Encoder(); |
||
54 | return new Response($encoder->encode($headers)); |
||
55 | } |
||
150 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.