Conditions | 10 |
Paths | 96 |
Total Lines | 134 |
Code Lines | 105 |
Lines | 8 |
Ratio | 5.97 % |
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 |
||
70 | public function __construct($id_user, $id) |
||
71 | { |
||
72 | require_once dirname(__FILE__).'/entry.class.php'; |
||
73 | global $babBody, $babDB; |
||
74 | $this->datebegin = $GLOBALS['babUrlScript']."?tg=month&callback=dateBegin&ymin=0&ymax=2"; |
||
75 | $this->datebegintxt = absences_translate("Begin date"); |
||
76 | $this->dateend = $GLOBALS['babUrlScript']."?tg=month&callback=dateEnd&ymin=0&ymax=2"; |
||
77 | $this->dateendtxt = absences_translate("End date"); |
||
78 | $this->vactype = absences_translate("Vacation type"); |
||
79 | View Code Duplication | if ($id) |
|
|
|||
80 | { |
||
81 | $this->addvac = absences_translate("Edit vacation request"); |
||
82 | $this->save_previsional = absences_translate("Save previsional request"); |
||
83 | } else { |
||
84 | $this->addvac = absences_translate("Request vacation"); |
||
85 | $this->save_previsional = absences_translate("Create previsional request"); |
||
86 | } |
||
87 | $this->remark = absences_translate("Remarks"); |
||
88 | $this->nbdaystxt = absences_translate("Quantity"); |
||
89 | $this->invaliddate = absences_translate("ERROR: End date must be older"); |
||
90 | $this->invaliddate = str_replace("'", "\'", $this->invaliddate); |
||
91 | $this->invaliddate = str_replace('"', "'+String.fromCharCode(34)+'",$this->invaliddate); |
||
92 | $this->invaliddate2 = absences_translate("Total days does'nt fit between dates"); |
||
93 | $this->invaliddate2 = str_replace("'", "\'", $this->invaliddate2); |
||
94 | $this->invaliddate2 = str_replace('"', "'+String.fromCharCode(34)+'",$this->invaliddate2); |
||
95 | $this->invalidentry = absences_translate("Invalid entry! Only numbers are accepted or . !"); |
||
96 | $this->invalidentry = str_replace("'", "\'", $this->invalidentry); |
||
97 | $this->invalidentry = str_replace('"', "'+String.fromCharCode(34)+'",$this->invalidentry); |
||
98 | $this->invalidentry1 = absences_translate("Invalid entry"); |
||
99 | $this->invalidentry3 = absences_translate("The number of days exceed the total allowed"); |
||
100 | $this->totaltxt = absences_translate("Total"); |
||
101 | $this->balancetxt = absences_translate("Balance"); |
||
102 | $this->calendar = absences_translate("Planning"); |
||
103 | $this->t_total = absences_translate("Total"); |
||
104 | $this->t_available = absences_translate("Available"); |
||
105 | $this->t_waiting = absences_translate("Waiting"); |
||
106 | $this->t_period_nbdays = absences_translate("Period days"); |
||
107 | $this->t_view_rights = absences_translate("View rights details"); |
||
108 | $this->t_recurring = absences_translate("Do a recuring request"); |
||
109 | $this->t_previsional = absences_translate("Previsional"); |
||
110 | $this->t_previsional_available = absences_translate("Prev. bal."); |
||
111 | |||
112 | $this->totalval = 0; |
||
113 | $this->maxallowed = 0; |
||
114 | $this->id = $id; |
||
115 | $this->id_user = $id_user; |
||
116 | $this->ide = bab_rp('ide'); |
||
117 | |||
118 | $this->year = isset($_REQUEST['year']) ? $_REQUEST['year'] : date('Y'); |
||
119 | $this->month = isset($_REQUEST['month']) ? $_REQUEST['month'] : date('n'); |
||
120 | $this->rfrom = isset($_REQUEST['rfrom']) ? $_REQUEST['rfrom'] : 0; |
||
121 | |||
122 | if (!empty($this->id) && !isset($_POST['daybegin'])) |
||
123 | { |
||
124 | include_once $GLOBALS['babInstallPath']."utilit/dateTime.php"; |
||
125 | |||
126 | $entry = absences_Entry::getById($this->id); |
||
127 | $arr = $entry->getRow(); |
||
128 | |||
129 | $date_begin = BAB_DateTime::fromIsoDateTime($arr['date_begin']); |
||
130 | $date_end = BAB_DateTime::fromIsoDateTime($arr['date_end']); |
||
131 | |||
132 | $this->yearbegin = $date_begin->getYear(); |
||
133 | $this->monthbegin = $date_begin->getMonth(); |
||
134 | $this->daybegin = $date_begin->getDayOfMonth(); |
||
135 | |||
136 | $this->yearend = $date_end->getYear(); |
||
137 | $this->monthend = $date_end->getMonth(); |
||
138 | $this->dayend = $date_end->getDayOfMonth(); |
||
139 | |||
140 | $this->hourbegin = date('H:i:s', $date_begin->getTimeStamp()); |
||
141 | $this->halfdaybegin = 'am' === date('a', $date_begin->getTimeStamp()) ? 0 : 1; |
||
142 | $this->hourend = date('H:i:s', $date_end->getTimeStamp()); |
||
143 | $this->halfdayend = 'am' === date('a', $date_end->getTimeStamp()) ? 0 : 1; |
||
144 | } |
||
145 | elseif (isset($_POST['daybegin'])) |
||
146 | { |
||
147 | $this->daybegin = $_POST['daybegin']; |
||
148 | $this->dayend = $_POST['dayend']; |
||
149 | $this->monthbegin = $_POST['monthbegin']; |
||
150 | $this->monthend = $_POST['monthend']; |
||
151 | $this->yearbegin = $this->year + $_POST['yearbegin'] - 1; |
||
152 | $this->yearend = $this->year + $_POST['yearend'] - 1; |
||
153 | $this->halfdaybegin = 0; |
||
154 | $this->halfdayend = 1; |
||
155 | $this->hourbegin = $_POST['hourbegin']; |
||
156 | $this->hourend = $_POST['hourend']; |
||
157 | } |
||
158 | else |
||
159 | { |
||
160 | $this->daybegin = date("j"); |
||
161 | $this->dayend = date("j"); |
||
162 | $this->monthbegin = date("n"); |
||
163 | $this->monthend = date("n"); |
||
164 | $this->yearbegin = $this->year; |
||
165 | $this->yearend = $this->year; |
||
166 | $this->halfdaybegin = 0; |
||
167 | $this->halfdayend = 1; |
||
168 | $this->hourbegin = '00:00:00'; |
||
169 | $this->hourend = '23:59:59'; |
||
170 | } |
||
171 | |||
172 | $this->halfdaysel = $this->halfdaybegin; |
||
173 | |||
174 | $this->calurl = absences_addon()->getUrl()."planning&idx=cal&idu=".$id_user; |
||
175 | |||
176 | $this->rights = absences_getRightsByGroupOnPeriod($id_user, $this->rfrom); |
||
177 | $this->total_available = array('D' => 0, 'H' => 0); |
||
178 | $this->total_waiting = array('D' => 0, 'H' => 0); |
||
179 | $this->total_previsional = array('D' => 0, 'H' => 0); |
||
180 | $this->total_prevavail = array('D' => 0, 'H' => 0); |
||
181 | |||
182 | $this->dayType = array( |
||
183 | absences_translate("Morning"), |
||
184 | absences_translate("Afternoon") |
||
185 | ); |
||
186 | |||
187 | $this->hours = absences_hoursList($GLOBALS['BAB_SESS_USERID']); |
||
188 | |||
189 | |||
190 | require_once $GLOBALS['babInstallPath'].'utilit/workinghoursincl.php'; |
||
191 | $jSON = array(); |
||
192 | $this->addWorkingPeriod(bab_getWHours($GLOBALS['BAB_SESS_USERID'], 0), $jSON); |
||
193 | $this->addWorkingPeriod(bab_getWHours($GLOBALS['BAB_SESS_USERID'], 1), $jSON); |
||
194 | $this->addWorkingPeriod(bab_getWHours($GLOBALS['BAB_SESS_USERID'], 2), $jSON); |
||
195 | $this->addWorkingPeriod(bab_getWHours($GLOBALS['BAB_SESS_USERID'], 3), $jSON); |
||
196 | $this->addWorkingPeriod(bab_getWHours($GLOBALS['BAB_SESS_USERID'], 4), $jSON); |
||
197 | $this->addWorkingPeriod(bab_getWHours($GLOBALS['BAB_SESS_USERID'], 5), $jSON); |
||
198 | $this->addWorkingPeriod(bab_getWHours($GLOBALS['BAB_SESS_USERID'], 6), $jSON); |
||
199 | |||
200 | |||
201 | $this->json_working_hours = '['.implode(',', $jSON).']'; |
||
202 | |||
203 | } |
||
204 | |||
371 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.