Conditions | 9 |
Paths | 24 |
Total Lines | 63 |
Code Lines | 44 |
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 | if (!empty($request->getVar('environmentId'))) { |
||
86 | $targetEnvironment = DNEnvironment::get()->byId((int) $request->getVar('environmentId')); |
||
87 | } |
||
88 | |||
89 | $refs = []; |
||
90 | $prevDeploys = []; |
||
91 | |||
92 | $uatEnvironment = $this->project->DNEnvironmentList()->filter('Usage', 'UAT')->first(); |
||
93 | $uatBuild = $uatEnvironment ? $uatEnvironment->CurrentBuild() : null; |
||
94 | if ($uatBuild && $uatBuild->exists() && $targetEnvironment && $targetEnvironment->Usage === 'Production') { |
||
95 | $refs[self::REF_TYPE_FROM_UAT] = [ |
||
96 | 'id' => self::REF_TYPE_FROM_UAT, |
||
97 | 'label' => 'Promote the version currently on UAT', |
||
98 | 'description' => 'Promote the version currently on UAT', |
||
99 | 'promote_build' => [ |
||
100 | 'id' => $uatBuild->ID, |
||
101 | 'deployed' => DBField::create_field('SS_Datetime', $uatBuild->Created, 'Created')->Ago(), |
||
102 | 'branch' => $uatBuild->Branch, |
||
103 | 'tags' => $uatBuild->getTags()->toArray(), |
||
104 | 'sha' => $uatBuild->SHA, |
||
105 | 'commit_message' => $uatBuild->getCommitMessage(), |
||
106 | 'commit_url' => $uatBuild->getCommitURL(), |
||
107 | ] |
||
108 | ]; |
||
109 | } |
||
110 | |||
111 | $refs[self::REF_TYPE_BRANCH] = [ |
||
112 | 'id' => self::REF_TYPE_BRANCH, |
||
113 | 'label' => 'Branch version', |
||
114 | 'description' => 'Deploy the latest version of a branch', |
||
115 | 'list' => $this->getGitBranches($this->project) |
||
116 | ]; |
||
117 | |||
118 | $refs[self::REF_TYPE_TAG] = [ |
||
119 | 'id' => self::REF_TYPE_TAG, |
||
120 | 'label' => 'Tag version', |
||
121 | 'description' => 'Deploy a tagged release', |
||
122 | 'list' => $this->getGitTags($this->project) |
||
123 | ]; |
||
124 | |||
125 | // @todo: the original was a tree that was keyed by environment, the |
||
126 | // front-end dropdown needs to be changed to support that. brrrr. |
||
127 | foreach ($this->getGitPrevDeploys($this->project) as $env) { |
||
128 | foreach ($env as $deploy) { |
||
129 | $prevDeploys[] = $deploy; |
||
130 | } |
||
131 | } |
||
132 | $refs[self::REF_TYPE_PREVIOUS] = [ |
||
133 | 'id' => self::REF_TYPE_PREVIOUS, |
||
134 | 'label' => 'Redeploy a release that was previously deployed (to any environment)', |
||
135 | 'description' => 'Deploy a previous release', |
||
136 | 'list' => $prevDeploys |
||
137 | ]; |
||
138 | $refs[self::REF_TYPE_SHA] = [ |
||
139 | 'id' => self::REF_TYPE_SHA, |
||
140 | 'label' => 'Deploy a specific SHA', |
||
141 | 'description' => 'Deploy a specific SHA' |
||
142 | ]; |
||
143 | |||
144 | return $this->getAPIResponse(['refs' => $refs], 200); |
||
145 | } |
||
146 | |||
269 |
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
.