Conditions | 19 |
Paths | 12288 |
Total Lines | 132 |
Code Lines | 84 |
Lines | 12 |
Ratio | 9.09 % |
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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
79 | public function __construct($idtype, $idcoll, $rgroup, $dateb, $datee, $active, $pos, $archived, $recovery, $name) |
||
80 | { |
||
81 | |||
82 | $this->desctxt = absences_translate("Description"); |
||
83 | $this->typetxt = absences_translate("Type"); |
||
84 | $this->nametxt = absences_translate("Name"); |
||
|
|||
85 | $this->kindtxt = absences_translate("Right kind"); |
||
86 | $this->quantitytxt = absences_translate("Quantity"); |
||
87 | $this->creditortxt = absences_translate("Author"); |
||
88 | $this->datetxt = absences_translate("Entry date"); |
||
89 | $this->date2txt = absences_translate("Entry date ( dd-mm-yyyy )"); |
||
90 | $this->addtxt = absences_translate("Allocate vacation rights"); |
||
91 | $this->filteron = absences_translate("Filter on"); |
||
92 | $this->begintxt = absences_translate("Begin"); |
||
93 | $this->endtxt = absences_translate("End"); |
||
94 | $this->altlistp = absences_translate("Beneficiaries"); |
||
95 | $this->statustxt = absences_translate("Active"); |
||
96 | $this->activeyes = absences_translate("Opened rights"); |
||
97 | $this->activeno = absences_translate("Closed rights"); |
||
98 | $this->closedtxt = absences_translate("Vac. closed"); |
||
99 | $this->openedtxt = absences_translate("Vac. opened"); |
||
100 | $this->alttxt = absences_translate("Modify"); |
||
101 | $this->t_edit = absences_translate("Modification"); |
||
102 | $this->t_first_page = absences_translate("First page"); |
||
103 | $this->t_previous_page = absences_translate("Previous page"); |
||
104 | $this->t_next_page = absences_translate("Next page"); |
||
105 | $this->t_last_page = absences_translate("Last page"); |
||
106 | $this->t_available = absences_translate("Availability"); |
||
107 | $this->topurl = ""; |
||
108 | $this->bottomurl = ""; |
||
109 | $this->nexturl = ""; |
||
110 | $this->prevurl = ""; |
||
111 | $this->yselected = ""; |
||
112 | $this->nselected = ""; |
||
113 | $this->t_position = ''; |
||
114 | global $babDB; |
||
115 | |||
116 | $this->pos = $pos; |
||
117 | |||
118 | $aaareq = array(); |
||
119 | $req = "".ABSENCES_RIGHTS_TBL." r LEFT JOIN ".ABSENCES_TYPES_TBL." t ON t.id=r.id_type where "; |
||
120 | |||
121 | if( $name != "") { |
||
122 | $aaareq[] = "r.description LIKE '%".$babDB->db_escape_like($name)."%'"; |
||
123 | } |
||
124 | |||
125 | if( $active != "") |
||
126 | $aaareq[] = "r.active='".$babDB->db_escape_string($active)."'"; |
||
127 | |||
128 | if( $idcoll != "") |
||
129 | { |
||
130 | $aaareq[] = "r.id IN(SELECT id_right FROM absences_coll_rights WHERE id_coll=".$babDB->quote($idcoll).")"; |
||
131 | } |
||
132 | |||
133 | if( $idtype != "") |
||
134 | { |
||
135 | $aaareq[] = "r.id_type=".$babDB->quote($idtype); |
||
136 | } |
||
137 | |||
138 | if( $rgroup != "") |
||
139 | { |
||
140 | $aaareq[] = "r.id_rgroup=".$babDB->quote($rgroup); |
||
141 | } |
||
142 | |||
143 | if( $dateb != "" ) |
||
144 | { |
||
145 | $ar = explode("-", $dateb); |
||
146 | $dateb = $ar[2]."-".$ar[1]."-".$ar[0]; |
||
147 | } |
||
148 | |||
149 | View Code Duplication | if( $datee != "" ) |
|
150 | { |
||
151 | $ar = explode("-", $datee); |
||
152 | $datee = $ar[2]."-".$ar[1]."-".$ar[0]; |
||
153 | } |
||
154 | |||
155 | if( $dateb != "" && $datee != "") |
||
156 | { |
||
157 | $aaareq[] = "( r.date_entry between '".$babDB->db_escape_string($dateb)."' and '".$babDB->db_escape_string($datee)."')"; |
||
158 | } |
||
159 | else if( $dateb == "" && $datee != "" ) |
||
160 | { |
||
161 | $aaareq[] = "r.date_entry <= '".$babDB->db_escape_string($datee)."'"; |
||
162 | } |
||
163 | else if ($dateb != "" ) |
||
164 | { |
||
165 | $aaareq[] = "r.date_entry >= '".$babDB->db_escape_string($dateb)."'"; |
||
166 | } |
||
167 | |||
168 | if ($archived) |
||
169 | { |
||
170 | $aaareq[] = "r.archived = ".$babDB->quote(1); |
||
171 | } else { |
||
172 | $aaareq[] = "r.archived = ".$babDB->quote(0); |
||
173 | } |
||
174 | |||
175 | if ($recovery) |
||
176 | { |
||
177 | $aaareq[] = "r.kind = ".$babDB->quote(absences_Right::RECOVERY); |
||
178 | } else { |
||
179 | $aaareq[] = "r.kind <> ".$babDB->quote(absences_Right::RECOVERY); |
||
180 | } |
||
181 | |||
182 | |||
183 | View Code Duplication | if( isset($aaareq) && sizeof($aaareq) > 0 ) |
|
184 | { |
||
185 | if( sizeof($aaareq) > 1 ) |
||
186 | $req .= implode(' and ', $aaareq); |
||
187 | else |
||
188 | $req .= $aaareq[0]; |
||
189 | } |
||
190 | $req .= " order by r.date_entry desc, r.id"; |
||
191 | |||
192 | list($total) = $babDB->db_fetch_row($babDB->db_query("select count(*) as total from ".$req)); |
||
193 | |||
194 | $this->paginate($total, ABSENCES_MAX_RIGHTS_LIST); |
||
195 | |||
196 | if( $total > ABSENCES_MAX_RIGHTS_LIST) |
||
197 | { |
||
198 | $req .= " limit ".$pos.",".ABSENCES_MAX_RIGHTS_LIST; |
||
199 | } |
||
200 | bab_debug("select r.*, t.name type, t.color typecolor from ".$req); |
||
201 | $this->res = $babDB->db_query("select r.*, t.name type, t.color typecolor from ".$req); |
||
202 | $this->count = $babDB->db_num_rows($this->res); |
||
203 | $this->addurl = absences_addon()->getUrl()."vacadma&idx=addvr"; |
||
204 | |||
205 | |||
206 | $this->dateburl = $GLOBALS['babUrlScript']."?tg=month&callback=dateBegin&ymin=0&ymax=3"; |
||
207 | $this->dateeurl = $GLOBALS['babUrlScript']."?tg=month&callback=dateEnd&ymin=0&ymax=3"; |
||
208 | |||
209 | $this->searchform = $this->getSearchForm(); |
||
210 | } |
||
211 | |||
405 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: