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