Conditions | 15 |
Paths | 168 |
Total Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
110 | protected function currentAbsoluteURL() { |
||
111 | global $url; |
||
112 | |||
113 | // Preserve BC - this has been moved from ParameterConfirmationToken |
||
114 | require_once(dirname(__FILE__).'/ParameterConfirmationToken.php'); |
||
115 | if (isset(ParameterConfirmationToken::$alternateBaseURL)) { |
||
116 | self::$alternateBaseURL = ParameterConfirmationToken::$alternateBaseURL; |
||
117 | } |
||
118 | |||
119 | // Are we http or https? Replicates Director::is_https() without its dependencies/ |
||
120 | $proto = 'http'; |
||
121 | // See https://en.wikipedia.org/wiki/List_of_HTTP_header_fields |
||
122 | // See https://support.microsoft.com/?kbID=307347 |
||
123 | $headerOverride = false; |
||
124 | if(TRUSTED_PROXY) { |
||
125 | $headers = (defined('SS_TRUSTED_PROXY_PROTOCOL_HEADER')) ? array(SS_TRUSTED_PROXY_PROTOCOL_HEADER) : null; |
||
126 | if(!$headers) { |
||
127 | // Backwards compatible defaults |
||
128 | $headers = array('HTTP_X_FORWARDED_PROTO', 'HTTP_X_FORWARDED_PROTOCOL', 'HTTP_FRONT_END_HTTPS'); |
||
129 | } |
||
130 | foreach($headers as $header) { |
||
131 | $headerCompareVal = ($header === 'HTTP_FRONT_END_HTTPS' ? 'on' : 'https'); |
||
132 | if(!empty($_SERVER[$header]) && strtolower($_SERVER[$header]) == $headerCompareVal) { |
||
133 | $headerOverride = true; |
||
134 | break; |
||
135 | } |
||
136 | } |
||
137 | } |
||
138 | |||
139 | if($headerOverride) { |
||
140 | $proto = 'https'; |
||
141 | } else if((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')) { |
||
142 | $proto = 'https'; |
||
143 | } else if(isset($_SERVER['SSL'])) { |
||
144 | $proto = 'https'; |
||
145 | } |
||
146 | |||
147 | $parts = array_filter(array( |
||
148 | // What's our host |
||
149 | $_SERVER['HTTP_HOST'], |
||
150 | // SilverStripe base |
||
151 | self::$alternateBaseURL !== null ? self::$alternateBaseURL : BASE_URL, |
||
152 | // And URL including base script (eg: if it's index.php/page/url/) |
||
153 | (defined('BASE_SCRIPT_URL') ? '/' . BASE_SCRIPT_URL : '') . $url, |
||
154 | )); |
||
155 | |||
156 | // Join together with protocol into our current absolute URL, avoiding duplicated "/" characters |
||
157 | return "$proto://" . preg_replace('#/{2,}#', '/', implode('/', $parts)); |
||
158 | } |
||
159 | |||
219 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.