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