Conditions | 12 |
Paths | 96 |
Total Lines | 87 |
Code Lines | 61 |
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 |
||
87 | public function show(\SS_HTTPRequest $request) { |
||
88 | $targetEnvironment = null; |
||
89 | $targetEnvironmentId = $request->getVar('environmentId'); |
||
90 | if (!empty($targetEnvironmentId)) { |
||
91 | $targetEnvironment = DNEnvironment::get()->byId((int) $targetEnvironmentId); |
||
92 | } |
||
93 | |||
94 | $refs = []; |
||
95 | $prevDeploys = []; |
||
96 | |||
97 | $uatEnvironment = $this->project->DNEnvironmentList()->filter('Usage', DNEnvironment::UAT)->first(); |
||
98 | $uatBuild = $uatEnvironment ? $uatEnvironment->CurrentBuild() : null; |
||
99 | if ($uatBuild && $uatBuild->exists() && $targetEnvironment && $targetEnvironment->Usage === DNEnvironment::PRODUCTION) { |
||
100 | $refs[self::REF_TYPE_FROM_UAT] = [ |
||
101 | 'id' => self::REF_TYPE_FROM_UAT, |
||
102 | 'label' => 'Promote the version currently on UAT', |
||
103 | 'description' => 'Promote the version currently on UAT', |
||
104 | 'promote_build' => $this->formatter->getDeploymentData($uatBuild) |
||
105 | ]; |
||
106 | } |
||
107 | |||
108 | $refs[self::REF_TYPE_BRANCH] = [ |
||
109 | 'id' => self::REF_TYPE_BRANCH, |
||
110 | 'label' => 'Branch version', |
||
111 | 'description' => 'Deploy the latest version of a branch', |
||
112 | 'list' => $this->getGitBranches($this->project) |
||
113 | ]; |
||
114 | |||
115 | $refs[self::REF_TYPE_TAG] = [ |
||
116 | 'id' => self::REF_TYPE_TAG, |
||
117 | 'label' => 'Tag version', |
||
118 | 'description' => 'Deploy a tagged release', |
||
119 | 'list' => $this->getGitTags($this->project) |
||
120 | ]; |
||
121 | |||
122 | // @todo: the original was a tree that was keyed by environment, the |
||
123 | // front-end dropdown needs to be changed to support that. brrrr. |
||
124 | foreach ($this->getGitPrevDeploys($this->project) as $env) { |
||
125 | foreach ($env as $deploy) { |
||
126 | $prevDeploys[] = $deploy; |
||
127 | } |
||
128 | } |
||
129 | $refs[self::REF_TYPE_PREVIOUS] = [ |
||
130 | 'id' => self::REF_TYPE_PREVIOUS, |
||
131 | 'label' => 'Redeploy a release that was previously deployed (to any environment)', |
||
132 | 'description' => 'Deploy a previous release', |
||
133 | 'list' => $prevDeploys |
||
134 | ]; |
||
135 | $refs[self::REF_TYPE_SHA] = [ |
||
136 | 'id' => self::REF_TYPE_SHA, |
||
137 | 'label' => 'Deploy a specific SHA', |
||
138 | 'description' => 'Deploy a specific SHA' |
||
139 | ]; |
||
140 | |||
141 | $options = []; |
||
142 | if ($targetEnvironment) { |
||
143 | foreach ($targetEnvironment->getSupportedOptions() as $option) { |
||
144 | $options[] = [ |
||
145 | 'name' => $option->getName(), |
||
146 | 'title' => $option->getTitle(), |
||
147 | 'defaultValue' => $option->getDefaultValue() |
||
148 | ]; |
||
149 | } |
||
150 | } |
||
151 | |||
152 | // get the last time git fetch was run |
||
153 | $lastFetchedDate = 'never'; |
||
154 | $lastFetchedAgo = null; |
||
155 | $fetch = DNGitFetch::get() |
||
156 | ->filter([ |
||
157 | 'ProjectID' => $this->project->ID, |
||
158 | 'Status' => 'Finished' |
||
159 | ]) |
||
160 | ->sort('LastEdited', 'DESC') |
||
161 | ->first(); |
||
162 | if ($fetch) { |
||
163 | $lastFetchedDate = $fetch->obj('LastEdited')->Date(); |
||
164 | $lastFetchedAgo = $fetch->obj('LastEdited')->Ago(); |
||
165 | } |
||
166 | |||
167 | return $this->getAPIResponse([ |
||
168 | 'refs' => $refs, |
||
169 | 'options' => $options, |
||
170 | 'last_fetched_date' => $lastFetchedDate, |
||
171 | 'last_fetched_ago' => $lastFetchedAgo |
||
172 | ], 200); |
||
173 | } |
||
174 | |||
305 |
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
.