| Conditions | 1 |
| Paths | 1 |
| Total Lines | 103 |
| Code Lines | 76 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 101 | public function configure(DataTable $dataTable, array $options) |
||
| 102 | { |
||
| 103 | $dataTable |
||
| 104 | ->add('name', TextColumn::class, [ |
||
| 105 | 'label' => $this->translator->trans('part.table.name'), |
||
| 106 | 'render' => function ($value, Part $context) { |
||
| 107 | return $this->urlGenerator->infoHTML($context); |
||
| 108 | }, |
||
| 109 | ]) |
||
| 110 | ->add('id', TextColumn::class, [ |
||
| 111 | 'label' => $this->translator->trans('part.table.id'), |
||
| 112 | 'visible' => false |
||
| 113 | ]) |
||
| 114 | ->add('description', TextColumn::class, [ |
||
| 115 | 'label' => $this->translator->trans('part.table.description'), |
||
| 116 | ]) |
||
| 117 | ->add('category', TextColumn::class, [ |
||
| 118 | 'field' => 'category.name', |
||
| 119 | 'label' => $this->translator->trans('part.table.category') |
||
| 120 | ]) |
||
| 121 | ->add('footprint', TextColumn::class, [ |
||
| 122 | 'field' => 'footprint.name', |
||
| 123 | 'label' => $this->translator->trans('part.table.footprint') |
||
| 124 | ]) |
||
| 125 | ->add('manufacturer', TextColumn::class, [ |
||
| 126 | 'field' => 'manufacturer.name', |
||
| 127 | 'label' => $this->translator->trans('part.table.manufacturer') |
||
| 128 | ]) |
||
| 129 | //->add('footprint', TextColumn::class, ['field' => 'footprint.name']) |
||
| 130 | //->add('manufacturer', TextColumn::class, ['field' => 'manufacturer.name' ]) |
||
| 131 | //->add('amountSum', TextColumn::class, ['label' => 'instock.label_short']) |
||
| 132 | ->add('amount', TextColumn::class, [ |
||
| 133 | 'label' => $this->translator->trans('part.table.amount'), |
||
| 134 | 'propertyPath' => 'amountSum' |
||
| 135 | ]) |
||
| 136 | ->add('minamount', TextColumn::class, [ |
||
| 137 | 'label' => $this->translator->trans('part.table.minamount'), |
||
| 138 | 'visible' => false |
||
| 139 | ]) |
||
| 140 | ->add('partUnit', TextColumn::class, [ |
||
| 141 | 'field' => 'partUnit.name', |
||
| 142 | 'label' => $this->translator->trans('part.table.partUnit'), |
||
| 143 | 'visible' => false |
||
| 144 | ]) |
||
| 145 | ->add('addedDate', LocaleDateTimeColumn::class, [ |
||
| 146 | 'label' => $this->translator->trans('part.table.addedDate'), |
||
| 147 | 'visible' => false |
||
| 148 | ]) |
||
| 149 | ->add('lastModified', LocaleDateTimeColumn::class, [ |
||
| 150 | 'label' => $this->translator->trans('part.table.lastModified'), |
||
| 151 | 'visible' => false |
||
| 152 | ]) |
||
| 153 | ->add('needs_review', BoolColumn::class, [ |
||
| 154 | 'label' => $this->translator->trans('part.table.needsReview'), |
||
| 155 | 'trueValue' => $this->translator->trans('true'), |
||
| 156 | 'falseValue' => $this->translator->trans('false'), |
||
| 157 | 'nullValue' => '', |
||
| 158 | 'visible' => false |
||
| 159 | ]) |
||
| 160 | ->add('favorite', BoolColumn::class, [ |
||
| 161 | 'label' => $this->translator->trans('part.table.favorite'), |
||
| 162 | 'trueValue' => $this->translator->trans('true'), |
||
| 163 | 'falseValue' => $this->translator->trans('false'), |
||
| 164 | 'nullValue' => '', |
||
| 165 | 'visible' => false |
||
| 166 | ]) |
||
| 167 | ->add('manufacturing_status', MapColumn::class, [ |
||
| 168 | 'label' => $this->translator->trans('part.table.manufacturingStatus'), |
||
| 169 | 'visible' => false, |
||
| 170 | 'default' => $this->translator->trans('m_status.unknown'), |
||
| 171 | 'map' => [ |
||
| 172 | '' => $this->translator->trans('m_status.unknown'), |
||
| 173 | 'announced' => $this->translator->trans('m_status.announced'), |
||
| 174 | 'active' => $this->translator->trans('m_status.active'), |
||
| 175 | 'nrfnd' => $this->translator->trans('m_status.nrfnd'), |
||
| 176 | 'eol' => $this->translator->trans('m_status.eol'), |
||
| 177 | 'discontinued' => $this->translator->trans('m_status.discontinued') |
||
| 178 | ] |
||
| 179 | ]) |
||
| 180 | ->add('manufacturer_product_number', TextColumn::class, [ |
||
| 181 | 'label' => $this->translator->trans('part.table.mpn'), |
||
| 182 | 'visible' => false |
||
| 183 | ]) |
||
| 184 | ->add('mass', TextColumn::class, [ |
||
| 185 | 'label' => $this->translator->trans('part.table.mass'), |
||
| 186 | 'visible' => false |
||
| 187 | ]) |
||
| 188 | ->add('tags', TextColumn::class, [ |
||
| 189 | 'label' => $this->translator->trans('part.table.tags'), |
||
| 190 | 'visible' => false |
||
| 191 | ]) |
||
| 192 | |||
| 193 | ->addOrderBy('name') |
||
| 194 | ->createAdapter(ORMAdapter::class, [ |
||
| 195 | 'query' => function(QueryBuilder $builder) { |
||
| 196 | $this->getQuery($builder); |
||
| 197 | }, |
||
| 198 | 'entity' => Part::class, |
||
| 199 | 'criteria' => [ |
||
| 200 | function (QueryBuilder $builder) use ($options) { |
||
| 201 | $this->buildCriteria($builder, $options); |
||
| 202 | }, |
||
| 203 | new SearchCriteriaProvider() |
||
| 204 | ] |
||
| 208 |