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