Conditions | 4 |
Paths | 1 |
Total Lines | 156 |
Code Lines | 114 |
Lines | 0 |
Ratio | 0 % |
Changes | 9 | ||
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 |
||
143 | public function configure(DataTable $dataTable, array $options): void |
||
144 | { |
||
145 | $resolver = new OptionsResolver(); |
||
146 | $this->configureOptions($resolver); |
||
147 | $options = $resolver->resolve($options); |
||
148 | |||
149 | $dataTable |
||
150 | ->add('picture', TextColumn::class, [ |
||
151 | 'label' => '', |
||
152 | 'render' => function ($value, Part $context) { |
||
153 | $preview_attachment = $this->previewGenerator->getTablePreviewAttachment($context); |
||
154 | if (null === $preview_attachment) { |
||
155 | return ''; |
||
156 | } |
||
157 | |||
158 | return sprintf( |
||
159 | '<img alt="%s" src="%s" data-thumbnail="%s" class="%s">', |
||
160 | 'Part image', |
||
161 | $this->attachmentURLGenerator->getThumbnailURL($preview_attachment), |
||
162 | $this->attachmentURLGenerator->getThumbnailURL($preview_attachment, 'thumbnail_md'), |
||
163 | 'img-fluid hoverpic' |
||
164 | ); |
||
165 | }, |
||
166 | ]) |
||
167 | ->add('name', TextColumn::class, [ |
||
168 | 'label' => $this->translator->trans('part.table.name'), |
||
169 | 'render' => function ($value, Part $context) { |
||
170 | return sprintf( |
||
171 | '<a href="%s">%s</a>', |
||
172 | $this->urlGenerator->infoURL($context), |
||
173 | $context->getName() |
||
174 | ); |
||
175 | }, |
||
176 | ]) |
||
177 | ->add('id', TextColumn::class, [ |
||
178 | 'label' => $this->translator->trans('part.table.id'), |
||
179 | 'visible' => false, |
||
180 | ]) |
||
181 | ->add('description', MarkdownColumn::class, [ |
||
182 | 'label' => $this->translator->trans('part.table.description'), |
||
183 | ]) |
||
184 | ->add('category', EntityColumn::class, [ |
||
185 | 'label' => $this->translator->trans('part.table.category'), |
||
186 | 'property' => 'category', |
||
187 | ]) |
||
188 | ->add('footprint', EntityColumn::class, [ |
||
189 | 'property' => 'footprint', |
||
190 | 'label' => $this->translator->trans('part.table.footprint'), |
||
191 | ]) |
||
192 | ->add('manufacturer', EntityColumn::class, [ |
||
193 | 'property' => 'manufacturer', |
||
194 | 'label' => $this->translator->trans('part.table.manufacturer'), |
||
195 | ]) |
||
196 | ->add('storelocation', TextColumn::class, [ |
||
197 | 'label' => $this->translator->trans('part.table.storeLocations'), |
||
198 | 'render' => function ($value, Part $context) { |
||
199 | $tmp = []; |
||
200 | foreach ($context->getPartLots() as $lot) { |
||
201 | //Ignore lots without storelocation |
||
202 | if (null === $lot->getStorageLocation()) { |
||
203 | continue; |
||
204 | } |
||
205 | $tmp[] = sprintf( |
||
206 | '<a href="%s">%s</a>', |
||
207 | $this->urlGenerator->listPartsURL($lot->getStorageLocation()), |
||
208 | $lot->getStorageLocation()->getName() |
||
209 | ); |
||
210 | } |
||
211 | |||
212 | return implode('<br>', $tmp); |
||
213 | }, |
||
214 | ]) |
||
215 | ->add('amount', TextColumn::class, [ |
||
216 | 'label' => $this->translator->trans('part.table.amount'), |
||
217 | 'render' => function ($value, Part $context) { |
||
218 | $amount = $context->getAmountSum(); |
||
219 | |||
220 | return $this->amountFormatter->format($amount, $context->getPartUnit()); |
||
221 | }, |
||
222 | ]) |
||
223 | ->add('minamount', TextColumn::class, [ |
||
224 | 'label' => $this->translator->trans('part.table.minamount'), |
||
225 | 'visible' => false, |
||
226 | 'render' => function ($value, Part $context) { |
||
227 | return $this->amountFormatter->format($value, $context->getPartUnit()); |
||
228 | }, |
||
229 | ]) |
||
230 | ->add('partUnit', TextColumn::class, [ |
||
231 | 'field' => 'partUnit.name', |
||
232 | 'label' => $this->translator->trans('part.table.partUnit'), |
||
233 | 'visible' => false, |
||
234 | ]) |
||
235 | ->add('addedDate', LocaleDateTimeColumn::class, [ |
||
236 | 'label' => $this->translator->trans('part.table.addedDate'), |
||
237 | 'visible' => false, |
||
238 | ]) |
||
239 | ->add('lastModified', LocaleDateTimeColumn::class, [ |
||
240 | 'label' => $this->translator->trans('part.table.lastModified'), |
||
241 | 'visible' => false, |
||
242 | ]) |
||
243 | ->add('needs_review', BoolColumn::class, [ |
||
244 | 'label' => $this->translator->trans('part.table.needsReview'), |
||
245 | 'trueValue' => $this->translator->trans('true'), |
||
246 | 'falseValue' => $this->translator->trans('false'), |
||
247 | 'nullValue' => '', |
||
248 | 'visible' => false, |
||
249 | ]) |
||
250 | ->add('favorite', BoolColumn::class, [ |
||
251 | 'label' => $this->translator->trans('part.table.favorite'), |
||
252 | 'trueValue' => $this->translator->trans('true'), |
||
253 | 'falseValue' => $this->translator->trans('false'), |
||
254 | 'nullValue' => '', |
||
255 | 'visible' => false, |
||
256 | ]) |
||
257 | ->add('manufacturing_status', MapColumn::class, [ |
||
258 | 'label' => $this->translator->trans('part.table.manufacturingStatus'), |
||
259 | 'visible' => false, |
||
260 | 'default' => $this->translator->trans('m_status.unknown'), |
||
261 | 'map' => [ |
||
262 | '' => $this->translator->trans('m_status.unknown'), |
||
263 | 'announced' => $this->translator->trans('m_status.announced'), |
||
264 | 'active' => $this->translator->trans('m_status.active'), |
||
265 | 'nrfnd' => $this->translator->trans('m_status.nrfnd'), |
||
266 | 'eol' => $this->translator->trans('m_status.eol'), |
||
267 | 'discontinued' => $this->translator->trans('m_status.discontinued'), |
||
268 | ], |
||
269 | ]) |
||
270 | ->add('manufacturer_product_number', TextColumn::class, [ |
||
271 | 'label' => $this->translator->trans('part.table.mpn'), |
||
272 | 'visible' => false, |
||
273 | ]) |
||
274 | ->add('mass', TextColumn::class, [ |
||
275 | 'label' => $this->translator->trans('part.table.mass'), |
||
276 | 'visible' => false, |
||
277 | ]) |
||
278 | ->add('tags', TagsColumn::class, [ |
||
279 | 'label' => $this->translator->trans('part.table.tags'), |
||
280 | 'visible' => false, |
||
281 | ]) |
||
282 | ->add('attachments', PartAttachmentsColumn::class, [ |
||
283 | 'label' => $this->translator->trans('part.table.attachments'), |
||
284 | 'visible' => false, |
||
285 | ]) |
||
286 | |||
287 | ->addOrderBy('name') |
||
288 | ->createAdapter(FetchJoinORMAdapter::class, [ |
||
289 | 'simple_total_query' => true, |
||
290 | 'query' => function (QueryBuilder $builder): void { |
||
291 | $this->getQuery($builder); |
||
292 | }, |
||
293 | 'entity' => Part::class, |
||
294 | 'criteria' => [ |
||
295 | function (QueryBuilder $builder) use ($options): void { |
||
296 | $this->buildCriteria($builder, $options); |
||
297 | }, |
||
298 | new SearchCriteriaProvider(), |
||
299 | ], |
||
471 |