| Conditions | 11 |
| Paths | 17 |
| Total Lines | 52 |
| Code Lines | 42 |
| 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 |
||
| 96 | private function askForBranches(bool $forSingleEnvironment = false): BranchesModel |
||
| 97 | { |
||
| 98 | try { |
||
| 99 | $branchesModel = BranchesModel::newFromMetadata(); |
||
| 100 | return $branchesModel; |
||
| 101 | } catch (ManifestException | JobException $e) { |
||
| 102 | if ($forSingleEnvironment) { |
||
| 103 | $branch = $this->askForBranch(true); |
||
| 104 | return new BranchesModel([$branch], []); |
||
| 105 | } |
||
| 106 | $singleBranch = 'On one single branch'; |
||
| 107 | $allBranches = 'On all branches'; |
||
| 108 | $customBranches = 'Choose custom branches'; |
||
| 109 | $choices = [$singleBranch, $allBranches, $customBranches]; |
||
| 110 | $strategy = $this->getAentHelper()->choiceQuestion('Which deployment strategy to you want to apply?', $choices) |
||
| 111 | ->ask(); |
||
| 112 | |||
| 113 | $branches = []; |
||
| 114 | $branchesToIgnore = []; |
||
| 115 | switch ($strategy) { |
||
| 116 | case $singleBranch: |
||
| 117 | $branches[] = $this->askForBranch(true); |
||
| 118 | break; |
||
| 119 | case $allBranches: |
||
| 120 | $branches[] = 'branches'; |
||
| 121 | break; |
||
| 122 | case $customBranches: |
||
| 123 | $branches[] = $this->askForBranch(true); |
||
| 124 | do { |
||
| 125 | $anotherBranch = $this->askForBranch(false); |
||
| 126 | if (!empty($anotherBranch)) { |
||
| 127 | $branches[] = $anotherBranch; |
||
| 128 | } |
||
| 129 | } while (!empty($anotherBranch)); |
||
| 130 | break; |
||
| 131 | } |
||
| 132 | |||
| 133 | if ($strategy !== $singleBranch) { |
||
| 134 | do { |
||
| 135 | $branchToIgnore = $this->getAentHelper()->question('Git branch to ignore (leave empty to skip)') |
||
| 136 | ->setDefault('') |
||
| 137 | ->setValidator(CommonValidators::getAlphaValidator(['_', '.', '-'], 'branch names can contain alphanumeric characters and "_", ".", "-".')) |
||
| 138 | ->ask(); |
||
| 139 | if (!empty($branchToIgnore)) { |
||
| 140 | $branchesToIgnore[] = $branchToIgnore; |
||
| 141 | } |
||
| 142 | } while (!empty($branchToIgnore)); |
||
| 143 | } |
||
| 144 | |||
| 145 | $branchesModel = new BranchesModel($branches, $branchesToIgnore); |
||
| 146 | $branchesModel->feedMetadata(); |
||
| 147 | return $branchesModel; |
||
| 148 | } |
||
| 163 |