| Conditions | 14 |
| Paths | 253 |
| Total Lines | 81 |
| Code Lines | 48 |
| Lines | 11 |
| Ratio | 13.58 % |
| Changes | 1 | ||
| 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 |
||
| 181 | public function handleFile($basename, $pathname, $depth) |
||
| 182 | { |
||
| 183 | $projectFile = false; |
||
| 184 | $theme = null; |
||
| 185 | |||
| 186 | // Template in theme |
||
| 187 | if (preg_match( |
||
| 188 | '#'.preg_quote($this->base.'/'.THEMES_DIR).'/([^/_]+)(_[^/]+)?/(.*)$#', |
||
| 189 | $pathname, |
||
| 190 | $matches |
||
| 191 | )) { |
||
| 192 | $theme = $matches[1]; |
||
| 193 | $relPath = $matches[3]; |
||
| 194 | |||
| 195 | // Template in project |
||
| 196 | } elseif (preg_match( |
||
| 197 | '#'.preg_quote($this->base.'/'.$this->project).'/(.*)$#', |
||
| 198 | $pathname, |
||
| 199 | $matches |
||
| 200 | )) { |
||
| 201 | $projectFile = true; |
||
| 202 | $relPath = $matches[1]; |
||
| 203 | |||
| 204 | // Template in module |
||
| 205 | View Code Duplication | } elseif (preg_match( |
|
| 206 | '#'.preg_quote($this->base).'/([^/]+)/(.*)$#', |
||
| 207 | $pathname, |
||
| 208 | $matches |
||
| 209 | )) { |
||
| 210 | $relPath = $matches[2]; |
||
| 211 | |||
| 212 | } else { |
||
| 213 | throw new \LogicException("Can't determine meaning of path: $pathname"); |
||
| 214 | } |
||
| 215 | |||
| 216 | // If a templates subfolder is used, ignore that |
||
| 217 | View Code Duplication | if (preg_match('#'.preg_quote(self::TEMPLATES_DIR).'/(.*)$#', $relPath, $matches)) { |
|
| 218 | $relPath = $matches[1]; |
||
| 219 | } |
||
| 220 | |||
| 221 | // Layout and Content folders have special meaning |
||
| 222 | if (preg_match('#^(.*/)?(Layout|Content|Includes)/([^/]+)$#', $relPath, $matches)) { |
||
| 223 | $type = $matches[2]; |
||
| 224 | $relPath = "$matches[1]$matches[3]"; |
||
| 225 | } else { |
||
| 226 | $type = "main"; |
||
| 227 | } |
||
| 228 | |||
| 229 | $name = strtolower(substr($relPath, 0, -3)); |
||
| 230 | $name = str_replace('/', '\\', $name); |
||
| 231 | |||
| 232 | if ($theme) { |
||
| 233 | $this->templates[$name]['themes'][$theme][$type] = $pathname; |
||
| 234 | } else if ($projectFile) { |
||
| 235 | $this->templates[$name][$this->project][$type] = $pathname; |
||
| 236 | } else { |
||
| 237 | $this->templates[$name][$type] = $pathname; |
||
| 238 | } |
||
| 239 | |||
| 240 | // If we've found a template in a subdirectory, then allow its use for a non-namespaced class |
||
| 241 | // as well. This was a common SilverStripe 3 approach, where templates were placed into |
||
| 242 | // subfolders to suit the whim of the developer. |
||
| 243 | if (strpos($name, '\\') !== false) { |
||
| 244 | $name2 = substr($name, strrpos($name, '\\') + 1); |
||
| 245 | // In of these cases, the template will only be provided if it isn't already set. This |
||
| 246 | // matches SilverStripe 3 prioritisation. |
||
| 247 | if ($theme) { |
||
| 248 | if (!isset($this->templates[$name2]['themes'][$theme][$type])) { |
||
| 249 | $this->templates[$name2]['themes'][$theme][$type] = $pathname; |
||
| 250 | } |
||
| 251 | } else if ($projectFile) { |
||
| 252 | if (!isset($this->templates[$name2][$this->project][$type])) { |
||
| 253 | $this->templates[$name2][$this->project][$type] = $pathname; |
||
| 254 | } |
||
| 255 | } else { |
||
| 256 | if (!isset($this->templates[$name2][$type])) { |
||
| 257 | $this->templates[$name2][$type] = $pathname; |
||
| 258 | } |
||
| 259 | } |
||
| 260 | } |
||
| 261 | } |
||
| 262 | |||
| 272 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: