Conditions | 13 |
Paths | 8 |
Total Lines | 41 |
Code Lines | 31 |
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 |
||
23 | public function runActualTask($params = []) |
||
24 | { |
||
25 | foreach ($this->mu()->getExistingModuleDirLocations() as $moduleDir) { |
||
26 | $errors = []; |
||
27 | $searchPath = $this->mu()->findMyCodeDir($moduleDir); |
||
28 | if (file_exists($searchPath)) { |
||
29 | $this->mu()->colourPrint('Searching in ' . $searchPath, 'blue for files with more than one class.'); |
||
30 | $fileFinder = new FindFiles($searchPath); |
||
31 | $flatArray = $fileFinder |
||
32 | ->setSearchPath($searchPath) |
||
33 | ->setExtensions(['php']) |
||
34 | ->getFlatFileArray(); |
||
35 | if (is_array($flatArray) && count($flatArray)) { |
||
36 | foreach ($flatArray as $path) { |
||
37 | $className = basename($path, '.php'); |
||
|
|||
38 | $classNames = []; |
||
39 | $content = file_get_contents($path); |
||
40 | $tokens = token_get_all($content); |
||
41 | $namespace = ''; |
||
42 | for ($index = 0; isset($tokens[$index]); $index++) { |
||
43 | if (! isset($tokens[$index][0])) { |
||
44 | continue; |
||
45 | } |
||
46 | if ($tokens[$index][0] === T_CLASS && $tokens[$index + 1][0] === T_WHITESPACE && $tokens[$index + 2][0] === T_STRING) { |
||
47 | $index += 2; // Skip class keyword and whitespace |
||
48 | $classNames[] = $tokens[$index][1]; |
||
49 | } |
||
50 | } |
||
51 | if (count($classNames) > 1) { |
||
52 | $errors[] = $path . ': ' . implode(', ', $classNames); |
||
53 | } |
||
54 | } |
||
55 | } else { |
||
56 | $this->mu()->colourPrint('Could not find any files in ' . $searchPath, 'red'); |
||
57 | } |
||
58 | } else { |
||
59 | $this->mu()->colourPrint('Could not find ' . $searchPath, 'blue'); |
||
60 | } |
||
61 | } |
||
62 | if (count($errors)) { |
||
63 | return 'Found files with multiple classes: ' . implode("\n\n ---\n\n", $errors); |
||
64 | } |
||
72 |