| 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 |
||
| 83 | public function findNewURL($varname = 'ecomlocale', $newCountryCode) |
||
| 84 | { |
||
| 85 | |||
| 86 | //COPIED FROM DIRECTOR::redirectBack() |
||
| 87 | // Don't cache the redirect back ever |
||
| 88 | HTTP::set_cache_age(0); |
||
| 89 | |||
| 90 | $url = null; |
||
| 91 | |||
| 92 | // In edge-cases, this will be called outside of a handleRequest() context; in that case, |
||
| 93 | // redirect to the homepage - don't break into the global state at this stage because we'll |
||
| 94 | // be calling from a test context or something else where the global state is inappropraite |
||
| 95 | if ($this->getRequest()) { |
||
| 96 | if ($this->getRequest()->requestVar('BackURL')) { |
||
| 97 | $url = $this->getRequest()->requestVar('BackURL'); |
||
| 98 | } elseif ($this->getRequest()->isAjax() && $this->getRequest()->getHeader('X-Backurl')) { |
||
| 99 | $url = $this->getRequest()->getHeader('X-Backurl'); |
||
| 100 | } elseif ($this->getRequest()->getHeader('Referer')) { |
||
| 101 | $url = $this->getRequest()->getHeader('Referer'); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | if (!$url) { |
||
| 106 | $url = Director::baseURL(); |
||
| 107 | } |
||
| 108 | // absolute redirection URLs not located on this site may cause phishing |
||
| 109 | if (Director::is_site_url($url)) { |
||
| 110 | $url = Director::absoluteURL($url, true); |
||
| 111 | $parsedUrl = parse_url($url); |
||
| 112 | $query = array(); |
||
| 113 | |||
| 114 | if (isset($parsedUrl['query'])) { |
||
| 115 | parse_str($parsedUrl['query'], $query); |
||
| 116 | if ($query[$varname] !== $newCountryCode) { |
||
| 117 | unset($query[$varname]); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | $path = isset($parsedUrl['path']) ? $parsedUrl['path'] : ''; |
||
| 122 | |||
| 123 | $query = !empty($query) ? '?'. http_build_query($query) : ''; |
||
| 124 | |||
| 125 | $hasCountrySegment = CountryPrice_Translation::get_country_url_provider()->hasCountrySegment($url); |
||
| 126 | if($hasCountrySegment){ |
||
| 127 | $url = CountryPrice_Translation::get_country_url_provider()->replaceCountryCodeInUrl($newCountryCode, $url); |
||
| 128 | } |
||
| 129 | else { |
||
| 130 | $url = CountryPrice_Translation::get_country_url_provider()->addCountryCodeToUrl($newCountryCode, $url); |
||
| 131 | } |
||
| 132 | return $url.$query; |
||
| 133 | } |
||
| 134 | return '/'; |
||
| 135 | } |
||
| 136 | |||
| 141 |
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.