Conditions | 18 |
Paths | 6144 |
Total Lines | 108 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
26 | public static function getArgs() |
||
27 | { |
||
28 | /// @todo should we prefix all test parameters with TESTS_ ? |
||
29 | $args = array( |
||
30 | 'DEBUG' => 0, |
||
31 | 'HTTPSERVER' => 'localhost', |
||
32 | 'HTTPURI' => null, |
||
33 | // now that we run tests in Docker by default, with a webserver set up for https, let's default to it |
||
34 | 'HTTPSSERVER' => 'localhost', |
||
35 | 'HTTPSURI' => null, |
||
36 | // example alternative: |
||
37 | //'HTTPSSERVER' => 'gggeek.altervista.org', |
||
38 | //'HTTPSURI' => '/sw/xmlrpc/demo/server/server.php', |
||
39 | 'HTTPSIGNOREPEER' => false, |
||
40 | 'HTTPSVERIFYHOST' => 2, |
||
41 | 'SSLVERSION' => 0, |
||
42 | 'PROXYSERVER' => null, |
||
43 | //'LOCALPATH' => __DIR__, |
||
44 | ); |
||
45 | |||
46 | // check for command line params (passed as env vars) vs. web page input params (passed as GET/POST) |
||
47 | // Note that the only use-case for web-page mode is when this is used by benchmark.php |
||
48 | if (!isset($_SERVER['REQUEST_METHOD'])) { |
||
49 | foreach($_SERVER as $key => $val) { |
||
50 | if (array_key_exists($key, $args)) { |
||
51 | $$key = $val; |
||
52 | } |
||
53 | } |
||
54 | } else { |
||
55 | // NB: we might as well consider using $_GET stuff later on... |
||
56 | extract($_GET); |
||
57 | extract($_POST); |
||
58 | } |
||
59 | |||
60 | if (isset($DEBUG)) { |
||
61 | $args['DEBUG'] = intval($DEBUG); |
||
62 | } |
||
63 | |||
64 | if (isset($HTTPSERVER)) { |
||
65 | $args['HTTPSERVER'] = $HTTPSERVER; |
||
66 | } else { |
||
67 | if (isset($HTTP_HOST)) { |
||
68 | $args['HTTPSERVER'] = $HTTP_HOST; |
||
69 | } elseif (isset($_SERVER['HTTP_HOST'])) { |
||
70 | $args['HTTPSERVER'] = $_SERVER['HTTP_HOST']; |
||
71 | } |
||
72 | } |
||
73 | |||
74 | if (!isset($HTTPURI) || $HTTPURI == '') { |
||
75 | // GUESTIMATE the url of local test controller |
||
76 | // play nice to php 5 and 7 in retrieving URL of index.php |
||
77 | /// @todo filter out query string from REQUEST_URI |
||
78 | /// @todo review this code... |
||
79 | /*if (isset($REQUEST_URI)) { |
||
80 | $HTTPURI = str_replace('/tests/testsuite.php', '/demo/server/server.php', $REQUEST_URI); |
||
81 | $HTTPURI = str_replace('/testsuite.php', '/server.php', $HTTPURI); |
||
82 | $HTTPURI = str_replace('/extras/benchmark.php', '/demo/server/server.php', $HTTPURI); |
||
83 | $HTTPURI = str_replace('/benchmark.php', '/server.php', $HTTPURI); |
||
84 | } elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['REQUEST_METHOD'])) { |
||
85 | $HTTPURI = str_replace('/tests/testsuite.php', '/demo/server/server.php', $_SERVER['PHP_SELF']); |
||
86 | $HTTPURI = str_replace('/testsuite.php', '/server.php', $HTTPURI); |
||
87 | $HTTPURI = str_replace('/extras/benchmark.php', '/demo/server/server.php', $HTTPURI); |
||
88 | $HTTPURI = str_replace('/benchmark.php', '/server.php', $HTTPURI); |
||
89 | } else {*/ |
||
90 | $HTTPURI = '/tests/index.php?demo=server/server.php'; |
||
91 | //} |
||
92 | } |
||
93 | if ($HTTPURI[0] != '/') { |
||
94 | $HTTPURI = '/' . $HTTPURI; |
||
95 | } |
||
96 | $args['HTTPURI'] = $HTTPURI; |
||
97 | |||
98 | if (isset($HTTPSSERVER)) { |
||
99 | $args['HTTPSSERVER'] = $HTTPSSERVER; |
||
100 | } |
||
101 | |||
102 | /// @todo if $HTTPSURI is unset, and HTTPSSERVER == localhost, use HTTPURI |
||
103 | if (isset($HTTPSURI)) { |
||
104 | $args['HTTPSURI'] = $HTTPSURI; |
||
105 | } |
||
106 | |||
107 | if (isset($HTTPSIGNOREPEER)) { |
||
108 | $args['HTTPSIGNOREPEER'] = (bool)$HTTPSIGNOREPEER; |
||
109 | } |
||
110 | |||
111 | if (isset($HTTPSVERIFYHOST)) { |
||
112 | $args['HTTPSVERIFYHOST'] = (int)$HTTPSVERIFYHOST; |
||
113 | } |
||
114 | |||
115 | if (isset($SSLVERSION)) { |
||
116 | $args['SSLVERSION'] = (int)$SSLVERSION; |
||
117 | } |
||
118 | |||
119 | if (isset($PROXYSERVER)) { |
||
120 | $arr = explode(':', $PROXYSERVER); |
||
121 | $args['PROXYSERVER'] = $arr[0]; |
||
122 | if (count($arr) > 1) { |
||
123 | $args['PROXYPORT'] = $arr[1]; |
||
124 | } else { |
||
125 | $args['PROXYPORT'] = 8080; |
||
126 | } |
||
127 | } |
||
128 | |||
129 | //if (isset($LOCALPATH)) { |
||
130 | // $args['LOCALPATH'] = $LOCALPATH; |
||
131 | //} |
||
132 | |||
133 | return $args; |
||
134 | } |
||
136 |