Conditions | 10 |
Paths | 192 |
Total Lines | 81 |
Code Lines | 55 |
Lines | 20 |
Ratio | 24.69 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
65 | protected function buildCommitSelector($project) { |
||
66 | // Branches |
||
67 | $branches = array(); |
||
68 | View Code Duplication | foreach($project->DNBranchList() as $branch) { |
|
69 | $sha = $branch->SHA(); |
||
70 | $name = $branch->Name(); |
||
71 | $branchValue = sprintf("%s (%s, %s old)", |
||
72 | $name, |
||
73 | substr($sha, 0, 8), |
||
74 | $branch->LastUpdated()->TimeDiff() |
||
75 | ); |
||
76 | $branches[$sha . '-' . $name] = $branchValue; |
||
77 | } |
||
78 | |||
79 | // Tags |
||
80 | $tags = array(); |
||
81 | View Code Duplication | foreach($project->DNTagList()->setLimit(null) as $tag) { |
|
82 | $sha = $tag->SHA(); |
||
83 | $name = $tag->Name(); |
||
84 | $tagValue = sprintf("%s (%s, %s old)", |
||
85 | $name, |
||
86 | substr($sha, 0, 8), |
||
87 | $branch->LastUpdated()->TimeDiff() |
||
88 | ); |
||
89 | $tags[$sha . '-' . $tag] = $tagValue; |
||
90 | } |
||
91 | $tags = array_reverse($tags); |
||
92 | |||
93 | // Past deployments |
||
94 | $redeploy = array(); |
||
95 | foreach($project->DNEnvironmentList() as $dnEnvironment) { |
||
96 | $envName = $dnEnvironment->Name; |
||
97 | foreach($dnEnvironment->DeployHistory() as $deploy) { |
||
98 | $sha = $deploy->SHA; |
||
99 | if(!isset($redeploy[$envName])) { |
||
100 | $redeploy[$envName] = array(); |
||
101 | } |
||
102 | if(!isset($redeploy[$envName][$sha])) { |
||
103 | $pastValue = sprintf("%s (deployed %s)", |
||
104 | substr($sha, 0, 8), |
||
105 | $deploy->obj('LastEdited')->Ago() |
||
106 | ); |
||
107 | $redeploy[$envName][$sha] = $pastValue; |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | |||
112 | // Merge fields |
||
113 | $releaseMethods = array(); |
||
114 | if(!empty($branches)) { |
||
115 | $releaseMethods[] = new SelectionGroup_Item( |
||
116 | 'Branch', |
||
117 | new DropdownField('Branch', 'Select a branch', $branches), |
||
118 | 'Deploy the latest version of a branch' |
||
119 | ); |
||
120 | } |
||
121 | if($tags) { |
||
122 | $releaseMethods[] = new SelectionGroup_Item( |
||
123 | 'Tag', |
||
124 | new DropdownField('Tag', 'Select a tag', $tags), |
||
125 | 'Deploy a tagged release' |
||
126 | ); |
||
127 | } |
||
128 | if($redeploy) { |
||
129 | $releaseMethods[] = new SelectionGroup_Item( |
||
130 | 'Redeploy', |
||
131 | new GroupedDropdownField('Redeploy', 'Redeploy', $redeploy), |
||
132 | 'Redeploy a release that was previously deployed (to any environment)' |
||
133 | ); |
||
134 | } |
||
135 | |||
136 | $releaseMethods[] = new SelectionGroup_Item( |
||
137 | 'SHA', |
||
138 | new Textfield('SHA', 'Please specify the full SHA'), |
||
139 | 'Deploy a specific SHA' |
||
140 | ); |
||
141 | |||
142 | $field = new TabbedSelectionGroup('SelectRelease', $releaseMethods); |
||
143 | $field->setValue(reset($releaseMethods)->getValue()); |
||
144 | return $field; |
||
145 | } |
||
146 | |||
164 |
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider
.