| Conditions | 18 |
| Paths | 768 |
| Total Lines | 109 |
| Code Lines | 77 |
| 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 |
||
| 83 | public function show(\SS_HTTPRequest $request) { |
||
| 84 | $targetEnvironment = null; |
||
| 85 | $targetEnvironmentId = $request->getVar('environmentId'); |
||
| 86 | if (!empty($targetEnvironmentId)) { |
||
| 87 | $targetEnvironment = DNEnvironment::get()->byId((int) $targetEnvironmentId); |
||
| 88 | } |
||
| 89 | |||
| 90 | $refs = []; |
||
| 91 | $prevDeploys = []; |
||
| 92 | |||
| 93 | $uatEnvironment = $this->project->DNEnvironmentList()->filter('Usage', DNEnvironment::UAT)->first(); |
||
| 94 | $uatBuild = $uatEnvironment ? $uatEnvironment->CurrentBuild() : null; |
||
| 95 | if ($uatBuild && $uatBuild->exists() && $targetEnvironment && $targetEnvironment->Usage === DNEnvironment::PRODUCTION) { |
||
| 96 | $refs[self::REF_TYPE_FROM_UAT] = [ |
||
| 97 | 'id' => self::REF_TYPE_FROM_UAT, |
||
| 98 | 'label' => 'Promote the version currently on UAT', |
||
| 99 | 'description' => 'Promote the version currently on UAT', |
||
| 100 | 'promote_build' => [ |
||
| 101 | 'id' => $uatBuild->ID, |
||
| 102 | 'deployed' => DBField::create_field('SS_Datetime', $uatBuild->Created, 'Created')->Ago(), |
||
| 103 | 'branch' => $uatBuild->Branch, |
||
| 104 | 'tags' => $uatBuild->getTags()->toArray(), |
||
| 105 | 'sha' => $uatBuild->SHA, |
||
| 106 | 'short_sha' => substr($uatBuild->SHA, 0, 7), |
||
| 107 | 'commit_message' => $uatBuild->getCommitMessage(), |
||
| 108 | 'commit_url' => $uatBuild->getCommitURL(), |
||
| 109 | ] |
||
| 110 | ]; |
||
| 111 | } |
||
| 112 | |||
| 113 | $refs[self::REF_TYPE_BRANCH] = [ |
||
| 114 | 'id' => self::REF_TYPE_BRANCH, |
||
| 115 | 'label' => 'Branch version', |
||
| 116 | 'description' => 'Deploy the latest version of a branch', |
||
| 117 | 'list' => $this->getGitBranches($this->project) |
||
| 118 | ]; |
||
| 119 | |||
| 120 | $refs[self::REF_TYPE_TAG] = [ |
||
| 121 | 'id' => self::REF_TYPE_TAG, |
||
| 122 | 'label' => 'Tag version', |
||
| 123 | 'description' => 'Deploy a tagged release', |
||
| 124 | 'list' => $this->getGitTags($this->project) |
||
| 125 | ]; |
||
| 126 | |||
| 127 | // @todo: the original was a tree that was keyed by environment, the |
||
| 128 | // front-end dropdown needs to be changed to support that. brrrr. |
||
| 129 | foreach ($this->getGitPrevDeploys($this->project) as $env) { |
||
| 130 | foreach ($env as $deploy) { |
||
| 131 | $prevDeploys[] = $deploy; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | $refs[self::REF_TYPE_PREVIOUS] = [ |
||
| 135 | 'id' => self::REF_TYPE_PREVIOUS, |
||
| 136 | 'label' => 'Redeploy a release that was previously deployed (to any environment)', |
||
| 137 | 'description' => 'Deploy a previous release', |
||
| 138 | 'list' => $prevDeploys |
||
| 139 | ]; |
||
| 140 | $refs[self::REF_TYPE_SHA] = [ |
||
| 141 | 'id' => self::REF_TYPE_SHA, |
||
| 142 | 'label' => 'Deploy a specific SHA', |
||
| 143 | 'description' => 'Deploy a specific SHA' |
||
| 144 | ]; |
||
| 145 | |||
| 146 | $options = []; |
||
| 147 | if ($targetEnvironment) { |
||
| 148 | foreach ($targetEnvironment->getSupportedOptions() as $option) { |
||
| 149 | $options[] = [ |
||
| 150 | 'name' => $option->getName(), |
||
| 151 | 'title' => $option->getTitle(), |
||
| 152 | 'defaultValue' => $option->getDefaultValue() |
||
| 153 | ]; |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | // get the last time git fetch was run |
||
| 158 | $lastFetchedDate = 'never'; |
||
| 159 | $lastFetchedAgo = null; |
||
| 160 | $fetch = DNGitFetch::get() |
||
| 161 | ->filter('ProjectID', $this->project->ID) |
||
| 162 | ->sort('LastEdited', 'DESC') |
||
| 163 | ->first(); |
||
| 164 | if ($fetch) { |
||
| 165 | $lastFetchedDate = $fetch->obj('LastEdited')->Date(); |
||
| 166 | $lastFetchedAgo = $fetch->obj('LastEdited')->Ago(); |
||
| 167 | } |
||
| 168 | |||
| 169 | $responseData = [ |
||
| 170 | 'refs' => $refs, |
||
| 171 | 'options' => $options, |
||
| 172 | 'last_fetched_date' => $lastFetchedDate, |
||
| 173 | 'last_fetched_ago' => $lastFetchedAgo |
||
| 174 | ]; |
||
| 175 | |||
| 176 | $current = $targetEnvironment ? $targetEnvironment->CurrentBuild() : null; |
||
| 177 | if ($request->getVar('redeploy') && $request->getVar('redeploy') == '1') { |
||
| 178 | if ($current && $current->exists()) { |
||
| 179 | $responseData['preselected_type'] = self::REF_TYPE_PREVIOUS; |
||
| 180 | $responseData['preselected_sha'] = $current->SHA; |
||
| 181 | } else { |
||
| 182 | $master = $this->project->DNBranchList()->byName('master'); |
||
| 183 | if ($master) { |
||
| 184 | $responseData['preselected_type'] = self::REF_TYPE_BRANCH; |
||
| 185 | $responseData['preselected_sha'] = $master->SHA(); |
||
| 186 | } |
||
| 187 | } |
||
| 188 | } |
||
| 189 | |||
| 190 | return $this->getAPIResponse($responseData, 200); |
||
| 191 | } |
||
| 192 | |||
| 315 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.