Conditions | 19 |
Paths | 2073 |
Total Lines | 81 |
Code Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
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 |
||
115 | public function runActualTask($params = []) |
||
116 | { |
||
117 | |||
118 | //replacement data |
||
119 | $replacementDataObjects = $this->getReplacementDataObjects(); |
||
120 | foreach ($replacementDataObjects as $replacementDataObject) { |
||
121 | if ($this->checkReplacementIssues) { |
||
122 | $this->checkReplacementDataIssues($replacementDataObject); |
||
123 | } |
||
124 | |||
125 | $replacementArray = $replacementDataObject->getReplacementArrays(); |
||
126 | |||
127 | if ($this->debug) { |
||
128 | $this->mu()->colourPrint($replacementArray); |
||
|
|||
129 | } |
||
130 | |||
131 | //replace API |
||
132 | |||
133 | foreach ($this->mu()->getExistingModuleDirLocationsWithThemeFolders() as $moduleOrThemeDir) { |
||
134 | $textSearchMachine = new SearchAndReplaceAPI($moduleOrThemeDir); |
||
135 | $textSearchMachine->setIsReplacingEnabled(true); |
||
136 | $textSearchMachine->addToIgnoreFolderArray($this->ignoreFolderArray); |
||
137 | |||
138 | foreach ($replacementArray as $path => $pathArray) { |
||
139 | $path = $moduleOrThemeDir . '/' . $path ?: ''; |
||
140 | $path = $this->mu()->checkIfPathExistsAndCleanItUp($path); |
||
141 | if (! file_exists($path)) { |
||
142 | $this->mu()->colourPrint("SKIPPING ${path}"); |
||
143 | } else { |
||
144 | $textSearchMachine->setSearchPath($path); |
||
145 | foreach ($pathArray as $extension => $extensionArray) { |
||
146 | //setting extensions to search files within |
||
147 | $textSearchMachine->setExtensions(explode('|', $extension)); |
||
148 | $this->mu()->colourPrint( |
||
149 | "++++++++++++++++++++++++++++++++++++\n" . |
||
150 | "CHECKING\n" . |
||
151 | "IN ${path}\n" . |
||
152 | "FOR ${extension} FILES\n" . |
||
153 | 'BASE ' . $moduleOrThemeDir . "\n" . |
||
154 | "++++++++++++++++++++++++++++++++++++\n" |
||
155 | ); |
||
156 | foreach ($extensionArray as $find => $findDetails) { |
||
157 | $replace = isset($findDetails['R']) ? $findDetails['R'] : $find; |
||
158 | $comment = isset($findDetails['C']) ? $findDetails['C'] : ''; |
||
159 | $ignoreCase = isset($findDetails['I']) ? $findDetails['I'] : false; |
||
160 | $caseSensitive = ! $ignoreCase; |
||
161 | //$replace = $replaceArray[1]; unset($replaceArray[1]); |
||
162 | //$fullReplacement = |
||
163 | // (isset($replaceArray[2]) ? "/* ".$replaceArray[2]." */\n" : "").$replaceArray[1]; |
||
164 | $fullReplacement = $replace; |
||
165 | $isStraightReplace = true; |
||
166 | if ($comment) { |
||
167 | $isStraightReplace = false; |
||
168 | } |
||
169 | if (! $find) { |
||
170 | user_error("no find is specified, replace is: ${replace}"); |
||
171 | } |
||
172 | if (! $fullReplacement) { |
||
173 | user_error(' |
||
174 | No replace is specified, find is: ${find}. |
||
175 | We suggest setting your final replace to a single space if |
||
176 | you would like to replace with NOTHING. |
||
177 | '); |
||
178 | } |
||
179 | $replaceKey = $isStraightReplace ? 'BASIC' : 'COMPLEX'; |
||
180 | |||
181 | $textSearchMachine->setSearchKey($find, $caseSensitive, $replaceKey); |
||
182 | $textSearchMachine->setReplacementKey($fullReplacement); |
||
183 | if ($comment) { |
||
184 | $textSearchMachine->setComment($comment); |
||
185 | } |
||
186 | $textSearchMachine->setReplacementHeader($this->replacementHeader); |
||
187 | $textSearchMachine->startSearchAndReplace(); |
||
188 | } |
||
189 | $replacements = $textSearchMachine->showFormattedSearchTotals(); |
||
190 | if ($replacements) { |
||
191 | } else { |
||
192 | //flush output anyway! |
||
193 | $this->mu()->colourPrint("No replacements for ${extension}"); |
||
194 | } |
||
195 | $this->mu()->colourPrint($textSearchMachine->getOutput()); |
||
196 | } |
||
286 |