Conditions | 17 |
Paths | 60 |
Total Lines | 91 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 createUrl($value = null, $options = null) |
||
84 | { |
||
85 | $base = ''; |
||
86 | |||
87 | // handles options |
||
88 | $canonical = null; |
||
89 | $addhash = false; |
||
90 | $format = null; |
||
91 | extract(is_array($options) ? $options : [], EXTR_IF_EXISTS); |
||
92 | |||
93 | // canonicalurl? |
||
94 | if ((bool) $this->config->get('canonicalurl') || $canonical === true) { |
||
95 | $base = rtrim($this->baseurl, '/'); |
||
96 | } |
||
97 | if ($canonical === false) { |
||
98 | $base = ''; |
||
99 | } |
||
100 | |||
101 | // value is empty: url() |
||
102 | if (empty($value) || $value == '/') { |
||
103 | return $base.'/'; |
||
104 | } |
||
105 | |||
106 | // value is a Page item |
||
107 | if ($value instanceof Page) { |
||
108 | if (!$format) { |
||
109 | $format = $value->getVariable('output'); |
||
110 | if (is_array($value->getVariable('output'))) { |
||
111 | $format = $value->getVariable('output')[0]; |
||
112 | } |
||
113 | if (!$format) { |
||
114 | $format = 'html'; |
||
115 | } |
||
116 | } |
||
117 | $url = $value->getUrl($format, $this->config); |
||
118 | $url = $base.'/'.ltrim($url, '/'); |
||
119 | |||
120 | return $url; |
||
121 | } |
||
122 | |||
123 | // value is an Asset object |
||
124 | if ($value instanceof Asset) { |
||
125 | $asset = $value; |
||
126 | $url = $asset['path']; |
||
127 | if ($addhash) { |
||
128 | $url .= '?'.$this->version; |
||
129 | } |
||
130 | $url = $base.'/'.ltrim($url, '/'); |
||
131 | $asset['path'] = $url; |
||
132 | |||
133 | return $asset; |
||
134 | } |
||
135 | |||
136 | // value is an external URL |
||
137 | if (Util::isExternalUrl($value)) { |
||
138 | $url = $value; |
||
139 | |||
140 | return $url; |
||
141 | } |
||
142 | |||
143 | // value is a string |
||
144 | $value = Util::joinPath($value); |
||
145 | |||
146 | // DEBUG |
||
147 | dump($value); |
||
148 | dump(strrpos($value, '.')); |
||
149 | |||
150 | // value is (certainly) a path to a ressource (ie: 'path/file.pdf') |
||
151 | if (false !== strpos($value, '.')) { |
||
152 | $url = $value; |
||
153 | if ($addhash) { |
||
154 | $url .= '?'.$this->version; |
||
155 | } |
||
156 | $url = $base.'/'.ltrim($url, '/'); |
||
157 | |||
158 | return $url; |
||
159 | } |
||
160 | |||
161 | // others cases |
||
162 | $url = $base.'/'.$value; |
||
163 | |||
164 | // value is a page ID (ie: 'path/my-page') |
||
165 | try { |
||
166 | $pageId = self::$slugifier->slugify($value); |
||
167 | $page = $this->builder->getPages()->get($pageId); |
||
168 | $url = $this->createUrl($page, $options); |
||
169 | } catch (\DomainException $e) { |
||
170 | // nothing to do |
||
171 | } |
||
172 | |||
173 | return $url; |
||
174 | } |
||
193 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.