| Conditions | 13 |
| Paths | 37 |
| Total Lines | 39 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 128 | private static function setBaseUrlUsingServerVar() { |
||
| 129 | $logger = self::getLogger(); |
||
| 130 | if (!isset(self::$config['base_url']) || !is_url(self::$config['base_url'])) { |
||
| 131 | if (ENVIRONMENT == 'production') { |
||
|
|
|||
| 132 | $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time'); |
||
| 133 | } |
||
| 134 | $baseUrl = null; |
||
| 135 | $protocol = 'http'; |
||
| 136 | if (is_https()) { |
||
| 137 | $protocol = 'https'; |
||
| 138 | } |
||
| 139 | $protocol .= '://'; |
||
| 140 | |||
| 141 | if (isset($_SERVER['SERVER_ADDR'])) { |
||
| 142 | $baseUrl = $_SERVER['SERVER_ADDR']; |
||
| 143 | //check if the server is running under IPv6 |
||
| 144 | if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) { |
||
| 145 | $baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']'; |
||
| 146 | } |
||
| 147 | $serverPort = 80; |
||
| 148 | if (isset($_SERVER['SERVER_PORT'])) { |
||
| 149 | $serverPort = $_SERVER['SERVER_PORT']; |
||
| 150 | } |
||
| 151 | $port = ''; |
||
| 152 | if ($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))) { |
||
| 153 | $port = ':' . $serverPort; |
||
| 154 | } |
||
| 155 | $baseUrl = $protocol . $baseUrl . $port . substr( |
||
| 156 | $_SERVER['SCRIPT_NAME'], |
||
| 157 | 0, |
||
| 158 | strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])) |
||
| 159 | ); |
||
| 160 | } else { |
||
| 161 | $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
||
| 162 | $baseUrl = 'http://localhost/'; |
||
| 163 | } |
||
| 164 | self::$config['base_url'] = $baseUrl; |
||
| 165 | } |
||
| 166 | self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/'; |
||
| 167 | } |
||
| 169 |