Conditions | 14 |
Paths | 330 |
Total Lines | 66 |
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 |
||
124 | public function findNewURL($newCountryCode) |
||
125 | { |
||
126 | |||
127 | //COPIED FROM DIRECTOR::redirectBack() |
||
128 | // Don't cache the redirect back ever |
||
129 | HTTP::set_cache_age(0); |
||
130 | |||
131 | $url = null; |
||
132 | |||
133 | // In edge-cases, this will be called outside of a handleRequest() context; in that case, |
||
134 | // redirect to the homepage - don't break into the global state at this stage because we'll |
||
135 | // be calling from a test context or something else where the global state is inappropraite |
||
136 | if ($this->getRequest()) { |
||
137 | if ($this->getRequest()->requestVar('BackURL')) { |
||
138 | $url = $this->getRequest()->requestVar('BackURL'); |
||
139 | } elseif ($this->getRequest()->isAjax() && $this->getRequest()->getHeader('X-Backurl')) { |
||
140 | $url = $this->getRequest()->getHeader('X-Backurl'); |
||
141 | } elseif ($this->getRequest()->getHeader('Referer')) { |
||
142 | $url = $this->getRequest()->getHeader('Referer'); |
||
143 | } |
||
144 | } |
||
145 | |||
146 | if (!$url) { |
||
147 | $url = Director::baseURL(); |
||
148 | } |
||
149 | |||
150 | // absolute redirection URLs not located on this site may cause phishing |
||
151 | if (Director::is_site_url($url)) { |
||
152 | $oldURL = Director::absoluteURL($url, true); |
||
153 | $parsedUrl = parse_url($oldURL); |
||
154 | $query = array(); |
||
155 | |||
156 | if (isset($parsedUrl['query'])) { |
||
157 | $varname = $this->Config()->get('locale_get_parameter'); |
||
158 | parse_str($parsedUrl['query'], $query); |
||
159 | if (isset($query[$varname])) { |
||
160 | if ($query[$varname] !== $newCountryCode) { |
||
161 | unset($query[$varname]); |
||
162 | } |
||
163 | } |
||
164 | } |
||
165 | |||
166 | $path = isset($parsedUrl['path']) ? $parsedUrl['path'] : ''; |
||
167 | |||
168 | $query = empty($query) ? '' : '?'. http_build_query($query); |
||
169 | $newURL = |
||
170 | $parsedUrl['scheme'] . |
||
171 | '://' . |
||
172 | Controller::join_links( |
||
173 | $parsedUrl['host'], |
||
174 | $parsedUrl['path'] |
||
175 | ). |
||
176 | $query; |
||
177 | $newURLwithNewCountryCode = CountryPrice_Translation::get_country_url_provider() |
||
178 | ->replaceCountryCodeInUrl( |
||
179 | $newCountryCode, |
||
180 | $newURL |
||
181 | ); |
||
182 | if ($newURLwithNewCountryCode) { |
||
183 | return $newURLwithNewCountryCode; |
||
184 | } else { |
||
185 | return $newURL; |
||
186 | } |
||
187 | } |
||
188 | return '/'; |
||
189 | } |
||
190 | |||
195 |