| Conditions | 16 |
| Paths | 12 |
| Total Lines | 55 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 28 | public function runActualTask($params = []) |
||
| 29 | { |
||
| 30 | $errors = []; |
||
| 31 | foreach ($this->mu()->getExistingModuleDirLocations() as $moduleDir) { |
||
| 32 | $this->mu()->colourPrint('Searching ' . $moduleDir, 'grey'); |
||
| 33 | $fileFinder = new FindFiles($moduleDir); |
||
| 34 | $searchPath = $this->mu()->findMyCodeDir($moduleDir); |
||
| 35 | if (file_exists($searchPath)) { |
||
| 36 | $flatArray = $fileFinder |
||
| 37 | ->setSearchPath($searchPath) |
||
| 38 | ->setExtensions(['php']) |
||
| 39 | ->getFlatFileArray(); |
||
| 40 | if (is_array($flatArray) && count($flatArray)) { |
||
| 41 | foreach ($flatArray as $path) { |
||
| 42 | $this->mu()->colourPrint('Searching ' . $path, 'grey'); |
||
| 43 | $className = basename($path, '.php'); |
||
|
|
|||
| 44 | $classNames = []; |
||
| 45 | $content = file_get_contents($path); |
||
| 46 | $tokens = token_get_all($content); |
||
| 47 | $namespace = ''; |
||
| 48 | for ($index = 0; isset($tokens[$index]); $index++) { |
||
| 49 | if (! isset($tokens[$index][0])) { |
||
| 50 | continue; |
||
| 51 | } |
||
| 52 | if ($tokens[$index][0] === T_USE && |
||
| 53 | $tokens[$index + 1][0] === T_WHITESPACE && |
||
| 54 | $tokens[$index + 2][0] === T_STRING && |
||
| 55 | $tokens[$index + 3] === ';' |
||
| 56 | ) { |
||
| 57 | $string = $tokens[$index + 2][1]; |
||
| 58 | if (! in_array($string, $this->listOfOKOnes, true)) { |
||
| 59 | $testPhrase = ltrim($string, '\\'); |
||
| 60 | if (! strpos($testPhrase, '\\')) { |
||
| 61 | $errors[] = $path . ': ' . $tokens[$index][1] . $tokens[$index + 1][1] . $tokens[$index + 2][1] . ';'; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | $index += 3; // Skip checked ones ... |
||
| 65 | } |
||
| 66 | } |
||
| 67 | } |
||
| 68 | } else { |
||
| 69 | $this->mu()->colourPrint('Could not find any files in ' . $searchPath, 'red'); |
||
| 70 | } |
||
| 71 | } else { |
||
| 72 | $this->mu()->colourPrint('Could not find ' . $searchPath, 'blue'); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | if (count($errors)) { |
||
| 76 | $error = 'Found errors in use statements: ' . "\n---\n---\n---\n" . implode("\n ---\n", $errors); |
||
| 77 | if (count($errors) > 10) { |
||
| 78 | return $error; |
||
| 79 | } |
||
| 80 | $this->mu()->colourPrint($error, 'red'); |
||
| 81 | } else { |
||
| 82 | $this->mu()->colourPrint('Clean bill of health in terms of use statements.', 'green'); |
||
| 83 | } |
||
| 105 |