| Conditions | 18 |
| Paths | 2072 |
| Total Lines | 76 |
| Code Lines | 54 |
| 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 |
||
| 65 | public function runActualTask($params = []) |
||
| 66 | { |
||
| 67 | if ($this->checkReplacementIssues) { |
||
| 68 | $this->checkReplacementDataIssues(); |
||
| 69 | } |
||
| 70 | |||
| 71 | //replacement data |
||
| 72 | $replacementDataObject = new LoadReplacementData( |
||
| 73 | $this->mu(), |
||
| 74 | $this->alternativePathForReplacementData, |
||
| 75 | $this->params |
||
| 76 | ); |
||
| 77 | $replacementArray = $replacementDataObject->getReplacementArrays(); |
||
| 78 | |||
| 79 | if ($this->debug) { |
||
| 80 | $this->mu()->colourPrint(print_r($replacementArray, 1)); |
||
| 81 | } |
||
| 82 | |||
| 83 | //replace API |
||
| 84 | foreach ($this->mu()->getExistingModuleDirLocationsWithThemeFolders() as $moduleOrThemeDir) { |
||
| 85 | $textSearchMachine = new SearchAndReplaceAPI($moduleOrThemeDir); |
||
| 86 | $textSearchMachine->setIsReplacingEnabled(true); |
||
| 87 | $textSearchMachine->addToIgnoreFolderArray($this->ignoreFolderArray); |
||
| 88 | |||
| 89 | foreach ($replacementArray as $path => $pathArray) { |
||
| 90 | $path = $moduleOrThemeDir . '/' . $path ?: ''; |
||
| 91 | $path = $this->mu()->checkIfPathExistsAndCleanItUp($path); |
||
| 92 | if (! file_exists($path)) { |
||
| 93 | $this->mu()->colourPrint("SKIPPING ${path}"); |
||
| 94 | } else { |
||
| 95 | $textSearchMachine->setSearchPath($path); |
||
| 96 | foreach ($pathArray as $extension => $extensionArray) { |
||
| 97 | $textSearchMachine->setExtensions(explode('|', $extension)); //setting extensions to search files within |
||
| 98 | $this->mu()->colourPrint( |
||
| 99 | "++++++++++++++++++++++++++++++++++++\n" . |
||
| 100 | "CHECKING\n" . |
||
| 101 | "IN ${path}\n" . |
||
| 102 | "FOR ${extension} FILES\n" . |
||
| 103 | 'BASE ' . $moduleOrThemeDir . "\n" . |
||
| 104 | "++++++++++++++++++++++++++++++++++++\n" |
||
| 105 | ); |
||
| 106 | foreach ($extensionArray as $find => $findDetails) { |
||
| 107 | $replace = isset($findDetails['R']) ? $findDetails['R'] : $find; |
||
| 108 | $comment = isset($findDetails['C']) ? $findDetails['C'] : ''; |
||
| 109 | $ignoreCase = isset($findDetails['I']) ? $findDetails['I'] : false; |
||
| 110 | $caseSensitive = ! $ignoreCase; |
||
| 111 | //$replace = $replaceArray[1]; unset($replaceArray[1]); |
||
| 112 | //$fullReplacement = (isset($replaceArray[2]) ? "/* ".$replaceArray[2]." */\n" : "").$replaceArray[1]; |
||
| 113 | $fullReplacement = $replace; |
||
| 114 | $isStraightReplace = true; |
||
| 115 | if ($comment) { |
||
| 116 | $isStraightReplace = false; |
||
| 117 | } |
||
| 118 | if (! $find) { |
||
| 119 | user_error("no find is specified, replace is: ${replace}"); |
||
| 120 | } |
||
| 121 | if (! $fullReplacement) { |
||
| 122 | user_error("no replace is specified, find is: ${find}. We suggest setting your final replace to a single space if you would like to replace with NOTHING."); |
||
| 123 | } |
||
| 124 | $replaceKey = $isStraightReplace ? 'BASIC' : 'COMPLEX'; |
||
| 125 | |||
| 126 | $textSearchMachine->setSearchKey($find, $caseSensitive, $replaceKey); |
||
| 127 | $textSearchMachine->setReplacementKey($fullReplacement); |
||
| 128 | if ($comment) { |
||
| 129 | $textSearchMachine->setComment($comment); |
||
| 130 | } |
||
| 131 | $textSearchMachine->setReplacementHeader($this->replacementHeader); |
||
| 132 | $textSearchMachine->startSearchAndReplace(); |
||
| 133 | } |
||
| 134 | $replacements = $textSearchMachine->showFormattedSearchTotals(); |
||
| 135 | if ($replacements) { |
||
| 136 | } else { |
||
| 137 | //flush output anyway! |
||
| 138 | $this->mu()->colourPrint("No replacements for ${extension}"); |
||
| 139 | } |
||
| 140 | $this->mu()->colourPrint($textSearchMachine->getOutput()); |
||
| 141 | } |
||
| 221 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.