Conditions | 20 |
Paths | > 20000 |
Total Lines | 130 |
Code Lines | 72 |
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 |
||
118 | public function assign_values(&$action, $id = 0, $ref = '') |
||
119 | { |
||
120 | // phpcs:enable |
||
121 | global $conf, $langs, $user, $mysoc, $canvas; |
||
122 | global $form; |
||
123 | |||
124 | $tmpobject = new Product($this->db); |
||
125 | if (!empty($id) || !empty($ref)) { |
||
126 | $tmpobject->fetch($id, $ref); |
||
127 | } |
||
128 | $this->object = $tmpobject; |
||
129 | |||
130 | foreach ($this->object as $key => $value) { |
||
131 | $this->tpl[$key] = $value; |
||
132 | } |
||
133 | |||
134 | $this->tpl['error'] = get_htmloutput_errors($this->object->error, $this->object->errors); |
||
135 | |||
136 | // canvas |
||
137 | $this->tpl['canvas'] = $this->canvas; |
||
138 | |||
139 | // id |
||
140 | $this->tpl['id'] = $this->id; |
||
141 | |||
142 | // Ref |
||
143 | $this->tpl['ref'] = $this->ref; |
||
144 | |||
145 | // Label |
||
146 | $this->tpl['label'] = $this->label; |
||
147 | |||
148 | // Description |
||
149 | $this->tpl['description'] = nl2br($this->description); |
||
150 | |||
151 | // Statut |
||
152 | $this->tpl['status'] = $this->object->getLibStatut(2); |
||
153 | |||
154 | // Note |
||
155 | $this->tpl['note'] = nl2br($this->note); |
||
156 | |||
157 | if ($action == 'create') { |
||
158 | // Price |
||
159 | $this->tpl['price'] = $this->price; |
||
160 | $this->tpl['price_min'] = $this->price_min; |
||
161 | $this->tpl['price_base_type'] = $form->selectPriceBaseType($this->price_base_type, "price_base_type"); |
||
162 | |||
163 | // VAT |
||
164 | $this->tpl['tva_tx'] = $form->load_tva("tva_tx", -1, $mysoc, ''); |
||
165 | } |
||
166 | |||
167 | if ($action == 'view') { |
||
168 | $head = product_prepare_head($this->object); |
||
169 | |||
170 | $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'ref', '', 1, 'ref'); |
||
171 | |||
172 | $titre = $langs->trans("CardProduct" . $this->object->type); |
||
173 | $picto = ($this->object->type == Product::TYPE_SERVICE ? 'service' : 'product'); |
||
174 | $this->tpl['showhead'] = dol_get_fiche_head($head, 'card', $titre, 0, $picto); |
||
175 | $this->tpl['showend'] = dol_get_fiche_end(); |
||
176 | |||
177 | // Accountancy buy code |
||
178 | $this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer); |
||
179 | $this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer); |
||
180 | |||
181 | // Accountancy sell code |
||
182 | $this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer); |
||
183 | $this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer); |
||
184 | } |
||
185 | |||
186 | $this->tpl['finished'] = $this->object->finished; |
||
187 | $this->tpl['ref'] = $this->object->ref; |
||
188 | $this->tpl['label'] = $this->object->label; |
||
189 | $this->tpl['id'] = $this->object->id; |
||
190 | $this->tpl['type'] = $this->object->type; |
||
191 | $this->tpl['note'] = $this->object->note_private; |
||
192 | $this->tpl['seuil_stock_alerte'] = $this->object->seuil_stock_alerte; |
||
193 | |||
194 | // Duration |
||
195 | $this->tpl['duration_value'] = $this->object->duration_value; |
||
196 | |||
197 | if ($action == 'create') { |
||
198 | // Title |
||
199 | $this->tpl['title'] = $langs->trans("NewService"); |
||
200 | } |
||
201 | |||
202 | if ($action == 'edit') { |
||
203 | $this->tpl['title'] = $langs->trans('Modify') . ' ' . $langs->trans('Service') . ' : ' . $this->object->ref; |
||
204 | } |
||
205 | |||
206 | if ($action == 'create' || $action == 'edit') { |
||
207 | // Status |
||
208 | $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell")); |
||
209 | $this->tpl['status'] = $form->selectarray('statut', $statutarray, $this->object->status); |
||
210 | |||
211 | $statutarray = array('1' => $langs->trans("ProductStatusOnBuy"), '0' => $langs->trans("ProductStatusNotOnBuy")); |
||
212 | $this->tpl['status_buy'] = $form->selectarray('statut_buy', $statutarray, $this->object->status_buy); |
||
213 | |||
214 | $this->tpl['description'] = $this->description; |
||
215 | $this->tpl['note'] = $this->note; |
||
216 | |||
217 | // Duration unit |
||
218 | // TODO creer fonction |
||
219 | $duration_unit = '<input name="duration_unit" type="radio" value="h"' . ($this->object->duration_unit == 'h' ? ' checked' : '') . '>' . $langs->trans("Hour"); |
||
220 | $duration_unit .= ' '; |
||
221 | $duration_unit .= '<input name="duration_unit" type="radio" value="d"' . ($this->object->duration_unit == 'd' ? ' checked' : '') . '>' . $langs->trans("Day"); |
||
222 | $duration_unit .= ' '; |
||
223 | $duration_unit .= '<input name="duration_unit" type="radio" value="w"' . ($this->object->duration_unit == 'w' ? ' checked' : '') . '>' . $langs->trans("Week"); |
||
224 | $duration_unit .= ' '; |
||
225 | $duration_unit .= '<input name="duration_unit" type="radio" value="m"' . ($this->object->duration_unit == 'm' ? ' checked' : '') . '>' . $langs->trans("Month"); |
||
226 | $duration_unit .= ' '; |
||
227 | $duration_unit .= '<input name="duration_unit" type="radio" value="y"' . ($this->object->duration_unit == 'y' ? ' checked' : '') . '>' . $langs->trans("Year"); |
||
228 | $this->tpl['duration_unit'] = $duration_unit; |
||
229 | } |
||
230 | |||
231 | if ($action == 'view') { |
||
232 | // Photo |
||
233 | $this->tpl['nblines'] = 4; |
||
234 | if ($this->object->is_photo_available($conf->service->multidir_output[$this->object->entity])) { |
||
235 | $this->tpl['photos'] = $this->object->show_photos('product', $conf->service->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80); |
||
236 | } |
||
237 | |||
238 | // Duration |
||
239 | $dur = array(); |
||
240 | if ($this->object->duration_value > 1) { |
||
241 | $dur = array("h" => $langs->trans("Hours"), "d" => $langs->trans("Days"), "w" => $langs->trans("Weeks"), "m" => $langs->trans("Months"), "y" => $langs->trans("Years")); |
||
242 | } elseif ($this->object->duration_value > 0) { |
||
243 | $dur = array("h" => $langs->trans("Hour"), "d" => $langs->trans("Day"), "w" => $langs->trans("Week"), "m" => $langs->trans("Month"), "y" => $langs->trans("Year")); |
||
244 | } |
||
245 | $this->tpl['duration_unit'] = $langs->trans($dur[$this->object->duration_unit]); |
||
246 | |||
247 | $this->tpl['fiche_end'] = dol_get_fiche_end(); |
||
248 | } |
||
300 |
This check looks for private methods that have been defined, but are not used inside the class.