Conditions | 11 |
Paths | 12 |
Total Lines | 19 |
Code Lines | 12 |
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 |
||
24 | function init($request) |
||
25 | { |
||
26 | $this->value = null; |
||
27 | $di = new DirectoryIterator(DEMO_PATH . $this->path); |
||
28 | foreach ($di as $file) |
||
29 | if (!$file->isDot() && strpos($file->getFilename(), '.') !== 0 && preg_match($this->options['pattern'], $file->getFilename())) |
||
30 | { |
||
31 | $this->files[] = $file->getFilename(); |
||
32 | if ($this->value === null && isset($this->options['default']) && $this->options['default'] == $file->getFilename()) |
||
33 | $this->value = $this->options['default']; |
||
34 | |||
35 | if ($this->request->get($this->name) == $file->getFilename()) |
||
36 | $this->value = $file->getFilename(); |
||
37 | } |
||
38 | |||
39 | sort($this->files); |
||
40 | |||
41 | if (!$this->value && count($this->files) > 0) |
||
42 | $this->value = $this->files[0]; |
||
43 | } |
||
84 |