Conditions | 5 |
Paths | 6 |
Total Lines | 54 |
Code Lines | 39 |
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 |
||
62 | public function runActualTask($params = []): ?string |
||
63 | { |
||
64 | foreach ($this->mu()->getExistingModuleDirLocations() as $moduleDir) { |
||
|
|||
65 | $moduleDir = $this->mu()->findMyCodeDir($moduleDir); |
||
66 | //Start search machine from the module location. replace API |
||
67 | $textSearchMachine = new SearchAndReplaceAPI($moduleDir); |
||
68 | $textSearchMachine->setIsReplacingEnabled(true); |
||
69 | $textSearchMachine->setFileReplacementMaxCount(1); |
||
70 | $textSearchMachine->setIgnoreFileIfFound(['private static $table_name']); |
||
71 | $textSearchMachine->addToIgnoreFolderArray($this->ignoreFolderArray); |
||
72 | $this->mu()->colourPrint("Checking ${moduleDir}"); |
||
73 | $moduleDir = $this->mu()->checkIfPathExistsAndCleanItUp($moduleDir); |
||
74 | if (! file_exists($moduleDir)) { |
||
75 | $this->mu()->colourPrint("SKIPPING ${moduleDir} as it does not exist."); |
||
76 | } else { |
||
77 | $textSearchMachine->setSearchPath($moduleDir); |
||
78 | $textSearchMachine->setExtensions($this->extensionArray); //setting extensions to search files within |
||
79 | $this->mu()->colourPrint( |
||
80 | "++++++++++++++++++++++++++++++++++++\n" . |
||
81 | "CHECKING\n" . |
||
82 | "IN ${moduleDir}\n" . |
||
83 | 'FOR ' . implode(',', $this->extensionArray) . " FILES\n" . |
||
84 | 'BASE ' . $moduleDir . "\n" . |
||
85 | "++++++++++++++++++++++++++++++++++++\n" |
||
86 | ); |
||
87 | foreach ($this->findArray as $finalFind) { |
||
88 | $caseSensitive = true; |
||
89 | $replacementType = 'COMPLEX'; |
||
90 | $comment = 'Check that is class indeed extends DataObject and that it is not a data-extension!'; |
||
91 | $finalReplace = ' |
||
92 | private static $table_name = \'[SEARCH_REPLACE_CLASS_NAME_GOES_HERE]\'; |
||
93 | |||
94 | ' . $finalFind; |
||
95 | $this->mu()->colourPrint( |
||
96 | ' --- FIND: ' . $finalFind . "\n" . |
||
97 | ' --- REPLACE: ' . $finalReplace . "\n" |
||
98 | ); |
||
99 | |||
100 | $textSearchMachine->setSearchKey($finalFind, $caseSensitive, $replacementType); |
||
101 | $textSearchMachine->setReplacementKey($finalReplace); |
||
102 | $textSearchMachine->setComment($comment); |
||
103 | $textSearchMachine->startSearchAndReplace(); |
||
104 | } |
||
105 | |||
106 | //SHOW TOTALS |
||
107 | $replacements = $textSearchMachine->showFormattedSearchTotals(); |
||
108 | if (! $replacements) { |
||
109 | //flush output anyway! |
||
110 | $this->mu()->colourPrint('No replacements for ' . implode(',', $this->extensionArray)); |
||
111 | } |
||
112 | $this->mu()->colourPrint($textSearchMachine->getOutput()); |
||
113 | } |
||
114 | } |
||
115 | return null; |
||
116 | } |
||
123 |