| Conditions | 10 |
| Paths | 8 |
| Total Lines | 27 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 40 | protected function buildData($rebuild) |
||
| 41 | { |
||
| 42 | if ($rebuild === true || empty($this->data)) { |
||
| 43 | $allFiles = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->path)); |
||
| 44 | $phpFiles = new RegexIterator($allFiles, '/\.php$/'); |
||
| 45 | foreach ($phpFiles as $phpFile) { |
||
| 46 | $content = file_get_contents($phpFile->getRealPath()); |
||
| 47 | $tokens = token_get_all($content); |
||
| 48 | $namespace = ''; |
||
| 49 | for ($index = 0; isset($tokens[$index]); $index++) { |
||
| 50 | if (!isset($tokens[$index][0])) { |
||
| 51 | continue; |
||
| 52 | } |
||
| 53 | if (T_NAMESPACE === $tokens[$index][0]) { |
||
| 54 | $index += 2; // Skip namespace keyword and whitespace |
||
| 55 | while (isset($tokens[$index]) && is_array($tokens[$index])) { |
||
| 56 | $namespace .= $tokens[$index++][1]; |
||
| 57 | } |
||
| 58 | } |
||
| 59 | if (T_CLASS === $tokens[$index][0]) { |
||
| 60 | $index += 2; // Skip class keyword and whitespace |
||
| 61 | $this->data[] = $namespace . '\\' . $tokens[$index][1]; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | } |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 78 | } |