Conditions | 9 |
Paths | 144 |
Total Lines | 105 |
Code Lines | 56 |
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 |
||
86 | function absences_waitingRequestList() |
||
87 | { |
||
88 | $W = bab_Widgets(); |
||
89 | $page = $W->babPage(); |
||
90 | |||
91 | $page->addStyleSheet(absences_Addon()->getStylePath().'vacation.css'); |
||
92 | $page->setTitle(absences_translate('Waiting requests')); |
||
93 | |||
94 | $f = new absences_getRequestSearchForm(); |
||
95 | |||
96 | $I = new absences_RequestIterator(); |
||
97 | $I->status = ''; |
||
98 | |||
99 | |||
100 | if ($userid = $f->param('userid')) |
||
101 | { |
||
102 | $I->users = array($userid); |
||
103 | } |
||
104 | |||
105 | if ($organization = $f->param('organization')) |
||
106 | { |
||
107 | $I->organization = array($organization); |
||
108 | } |
||
109 | |||
110 | $datePicker = $W->DatePicker(); |
||
111 | |||
112 | if ('0000-00-00' !== $begin = $datePicker->getISODate($f->param('dateb', null))) |
||
113 | { |
||
114 | $I->startFrom = $begin; |
||
115 | } |
||
116 | |||
117 | if ('0000-00-00' !== $end = $datePicker->getISODate($f->param('datee', null))) |
||
118 | { |
||
119 | $I->startTo = $end; |
||
120 | } |
||
121 | |||
122 | bab_functionality::includeOriginal('Icons'); |
||
123 | |||
124 | $table = $W->BabTableView(); |
||
125 | $table->addClass(Func_Icons::ICON_LEFT_16); |
||
126 | |||
127 | $table->addItem($W->Label(absences_translate('Request type')) , 0, 0); |
||
128 | $table->addItem($W->Label(absences_translate('Appliquant')) , 0, 1); |
||
129 | $table->addItem($W->Label(absences_translate('Approver(s)')) , 0, 2); |
||
130 | $table->addItem($W->Label(absences_translate('Approbation sheme')) , 0, 3); |
||
131 | $table->addItem($W->Label(absences_translate('Last action date')) , 0, 4); |
||
132 | $table->addItem($W->Label(absences_translate('Last action')) , 0, 5); |
||
133 | $table->addItem($W->Label(absences_translate('Edit')) , 0, 6); |
||
134 | $table->addItem($W->Label(absences_translate('Delete')) , 0, 7); |
||
135 | |||
136 | $table->addHeadRow(0); |
||
137 | |||
138 | $row = 1; |
||
139 | foreach($I as $request) |
||
140 | { |
||
141 | /* @var $request absences_Request */ |
||
142 | |||
143 | $appliquant = absences_Agent::getFromIdUser($request->id_user); |
||
144 | $approbation = $appliquant->getApprobation(); |
||
145 | |||
146 | if ($movement = $request->getLastMovement()) |
||
147 | { |
||
148 | $last_createdOn = $movement->createdOn; |
||
149 | $last_message = $movement->message; |
||
150 | } else { |
||
151 | $last_createdOn = ''; |
||
152 | $last_message = ''; |
||
153 | } |
||
154 | |||
155 | |||
156 | $table->addItem($W->Label($request->getRequestType()) , $row, 0 ); |
||
157 | $table->addItem($W->Label($appliquant->getName()) , $row, 1 ); |
||
158 | $table->addItem($W->Label($request->getNextApprovers()) , $row, 2 ); |
||
159 | $table->addItem($W->Label($approbation['name'].sprintf(' (%s)', $approbation['type'])) , $row, 3 ); |
||
160 | $table->addItem($W->Label(bab_shortDate(bab_mktime($last_createdOn))) , $row, 4 ); |
||
161 | $table->addItem($W->Label($last_message) , $row, 5 ); |
||
162 | $table->addItem($W->Link($W->Icon('', Func_Icons::ACTIONS_DOCUMENT_EDIT), $request->getManagerEditUrl()) , $row, 6 ); |
||
163 | |||
164 | |||
165 | $deleteLink = $W->Link($W->Icon('', Func_Icons::ACTIONS_EDIT_DELETE), $request->getManagerDeleteUrl()); |
||
166 | |||
167 | if (!($request instanceof absences_Entry)) |
||
168 | { |
||
169 | $deleteLink->setConfirmationMessage(absences_translate('Do you really want to delete?')); |
||
170 | } |
||
171 | |||
172 | |||
173 | $table->addItem($deleteLink , $row, 7 ); |
||
174 | |||
175 | if ($request->approbAlert()) |
||
176 | { |
||
177 | $table->addRowClass($row, 'widget-strong'); |
||
178 | } |
||
179 | |||
180 | $row++; |
||
181 | } |
||
182 | |||
183 | |||
184 | |||
185 | |||
186 | $page->addItem($f->getForm()); |
||
187 | $page->addItem($table); |
||
188 | |||
189 | $page->displayHtml(); |
||
190 | } |
||
191 | |||
234 | bab_siteMap::setPosition('absences','User'); |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.