Conditions | 10 |
Paths | 11 |
Total Lines | 40 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
57 | public function generateRelativeUrl($path) |
||
58 | { |
||
59 | if ($this->isNetworkPath($path) |
||
60 | || ! $this->hasLeadingSlash($path) |
||
61 | ) { |
||
62 | return $path; |
||
63 | } |
||
64 | |||
65 | $uri = $this->request->getUri(); |
||
66 | |||
67 | $basePath = $uri->getPath(); |
||
68 | if ($path === $basePath) { |
||
69 | return ''; |
||
70 | } |
||
71 | |||
72 | $baseParts = explode('/', $basePath, -1); |
||
73 | $pathParts = explode('/', $path); |
||
74 | |||
75 | foreach ($baseParts as $i => $segment) { |
||
76 | if (isset($pathParts[$i]) && $segment === $pathParts[$i]) { |
||
77 | unset($baseParts[$i], $pathParts[$i]); |
||
78 | } else { |
||
79 | break; |
||
80 | } |
||
81 | } |
||
82 | |||
83 | $path = str_repeat('../', count($baseParts)) . implode('/', $pathParts); |
||
84 | |||
85 | if (empty($path)) { |
||
86 | return './'; |
||
87 | } |
||
88 | |||
89 | if (empty($baseParts) |
||
90 | && false !== strpos(current($pathParts), ':') |
||
91 | ) { |
||
92 | $path = './' . $path; |
||
93 | } |
||
94 | |||
95 | return $path; |
||
96 | } |
||
97 | |||
117 |