| Conditions | 10 |
| Paths | 4 |
| Total Lines | 42 |
| Code Lines | 32 |
| 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 |
||
| 32 | public function runActualTask($params = []): ?string |
||
| 33 | { |
||
| 34 | foreach ($this->mu()->getExistingModuleDirLocations() as $moduleDir) { |
||
|
|
|||
| 35 | $fileFinder = new FindFiles(); |
||
| 36 | $searchPath = $this->mu()->findMyCodeDir($moduleDir); |
||
| 37 | if (file_exists($searchPath)) { |
||
| 38 | $flatArray = $fileFinder |
||
| 39 | ->setSearchPath($searchPath) |
||
| 40 | ->setExtensions(['php']) |
||
| 41 | ->getFlatFileArray(); |
||
| 42 | if (is_array($flatArray) && count($flatArray)) { |
||
| 43 | foreach ($flatArray as $path) { |
||
| 44 | $tableName = basename($path, '.php'); |
||
| 45 | $newLine = 'private static $table_name = \'' . $tableName . '\';'; |
||
| 46 | $filecontent = file_get_contents($path); |
||
| 47 | $hasNewLine = strpos($filecontent, 'private static $table_name'); |
||
| 48 | if (! $hasNewLine) { |
||
| 49 | $positionOfPrivateStatic = 0; |
||
| 50 | foreach ($this->listToSearchFor as $item) { |
||
| 51 | $positionOfPrivateStatic = strpos($filecontent, $item); |
||
| 52 | if ($positionOfPrivateStatic) { |
||
| 53 | break; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | if ($positionOfPrivateStatic) { |
||
| 57 | $this->mu()->colourPrint('Adding ' . $newLine . ' to ' . $path, 'green'); |
||
| 58 | $filecontent = |
||
| 59 | substr($filecontent, 0, $positionOfPrivateStatic) . |
||
| 60 | "\r\n" . "\r\n" . ' ' . $newLine . "\r\n" . "\r\n" . |
||
| 61 | substr($filecontent, $positionOfPrivateStatic); |
||
| 62 | file_put_contents($path, $filecontent); |
||
| 63 | } |
||
| 64 | } |
||
| 65 | } |
||
| 66 | } else { |
||
| 67 | $this->mu()->colourPrint('Could not find any files in ' . $searchPath, 'red'); |
||
| 68 | } |
||
| 69 | } else { |
||
| 70 | $this->mu()->colourPrint('Could not find ' . $searchPath, 'blue'); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | return null; |
||
| 74 | } |
||
| 81 |