| Conditions | 13 | 
| Paths | 40 | 
| Total Lines | 119 | 
| Code Lines | 68 | 
| 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 | ||
| 42 | public function runActualTask($params = []): ?string | ||
| 43 |     { | ||
| 44 | //replacement data patterns that will be searched for | ||
| 45 | $replacementArray = [ | ||
| 46 | 'src' => [ | ||
| 47 | 'php' => [ | ||
| 48 |                     'Requirements::javascript(' => [ | ||
| 49 | 'R' => '', | ||
| 50 | ], | ||
| 51 |                     'Requirements::css(' => [ | ||
| 52 | 'R' => '', | ||
| 53 | ], | ||
| 54 |                     'Requirements::themedCSS(' => [ | ||
| 55 | 'R' => '', | ||
| 56 | ], | ||
| 57 | ], | ||
| 58 | ], | ||
| 59 | ]; | ||
| 60 | |||
| 61 |         if ($this->debug) { | ||
| 62 | $this->mu()->colourPrint($replacementArray); | ||
|  | |||
| 63 | } | ||
| 64 |         foreach ($this->mu()->getExistingModuleDirLocations() as $moduleDir) { | ||
| 65 | //Start search machine from the module location. replace API | ||
| 66 | $textSearchMachine = new SearchAndReplaceAPI($moduleDir); | ||
| 67 | $textSearchMachine->setIsReplacingEnabled(true); | ||
| 68 | $textSearchMachine->addToIgnoreFolderArray($this->ignoreFolderArray); | ||
| 69 | |||
| 70 | /*For all the different patterns listed in the replacement array | ||
| 71 | * iterate over them such that the $path would be 'src' and $patharray would be 'php' | ||
| 72 | * together making it ['src']['php'] | ||
| 73 | */ | ||
| 74 |             foreach ($replacementArray as $path => $pathArray) { | ||
| 75 | $path = $moduleDir . '/' . $path ?: ''; | ||
| 76 | $path = $this->mu()->checkIfPathExistsAndCleanItUp($path); | ||
| 77 |                 if (! file_exists($path)) { | ||
| 78 |                     $this->mu()->colourPrint("SKIPPING ${path} as it does not exist."); | ||
| 79 |                 } else { | ||
| 80 | $textSearchMachine->setSearchPath($path); | ||
| 81 |                     foreach ($pathArray as $extension => $extensionArray) { | ||
| 82 | //setting extensions to search files within | ||
| 83 |                         $textSearchMachine->setExtensions(explode('|', $extension)); | ||
| 84 | $this->mu()->colourPrint( | ||
| 85 | "++++++++++++++++++++++++++++++++++++\n" . | ||
| 86 | "CHECKING\n" . | ||
| 87 |                             "IN ${path}\n" . | ||
| 88 |                             "FOR ${extension} FILES\n" . | ||
| 89 | 'BASE ' . $moduleDir . "\n" . | ||
| 90 | "++++++++++++++++++++++++++++++++++++\n" | ||
| 91 | ); | ||
| 92 |                         foreach ($extensionArray as $find => $findDetails) { | ||
| 93 | $replace = $findDetails['R'] ?? $find; | ||
| 94 | $caseSensitive = false; | ||
| 95 | |||
| 96 | $isStraightReplace = true; | ||
| 97 | $replacementType = 'BASIC'; | ||
| 98 | |||
| 99 | // REPLACMENT PATTERN! | ||
| 100 | //Requirements::javascript(moduledirfolder/bla); | ||
| 101 | //Requirements::javascript(vpl: bla); | ||
| 102 | // $findWithPackageName = $find . strtolower($this->mu()->getPackageName()); | ||
| 103 | $vendorAndPackageFolderNameForInstall = | ||
| 104 | $this->mu()->getVendorAndPackageFolderNameForInstall(); | ||
| 105 | |||
| 106 |                             foreach (['\'', '"'] as $quoteMark) { | ||
| 107 | $finalReplace = $find . $quoteMark . $vendorAndPackageFolderNameForInstall . ': '; | ||
| 108 |                                 if (! $finalReplace && $finalReplace !== ' ') { | ||
| 109 |                                     user_error(" | ||
| 110 |                                         no replace is specified, find is: ${find}. | ||
| 111 | We suggest setting your final replace to a single space | ||
| 112 | if you would like to replace with NOTHING. | ||
| 113 | "); | ||
| 114 | } | ||
| 115 | $finalFind = $find . $quoteMark; | ||
| 116 | $this->mu()->colourPrint( | ||
| 117 | ' --- FIND: ' . $finalFind . "\n" . | ||
| 118 | ' --- REPLACE: ' . $finalReplace . "\n" | ||
| 119 | ); | ||
| 120 | |||
| 121 | $textSearchMachine->setSearchKey($finalFind, $caseSensitive, $replacementType); | ||
| 122 | $textSearchMachine->setReplacementKey($finalReplace); | ||
| 123 | $textSearchMachine->startSearchAndReplace(); | ||
| 124 | } | ||
| 125 | } | ||
| 126 | |||
| 127 | //fix double-ups | ||
| 128 | //fixes things like | ||
| 129 | //vendor/packagename: silverstripe/admin | ||
| 130 | //to | ||
| 131 | //silverstripe/admin: only | ||
| 132 | $isCaseSensitive = true; | ||
| 133 |                         foreach (['cms', 'framework', 'siteconfig', 'reports'] as $ssModule) { | ||
| 134 | $finalFind = $vendorAndPackageFolderNameForInstall . ': silverstripe/' . $ssModule . ': '; | ||
| 135 | $finalReplace = 'silverstripe/' . $ssModule . ': '; | ||
| 136 | $this->mu()->colourPrint( | ||
| 137 | ' --- FIND: ' . $finalFind . "\n" . | ||
| 138 | ' --- REPLACE: ' . $finalReplace . "\n" | ||
| 139 | ); | ||
| 140 | $textSearchMachine->setSearchKey( | ||
| 141 | $finalFind, | ||
| 142 | $isCaseSensitive, | ||
| 143 | 'silverstripe/' . $ssModule . '/@@@@double-up@@@@' | ||
| 144 | ); | ||
| 145 | $textSearchMachine->setReplacementKey($finalReplace); | ||
| 146 | $textSearchMachine->startSearchAndReplace(); | ||
| 147 | } | ||
| 148 | |||
| 149 | //SHOW TOTALS | ||
| 150 | $replacements = $textSearchMachine->showFormattedSearchTotals(); | ||
| 151 |                         if (! $replacements) { | ||
| 152 | //flush output anyway! | ||
| 153 |                             $this->mu()->colourPrint("No replacements for  ${extension}"); | ||
| 154 | } | ||
| 155 | $this->mu()->colourPrint($textSearchMachine->getOutput()); | ||
| 156 | } | ||
| 157 | } | ||
| 158 | } | ||
| 159 | } | ||
| 160 | return null; | ||
| 161 | } | ||
| 168 |