| Conditions | 21 |
| Paths | 240 |
| Total Lines | 39 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 91 | public function generateUri($referenceScheme, $referenceHost, $referencePort, $forceCanonical) |
||
| 92 | { |
||
| 93 | $url = ''; |
||
| 94 | $scheme = $referenceScheme; |
||
| 95 | $port = $this->port; |
||
| 96 | |||
| 97 | if ($forceCanonical || $this->scheme !== null && $referenceScheme !== $this->scheme) { |
||
| 98 | $url .= ($scheme = $this->scheme ?: $referenceScheme) . ':'; |
||
| 99 | $forceCanonical = true; |
||
| 100 | } |
||
| 101 | |||
| 102 | if (null === $this->port) { |
||
| 103 | if ($scheme === $referenceScheme && (null === $this->host || $this->host === $referenceHost)) { |
||
| 104 | $port = $referencePort; |
||
| 105 | } else { |
||
| 106 | $port = 'http' === $scheme ? 80 : 443; |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | if ($forceCanonical || $this->host !== null && $referenceHost !== $this->host || $port !== $referencePort) { |
||
| 111 | $url .= '//' . ($this->host ?: $referenceHost); |
||
| 112 | |||
| 113 | if ('http' === $scheme && 80 !== $port || 'https' === $scheme && 443 !== $port) { |
||
| 114 | $url .= ':' . $port; |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | $url .= strtr(rawurlencode($this->path), static::$allowedPathChars); |
||
| 119 | |||
| 120 | if ($this->query !== null) { |
||
| 121 | $url .= '?' . http_build_query($this->query, '', '&'); |
||
| 122 | } |
||
| 123 | |||
| 124 | if ($this->fragment !== null) { |
||
| 125 | $url .= '#' . $this->fragment; |
||
| 126 | } |
||
| 127 | |||
| 128 | return $url; |
||
| 129 | } |
||
| 130 | } |
||
| 131 |