Conditions | 11 |
Paths | 2 |
Total Lines | 37 |
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 |
||
33 | public function find($needle = null, $rebuild = FALSE) |
||
34 | { |
||
35 | if($rebuild === TRUE || empty($this->data)) |
||
36 | { |
||
37 | $allFiles = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->path)); |
||
38 | $phpFiles = new RegexIterator($allFiles, '/\.php$/'); |
||
39 | foreach ($phpFiles as $phpFile) { |
||
40 | $content = file_get_contents($phpFile->getRealPath()); |
||
41 | $tokens = token_get_all($content); |
||
42 | $namespace = ''; |
||
43 | for ($index = 0; isset($tokens[$index]); $index++) { |
||
44 | if (!isset($tokens[$index][0])) { |
||
45 | continue; |
||
46 | |||
47 | } |
||
48 | if (T_NAMESPACE === $tokens[$index][0]) { |
||
49 | $index += 2; // Skip namespace keyword and whitespace |
||
50 | while (isset($tokens[$index]) && is_array($tokens[$index])) { |
||
51 | $namespace .= $tokens[$index++][1]; |
||
52 | } |
||
53 | } |
||
54 | if (T_CLASS === $tokens[$index][0]) { |
||
55 | $index += 2; // Skip class keyword and whitespace |
||
56 | $this->data[] = $namespace.'\\'.$tokens[$index][1]; |
||
57 | } |
||
58 | } |
||
59 | } |
||
60 | } |
||
61 | |||
62 | return array_values(array_filter($this->data, function ($var) use ($needle) { |
||
63 | if (strpos($var, $needle) !== false) { |
||
64 | return TRUE; |
||
65 | } |
||
66 | return FALSE; |
||
67 | })); |
||
68 | |||
69 | } |
||
70 | |||
72 | } |