| Conditions | 7 |
| Paths | 7 |
| Total Lines | 60 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 27 | public function runActualTask($params = []): ?string |
||
| 28 | { |
||
| 29 | $codeDirs = $this->mu()->findNameSpaceAndCodeDirs(); |
||
|
|
|||
| 30 | $dirsDone = []; |
||
| 31 | foreach ($codeDirs as $baseNameSpace => $codeDir) { |
||
| 32 | $directories = new \RecursiveDirectoryIterator($codeDir); |
||
| 33 | foreach (new \RecursiveIteratorIterator($directories) as $file => $fileObject) { |
||
| 34 | if ($fileObject->getExtension() === 'php') { |
||
| 35 | $dirName = realpath(dirname($file)); |
||
| 36 | if (! isset($dirsDone[$dirName])) { |
||
| 37 | $dirsDone[$dirName] = true; |
||
| 38 | $nameSpaceAppendix = str_replace($codeDir, '', $dirName); |
||
| 39 | $nameSpaceAppendix = trim($nameSpaceAppendix, '/'); |
||
| 40 | $nameSpaceAppendix = str_replace('/', '\\', $nameSpaceAppendix); |
||
| 41 | //prepend $baseNameSpace |
||
| 42 | $nameSpace = $baseNameSpace . '\\' . $nameSpaceAppendix; |
||
| 43 | //turn into array |
||
| 44 | $nameSpaceArray = explode('\\', $nameSpace); |
||
| 45 | $nameSpaceArrayNew = []; |
||
| 46 | foreach ($nameSpaceArray as $nameSpaceSnippet) { |
||
| 47 | if ($nameSpaceSnippet) { |
||
| 48 | $nameSpaceArrayNew[] = $this->mu()->cleanCamelCase($nameSpaceSnippet); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | $nameSpace = implode('\\', $nameSpaceArrayNew); |
||
| 52 | $this->mu()->execMe( |
||
| 53 | $codeDir, |
||
| 54 | 'php ' . $this->mu()->getLocationOfSSUpgradeModule() . ' add-namespace "' . $nameSpace . '" ' . $dirName . ' --root-dir=' . $this->mu()->getWebRootDirLocation() . ' --write --psr4 -vvv', |
||
| 55 | 'adding namespace: ' . $nameSpace . ' to ' . $dirName, |
||
| 56 | false |
||
| 57 | ); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | } |
||
| 61 | // } else { |
||
| 62 | // //@todo: we assume 'code' for now ... |
||
| 63 | // $codeDirs = $this->mu()->findNameSpaceAndCodeDirs(); |
||
| 64 | // foreach ($codeDirs as $codeDir) { |
||
| 65 | // $this->mu()->execMe( |
||
| 66 | // $this->mu()->getLocationOfSSUpgradeModule(), |
||
| 67 | // 'find '.$codeDir.' -mindepth 1 -maxdepth 2 -type d -exec '. |
||
| 68 | // 'sh -c '. |
||
| 69 | // '\'dir=${1##*/}; '. |
||
| 70 | // 'php '.$this->mu()->getLocationOfSSUpgradeModule().' add-namespace "'.$this->mu()->getVendorNamespace().'\\'.$this->mu()->getPackageNamespace().'\\$dir" "$dir" --write --psr4 -vvv'. |
||
| 71 | // '\' _ {} '. |
||
| 72 | // '\;', |
||
| 73 | // 'adding name spaces', |
||
| 74 | // false |
||
| 75 | // ); |
||
| 76 | // } |
||
| 77 | // } |
||
| 78 | $this->mu()->execMe( |
||
| 79 | $codeDir, |
||
| 80 | 'php ' . $this->mu()->getLocationOfSSUpgradeModule() . ' add-namespace "' . $baseNameSpace . '\" ' . $codeDir . ' --root-dir=' . $this->mu()->getWebRootDirLocation() . ' --write --psr4 -vvv', |
||
| 81 | 'adding namespace: ' . $baseNameSpace . ' to ' . $codeDir, |
||
| 82 | false |
||
| 83 | ); |
||
| 84 | $this->setCommitMessage('API: adding namespaces'); |
||
| 85 | } |
||
| 86 | return null; |
||
| 87 | } |
||
| 94 |