Conditions | 9 |
Paths | 16 |
Total Lines | 57 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
59 | public function runActualTask($params = []): ?string |
||
60 | { |
||
61 | //replacement data patterns that will be searched for |
||
62 | |||
63 | if ($this->debug) { |
||
64 | $this->mu()->colourPrint($this->replacementArray); |
||
|
|||
65 | } |
||
66 | foreach ($this->mu()->getExistingModuleDirLocations() as $moduleDir) { |
||
67 | //Start search machine from the module location. replace API |
||
68 | $textSearchMachine = new SearchAndReplaceAPI($moduleDir); |
||
69 | $textSearchMachine->setIsReplacingEnabled(true); |
||
70 | $textSearchMachine->addToIgnoreFolderArray($this->ignoreFolderArray); |
||
71 | |||
72 | /*For all the different patterns listed in the replacement array |
||
73 | * iterate over them such that the $path would be 'src' and $patharray would be 'php' |
||
74 | * together making it ['src']['php'] |
||
75 | */ |
||
76 | foreach ($this->replacementArray as $path => $pathArray) { |
||
77 | $path = $moduleDir . '/' . $path ?: ''; |
||
78 | $path = $this->mu()->checkIfPathExistsAndCleanItUp($path); |
||
79 | if (! file_exists($path)) { |
||
80 | $this->mu()->colourPrint("SKIPPING ${path} as it does not exist."); |
||
81 | } else { |
||
82 | $textSearchMachine->setSearchPath($path); |
||
83 | foreach ($pathArray as $extension => $extensionArray) { |
||
84 | //setting extensions to search files within |
||
85 | $textSearchMachine->setExtensions(explode('|', $extension)); |
||
86 | foreach ($extensionArray as $find) { |
||
87 | $caseSensitive = false; |
||
88 | $replacementType = 'BASIC'; |
||
89 | |||
90 | // $this->mu()->colourPrint( |
||
91 | // "++++++++++++++++++++++++++++++++++++\n". |
||
92 | // "CHECKING\n". |
||
93 | // "IN $path\n". |
||
94 | // "FOR $extension FILES\n". |
||
95 | // "BASE ".$moduleDir."\n". |
||
96 | // "FIND '".$find."'\n". |
||
97 | // "REPLACE ''\n". |
||
98 | // "++++++++++++++++++++++++++++++++++++\n" |
||
99 | // ); |
||
100 | $textSearchMachine->setSearchKey($find, $caseSensitive, $replacementType); |
||
101 | $textSearchMachine->setReplacementKey(''); |
||
102 | $textSearchMachine->startSearchAndReplace(); |
||
103 | } |
||
104 | //SHOW TOTALS |
||
105 | $replacements = $textSearchMachine->showFormattedSearchTotals(); |
||
106 | if (! $replacements) { |
||
107 | //flush output anyway! |
||
108 | $this->mu()->colourPrint("No replacements for ${extension}"); |
||
109 | } |
||
110 | $this->mu()->colourPrint($textSearchMachine->getOutput()); |
||
111 | } |
||
112 | } |
||
113 | } |
||
114 | } |
||
115 | return null; |
||
116 | } |
||
123 |