Conditions | 8 |
Paths | 1 |
Total Lines | 138 |
Code Lines | 91 |
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 |
||
81 | public function configure(DataTable $dataTable, array $options) |
||
82 | { |
||
83 | $dataTable->add('picture', TextColumn::class, [ |
||
84 | 'label' => '', |
||
85 | 'render' => function ($value, Attachment $context) { |
||
86 | if ($context->isPicture() |
||
87 | && !$context->isExternal() |
||
88 | && $this->attachmentHelper->isFileExisting($context)) { |
||
89 | return sprintf( |
||
90 | '<img alt="%s" src="%s" class="%s">', |
||
91 | 'Part image', |
||
92 | $this->entityURLGenerator->viewURL($context), |
||
93 | 'img-fluid hoverpic' |
||
94 | ); |
||
95 | } |
||
96 | |||
97 | return ''; |
||
98 | } |
||
99 | ]); |
||
100 | |||
101 | $dataTable->add('name', TextColumn::class, [ |
||
102 | 'label' => $this->translator->trans('attachment.edit.name'), |
||
103 | 'render' => function ($value, Attachment $context) { |
||
104 | //Link to external source |
||
105 | if ($context->isExternal()) { |
||
106 | return sprintf( |
||
107 | '<a href="%s" class="link-external">%s</a>', |
||
108 | htmlspecialchars($context->getURL()), |
||
109 | htmlspecialchars($value) |
||
110 | ); |
||
111 | } |
||
112 | |||
113 | if ($this->attachmentHelper->isFileExisting($context)) { |
||
114 | return sprintf( |
||
115 | '<a href="%s" target="_blank" data-no-ajax>%s</a>', |
||
116 | $this->entityURLGenerator->viewURL($context), |
||
117 | htmlspecialchars($value) |
||
118 | ); |
||
119 | } |
||
120 | |||
121 | return $value; |
||
122 | } |
||
123 | ]); |
||
124 | |||
125 | $dataTable->add('attachment_type', TextColumn::class, [ |
||
126 | 'field' => 'attachment_type.name', |
||
127 | 'render' => function ($value, Attachment $context) { |
||
128 | return sprintf( |
||
129 | '<a href="%s">%s</a>', |
||
130 | $this->entityURLGenerator->editURL($context->getAttachmentType()), |
||
131 | htmlspecialchars($value) |
||
132 | ); |
||
133 | } |
||
134 | ]); |
||
135 | |||
136 | $dataTable->add('element', TextColumn::class, [ |
||
137 | 'label' => $this->translator->trans('attachment.table.element'), |
||
138 | //'propertyPath' => 'element.name', |
||
139 | 'render' => function ($value, Attachment $context) { |
||
140 | return sprintf( |
||
141 | '<a href="%s">%s</a>', |
||
142 | $this->entityURLGenerator->infoURL($context->getElement()), |
||
|
|||
143 | $this->elementTypeNameGenerator->getTypeNameCombination($context->getElement(), true) |
||
144 | ); |
||
145 | } |
||
146 | ]); |
||
147 | |||
148 | $dataTable->add('filename', TextColumn::class, [ |
||
149 | 'propertyPath' => 'filename' |
||
150 | ]); |
||
151 | |||
152 | $dataTable->add('filesize', TextColumn::class, [ |
||
153 | 'render' => function ($value, Attachment $context) { |
||
154 | if ($this->attachmentHelper->isFileExisting($context)) { |
||
155 | return $this->attachmentHelper->getHumanFileSize($context); |
||
156 | } |
||
157 | if ($context->isExternal()) { |
||
158 | return '<i>' . $this->translator->trans('attachment.external') . '</i>'; |
||
159 | } |
||
160 | |||
161 | return sprintf( |
||
162 | '<span class="badge badge-warning"> |
||
163 | <i class="fas fa-exclamation-circle fa-fw"></i>%s |
||
164 | </span>', |
||
165 | $this->translator->trans('attachment.file_not_found') |
||
166 | ); |
||
167 | } |
||
168 | ]); |
||
169 | |||
170 | $dataTable |
||
171 | ->add('addedDate', LocaleDateTimeColumn::class, [ |
||
172 | 'label' => $this->translator->trans('part.table.addedDate'), |
||
173 | 'visible' => false |
||
174 | ]) |
||
175 | ->add('lastModified', LocaleDateTimeColumn::class, [ |
||
176 | 'label' => $this->translator->trans('part.table.lastModified'), |
||
177 | 'visible' => false |
||
178 | ]); |
||
179 | |||
180 | $dataTable->add('show_in_table', BoolColumn::class, [ |
||
181 | 'label' => $this->translator->trans('attachment.edit.show_in_table'), |
||
182 | 'trueValue' => $this->translator->trans('true'), |
||
183 | 'falseValue' => $this->translator->trans('false'), |
||
184 | 'nullValue' => '', |
||
185 | 'visible' => false |
||
186 | ]); |
||
187 | |||
188 | $dataTable->add('isPicture', BoolColumn::class, [ |
||
189 | 'label' => $this->translator->trans('attachment.edit.isPicture'), |
||
190 | 'trueValue' => $this->translator->trans('true'), |
||
191 | 'falseValue' => $this->translator->trans('false'), |
||
192 | 'nullValue' => '', |
||
193 | 'visible' => false, |
||
194 | 'propertyPath' => 'picture' |
||
195 | ]); |
||
196 | |||
197 | $dataTable->add('is3DModel', BoolColumn::class, [ |
||
198 | 'label' => $this->translator->trans('attachment.edit.is3DModel'), |
||
199 | 'trueValue' => $this->translator->trans('true'), |
||
200 | 'falseValue' => $this->translator->trans('false'), |
||
201 | 'nullValue' => '', |
||
202 | 'visible' => false, |
||
203 | 'propertyPath' => '3dmodel' |
||
204 | ]); |
||
205 | |||
206 | $dataTable->add('isBuiltin', BoolColumn::class, [ |
||
207 | 'label' => $this->translator->trans('attachment.edit.isBuiltin'), |
||
208 | 'trueValue' => $this->translator->trans('true'), |
||
209 | 'falseValue' => $this->translator->trans('false'), |
||
210 | 'nullValue' => '', |
||
211 | 'visible' => false, |
||
212 | 'propertyPath' => 'builtin' |
||
213 | ]); |
||
214 | |||
215 | $dataTable->createAdapter(ORMAdapter::class, [ |
||
216 | 'entity' => Attachment::class, |
||
217 | 'query' => function (QueryBuilder $builder) { |
||
218 | $this->getQuery($builder); |
||
219 | }, |
||
222 | } |