| Conditions | 5 |
| Paths | 6 |
| Total Lines | 63 |
| Code Lines | 32 |
| 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 declare(strict_types = 1); |
||
| 42 | public function run(string $travisFile = '.travis.yml'): int |
||
| 43 | { |
||
| 44 | $this->climate->border(); |
||
| 45 | $this->climate->info('Adding ' . $this->getCommand()); |
||
| 46 | $this->climate->border(); |
||
| 47 | |||
| 48 | // install composer packages |
||
| 49 | $retVal = $this->installPackages(); |
||
| 50 | if ($retVal !== 0) { |
||
| 51 | $this->climate->error('Packages could not be installed, not altering Travis or adding config files'); |
||
| 52 | |||
| 53 | return $retVal; |
||
| 54 | } |
||
| 55 | |||
| 56 | $this->addScriptsToComposerJSON(); |
||
| 57 | |||
| 58 | |||
| 59 | // any alterations post composer failures should be successful |
||
| 60 | $helper = new TravisYMLHelper($travisFile); |
||
| 61 | |||
| 62 | /** @var array<string, string|array> $yamlAsArray */ |
||
| 63 | $yamlAsArray = $helper->loadTravis(); |
||
| 64 | |||
| 65 | $helper->ensurePathExistsInYaml($yamlAsArray, 'matrix/include'); |
||
| 66 | |||
| 67 | $foundExisting = $helper->checkForExistingInEnv($yamlAsArray, $this->getFlag()); |
||
| 68 | if (!$foundExisting) { |
||
| 69 | // add a matrix entry |
||
| 70 | $yamlAsArray['matrix']['include'][] = [ |
||
| 71 | 'php' => 7.4, |
||
| 72 | 'env' => $this->getFlag() . '=1', |
||
| 73 | ]; |
||
| 74 | |||
| 75 | $this->taskReport('Added env option: ' . $this->getFlag() . '=1'); |
||
| 76 | |||
| 77 | /** @var string $prefix the bash prefix to check for the flag being set */ |
||
| 78 | $prefix = 'if [[ $' . $this->getFlag() .' ]]; then '; |
||
| 79 | |||
| 80 | $beforeScript = $this->getTravisBeforeScript(); |
||
| 81 | if (isset($beforeScript)) { |
||
| 82 | // install jdscpd, node tool, for duplication detection |
||
| 83 | $helper->ensurePathExistsInYaml($yamlAsArray, 'before_script'); |
||
| 84 | $yamlAsArray['before_script'][] = $prefix . $beforeScript . ' ;fi'; |
||
| 85 | $this->taskReport('Added before script: ' . $beforeScript); |
||
| 86 | } |
||
| 87 | |||
| 88 | $script = $this->getTravisScript(); |
||
| 89 | if (isset($script)) { |
||
| 90 | // run jscpd on src and tests dir |
||
| 91 | $helper->ensurePathExistsInYaml($yamlAsArray, 'script'); |
||
| 92 | $yamlAsArray['script'][] = $prefix . $script . ' ; fi'; |
||
| 93 | $this->taskReport('Added script: ' . $script); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | $helper->saveTravis($yamlAsArray); |
||
| 98 | |||
| 99 | $this->copyFiles(); |
||
| 100 | |||
| 101 | $this->climate->br(4); |
||
| 102 | |||
| 103 | // signal success |
||
| 104 | return 1; |
||
| 105 | } |
||
| 198 |