| Conditions | 28 | 
| Paths | > 20000 | 
| Total Lines | 123 | 
| Code Lines | 55 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 5 | ||
| 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  | 
            ||
| 47 | public function detect()  | 
            ||
| 48 |     { | 
            ||
| 49 | $aURL = [];  | 
            ||
| 50 | // Try to get the request URL  | 
            ||
| 51 | if(!empty($_SERVER['REQUEST_URI']))  | 
            ||
| 52 |         { | 
            ||
| 53 | $_SERVER['REQUEST_URI'] = str_replace(['"', "'", '<', '>'], ['%22', '%27', '%3C', '%3E'], $_SERVER['REQUEST_URI']);  | 
            ||
| 54 | $aURL = parse_url($_SERVER['REQUEST_URI']);  | 
            ||
| 55 | if(!is_array($aURL))  | 
            ||
| 56 |             { | 
            ||
| 57 | $aURL = [];  | 
            ||
| 58 | }  | 
            ||
| 59 | }  | 
            ||
| 60 | |||
| 61 | // Fill in the empty values  | 
            ||
| 62 | if(empty($aURL['scheme']))  | 
            ||
| 63 |         { | 
            ||
| 64 | if(!empty($_SERVER['HTTP_SCHEME']))  | 
            ||
| 65 |             { | 
            ||
| 66 | $aURL['scheme'] = $_SERVER['HTTP_SCHEME'];  | 
            ||
| 67 | }  | 
            ||
| 68 | else  | 
            ||
| 69 |             { | 
            ||
| 70 | $aURL['scheme'] = ((!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') ? 'https' : 'http');  | 
            ||
| 71 | }  | 
            ||
| 72 | }  | 
            ||
| 73 | |||
| 74 | $this->getHostFromServer($aURL, 'HTTP_X_FORWARDED_HOST');  | 
            ||
| 75 | $this->getHostFromServer($aURL, 'HTTP_HOST');  | 
            ||
| 76 | $this->getHostFromServer($aURL, 'SERVER_NAME');  | 
            ||
| 77 | if(empty($aURL['host']))  | 
            ||
| 78 |         { | 
            ||
| 79 | throw new \Jaxon\Exception\URI();  | 
            ||
| 80 | }  | 
            ||
| 81 | |||
| 82 | if(empty($aURL['port']) && !empty($_SERVER['SERVER_PORT']))  | 
            ||
| 83 |         { | 
            ||
| 84 | $aURL['port'] = $_SERVER['SERVER_PORT'];  | 
            ||
| 85 | }  | 
            ||
| 86 | |||
| 87 | if(!empty($aURL['path']) && strlen(basename($aURL['path'])) == 0)  | 
            ||
| 88 |         { | 
            ||
| 89 | unset($aURL['path']);  | 
            ||
| 90 | }  | 
            ||
| 91 | |||
| 92 | if(empty($aURL['path']))  | 
            ||
| 93 |         { | 
            ||
| 94 | if(!empty($_SERVER['PATH_INFO']))  | 
            ||
| 95 |             { | 
            ||
| 96 | $sPath = parse_url($_SERVER['PATH_INFO']);  | 
            ||
| 97 | }  | 
            ||
| 98 | else  | 
            ||
| 99 |             { | 
            ||
| 100 | $sPath = parse_url($_SERVER['PHP_SELF']);  | 
            ||
| 101 | }  | 
            ||
| 102 | if(isset($sPath['path']))  | 
            ||
| 103 |             { | 
            ||
| 104 | $aURL['path'] = str_replace(['"', "'", '<', '>'], ['%22', '%27', '%3C', '%3E'], $sPath['path']);  | 
            ||
| 105 | }  | 
            ||
| 106 | unset($sPath);  | 
            ||
| 107 | }  | 
            ||
| 108 | |||
| 109 | if(empty($aURL['query']))  | 
            ||
| 110 |         { | 
            ||
| 111 | $aURL['query'] = empty($_SERVER['QUERY_STRING']) ? '' : $_SERVER['QUERY_STRING'];  | 
            ||
| 112 | }  | 
            ||
| 113 | |||
| 114 | if(!empty($aURL['query']))  | 
            ||
| 115 |         { | 
            ||
| 116 | $aURL['query'] = '?' . $aURL['query'];  | 
            ||
| 117 | }  | 
            ||
| 118 | |||
| 119 | // Build the URL: Start with scheme, user and pass  | 
            ||
| 120 | $sURL = $aURL['scheme'] . '://';  | 
            ||
| 121 | if(!empty($aURL['user']))  | 
            ||
| 122 |         { | 
            ||
| 123 | $sURL .= $aURL['user'];  | 
            ||
| 124 | if(!empty($aURL['pass']))  | 
            ||
| 125 |             { | 
            ||
| 126 | $sURL .= ':' . $aURL['pass'];  | 
            ||
| 127 | }  | 
            ||
| 128 | $sURL .= '@';  | 
            ||
| 129 | }  | 
            ||
| 130 | |||
| 131 | // Add the host  | 
            ||
| 132 | $sURL .= $aURL['host'];  | 
            ||
| 133 | |||
| 134 | // Add the port if needed  | 
            ||
| 135 | if(!empty($aURL['port']) &&  | 
            ||
| 136 | (($aURL['scheme'] == 'http' && $aURL['port'] != 80) ||  | 
            ||
| 137 | ($aURL['scheme'] == 'https' && $aURL['port'] != 443)))  | 
            ||
| 138 |         { | 
            ||
| 139 | $sURL .= ':' . $aURL['port'];  | 
            ||
| 140 | }  | 
            ||
| 141 | |||
| 142 | // Add the path and the query string  | 
            ||
| 143 | $sURL .= $aURL['path'] . $aURL['query'];  | 
            ||
| 144 | |||
| 145 | // Clean up  | 
            ||
| 146 | unset($aURL);  | 
            ||
| 147 | |||
| 148 |         $aURL = explode("?", $sURL); | 
            ||
| 149 | |||
| 150 | if(1 < count($aURL))  | 
            ||
| 151 |         { | 
            ||
| 152 |             $aQueries = explode("&", $aURL[1]); | 
            ||
| 153 | |||
| 154 | foreach($aQueries as $sKey => $sQuery)  | 
            ||
| 155 |             { | 
            ||
| 156 |                 if("jxnGenerate" == substr($sQuery, 0, 11)) | 
            ||
| 157 |                 { | 
            ||
| 158 | unset($aQueries[$sKey]);  | 
            ||
| 159 | }  | 
            ||
| 160 | }  | 
            ||
| 161 | |||
| 162 |             $sQueries = implode("&", $aQueries); | 
            ||
| 163 | |||
| 164 | $aURL[1] = $sQueries;  | 
            ||
| 165 | |||
| 166 |             $sURL = implode("?", $aURL); | 
            ||
| 167 | }  | 
            ||
| 168 | |||
| 169 | return $sURL;  | 
            ||
| 170 | }  | 
            ||
| 172 |