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