Conditions | 8 |
Paths | 1 |
Total Lines | 110 |
Code Lines | 66 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
58 | public function configure(DataTable $dataTable, array $options) |
||
59 | { |
||
60 | $dataTable |
||
61 | //->add('select', SelectColumn::class) |
||
62 | ->add('picture', TextColumn::class, [ |
||
63 | 'label' => '', |
||
64 | 'className' => 'no-colvis', |
||
65 | 'render' => function ($value, ProjectBOMEntry $context) { |
||
66 | if($context->getPart() === null) { |
||
67 | return ''; |
||
68 | } |
||
69 | return $this->partDataTableHelper->renderPicture($context->getPart()); |
||
70 | }, |
||
71 | ]) |
||
72 | |||
73 | ->add('id', TextColumn::class, [ |
||
74 | 'label' => $this->translator->trans('part.table.id'), |
||
75 | 'visible' => false, |
||
76 | ]) |
||
77 | |||
78 | ->add('quantity', TextColumn::class, [ |
||
79 | 'label' => $this->translator->trans('project.bom.quantity'), |
||
80 | 'className' => 'text-center', |
||
81 | 'render' => function ($value, ProjectBOMEntry $context) { |
||
82 | //If we have a non-part entry, only show the rounded quantity |
||
83 | if ($context->getPart() === null) { |
||
84 | return round($context->getQuantity()); |
||
85 | } |
||
86 | //Otherwise use the unit of the part to format the quantity |
||
87 | return $this->amountFormatter->format($context->getQuantity(), $context->getPart()->getPartUnit()); |
||
88 | }, |
||
89 | ]) |
||
90 | |||
91 | ->add('name', TextColumn::class, [ |
||
92 | 'label' => $this->translator->trans('part.table.name'), |
||
93 | 'orderable' => false, |
||
94 | 'render' => function ($value, ProjectBOMEntry $context) { |
||
95 | if($context->getPart() === null) { |
||
96 | return $context->getName(); |
||
97 | } |
||
98 | if($context->getPart() !== null) { |
||
99 | $tmp = $this->partDataTableHelper->renderName($context->getPart()); |
||
100 | if(!empty($context->getName())) { |
||
101 | $tmp .= '<br><b>'.htmlspecialchars($context->getName()).'</b>'; |
||
102 | } |
||
103 | return $tmp; |
||
104 | } |
||
105 | throw new \Exception('This should never happen!'); |
||
106 | }, |
||
107 | ]) |
||
108 | |||
109 | ->add('description', MarkdownColumn::class, [ |
||
110 | 'label' => $this->translator->trans('part.table.description'), |
||
111 | 'data' => function (ProjectBOMEntry $context) { |
||
112 | if($context->getPart() !== null) { |
||
113 | return $context->getPart()->getDescription(); |
||
114 | } |
||
115 | //For non-part BOM entries show the comment field |
||
116 | return $context->getComment(); |
||
117 | }, |
||
118 | ]) |
||
119 | |||
120 | |||
121 | ->add('category', EntityColumn::class, [ |
||
122 | 'label' => $this->translator->trans('part.table.category'), |
||
123 | 'property' => 'part.category', |
||
124 | ]) |
||
125 | ->add('footprint', EntityColumn::class, [ |
||
126 | 'property' => 'part.footprint', |
||
127 | 'label' => $this->translator->trans('part.table.footprint'), |
||
128 | ]) |
||
129 | |||
130 | ->add('manufacturer', EntityColumn::class, [ |
||
131 | 'property' => 'part.manufacturer', |
||
132 | 'label' => $this->translator->trans('part.table.manufacturer'), |
||
133 | ]) |
||
134 | |||
135 | ->add('mountnames', TextColumn::class, [ |
||
136 | 'label' => 'project.bom.mountnames', |
||
137 | 'render' => function ($value, ProjectBOMEntry $context) { |
||
138 | $html = ''; |
||
139 | |||
140 | foreach (explode(',', $context->getMountnames()) as $mountname) { |
||
141 | $html .= sprintf('<span class="badge badge-secondary bg-secondary">%s</span> ', htmlspecialchars($mountname)); |
||
142 | } |
||
143 | return $html; |
||
144 | }, |
||
145 | ]) |
||
146 | |||
147 | |||
148 | ->add('addedDate', LocaleDateTimeColumn::class, [ |
||
149 | 'label' => $this->translator->trans('part.table.addedDate'), |
||
150 | 'visible' => false, |
||
151 | ]) |
||
152 | ->add('lastModified', LocaleDateTimeColumn::class, [ |
||
153 | 'label' => $this->translator->trans('part.table.lastModified'), |
||
154 | 'visible' => false, |
||
155 | ]) |
||
156 | ; |
||
157 | |||
158 | $dataTable->createAdapter(ORMAdapter::class, [ |
||
159 | 'entity' => Attachment::class, |
||
160 | 'query' => function (QueryBuilder $builder) use ($options): void { |
||
161 | $this->getQuery($builder, $options); |
||
162 | }, |
||
163 | 'criteria' => [ |
||
164 | function (QueryBuilder $builder) use ($options): void { |
||
165 | $this->buildCriteria($builder, $options); |
||
166 | }, |
||
167 | new SearchCriteriaProvider(), |
||
168 | ], |
||
187 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.