| Conditions | 9 |
| Paths | 24 |
| Total Lines | 64 |
| Code Lines | 45 |
| 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', '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 | 'commit_message' => $uatBuild->getCommitMessage(), |
||
| 107 | 'commit_url' => $uatBuild->getCommitURL(), |
||
| 108 | ] |
||
| 109 | ]; |
||
| 110 | } |
||
| 111 | |||
| 112 | $refs[self::REF_TYPE_BRANCH] = [ |
||
| 113 | 'id' => self::REF_TYPE_BRANCH, |
||
| 114 | 'label' => 'Branch version', |
||
| 115 | 'description' => 'Deploy the latest version of a branch', |
||
| 116 | 'list' => $this->getGitBranches($this->project) |
||
| 117 | ]; |
||
| 118 | |||
| 119 | $refs[self::REF_TYPE_TAG] = [ |
||
| 120 | 'id' => self::REF_TYPE_TAG, |
||
| 121 | 'label' => 'Tag version', |
||
| 122 | 'description' => 'Deploy a tagged release', |
||
| 123 | 'list' => $this->getGitTags($this->project) |
||
| 124 | ]; |
||
| 125 | |||
| 126 | // @todo: the original was a tree that was keyed by environment, the |
||
| 127 | // front-end dropdown needs to be changed to support that. brrrr. |
||
| 128 | foreach ($this->getGitPrevDeploys($this->project) as $env) { |
||
| 129 | foreach ($env as $deploy) { |
||
| 130 | $prevDeploys[] = $deploy; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | $refs[self::REF_TYPE_PREVIOUS] = [ |
||
| 134 | 'id' => self::REF_TYPE_PREVIOUS, |
||
| 135 | 'label' => 'Redeploy a release that was previously deployed (to any environment)', |
||
| 136 | 'description' => 'Deploy a previous release', |
||
| 137 | 'list' => $prevDeploys |
||
| 138 | ]; |
||
| 139 | $refs[self::REF_TYPE_SHA] = [ |
||
| 140 | 'id' => self::REF_TYPE_SHA, |
||
| 141 | 'label' => 'Deploy a specific SHA', |
||
| 142 | 'description' => 'Deploy a specific SHA' |
||
| 143 | ]; |
||
| 144 | |||
| 145 | return $this->getAPIResponse(['refs' => $refs], 200); |
||
| 146 | } |
||
| 147 | |||
| 270 |
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.