Conditions | 13 |
Paths | 250 |
Total Lines | 53 |
Code Lines | 29 |
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 |
||
112 | public function findNewURL($varname = 'ecomlocale', $newCountryCode) |
||
113 | { |
||
114 | |||
115 | //COPIED FROM DIRECTOR::redirectBack() |
||
116 | // Don't cache the redirect back ever |
||
117 | HTTP::set_cache_age(0); |
||
118 | |||
119 | $url = null; |
||
120 | |||
121 | // In edge-cases, this will be called outside of a handleRequest() context; in that case, |
||
122 | // redirect to the homepage - don't break into the global state at this stage because we'll |
||
123 | // be calling from a test context or something else where the global state is inappropraite |
||
124 | if ($this->getRequest()) { |
||
125 | if ($this->getRequest()->requestVar('BackURL')) { |
||
126 | $url = $this->getRequest()->requestVar('BackURL'); |
||
127 | } elseif ($this->getRequest()->isAjax() && $this->getRequest()->getHeader('X-Backurl')) { |
||
128 | $url = $this->getRequest()->getHeader('X-Backurl'); |
||
129 | } elseif ($this->getRequest()->getHeader('Referer')) { |
||
130 | $url = $this->getRequest()->getHeader('Referer'); |
||
131 | } |
||
132 | } |
||
133 | |||
134 | if (!$url) { |
||
135 | $url = Director::baseURL(); |
||
136 | } |
||
137 | // absolute redirection URLs not located on this site may cause phishing |
||
138 | if (Director::is_site_url($url)) { |
||
139 | $url = Director::absoluteURL($url, true); |
||
140 | $parsedUrl = parse_url($url); |
||
141 | $query = array(); |
||
142 | |||
143 | if (isset($parsedUrl['query'])) { |
||
144 | parse_str($parsedUrl['query'], $query); |
||
145 | if ($query[$varname] !== $newCountryCode) { |
||
146 | unset($query[$varname]); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | $path = isset($parsedUrl['path']) ? $parsedUrl['path'] : ''; |
||
151 | |||
152 | $query = !empty($query) ? '?'. http_build_query($query) : ''; |
||
153 | |||
154 | $hasCountrySegment = CountryPrice_Translation::get_country_url_provider()->hasCountrySegment($url); |
||
155 | if($hasCountrySegment){ |
||
156 | $url = CountryPrice_Translation::get_country_url_provider()->replaceCountryCodeInUrl($newCountryCode, $url); |
||
157 | } |
||
158 | else { |
||
159 | $url = CountryPrice_Translation::get_country_url_provider()->addCountryCodeToUrl($newCountryCode, $url); |
||
160 | } |
||
161 | return $url.$query; |
||
162 | } |
||
163 | return '/'; |
||
164 | } |
||
165 | |||
170 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.