Conditions | 16 |
Paths | 1 |
Total Lines | 157 |
Code Lines | 102 |
Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
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 |
||
105 | public function configure(DataTable $dataTable, array $options): void |
||
106 | { |
||
107 | $resolver = new OptionsResolver(); |
||
108 | $this->configureOptions($resolver); |
||
109 | $options = $resolver->resolve($options); |
||
110 | |||
111 | |||
112 | $dataTable->add('symbol', TextColumn::class, [ |
||
113 | 'label' => '', |
||
114 | 'render' => function ($value, AbstractLogEntry $context) { |
||
115 | switch ($context->getLevelString()) { |
||
116 | case LogLevel::DEBUG: |
||
117 | $symbol = 'fa-bug'; |
||
118 | |||
119 | break; |
||
120 | case LogLevel::INFO: |
||
121 | $symbol = 'fa-info'; |
||
122 | |||
123 | break; |
||
124 | case LogLevel::NOTICE: |
||
125 | $symbol = 'fa-flag'; |
||
126 | |||
127 | break; |
||
128 | case LogLevel::WARNING: |
||
129 | $symbol = 'fa-exclamation-circle'; |
||
130 | |||
131 | break; |
||
132 | case LogLevel::ERROR: |
||
133 | $symbol = 'fa-exclamation-triangle'; |
||
134 | |||
135 | break; |
||
136 | case LogLevel::CRITICAL: |
||
137 | $symbol = 'fa-bolt'; |
||
138 | |||
139 | break; |
||
140 | case LogLevel::ALERT: |
||
141 | $symbol = 'fa-radiation'; |
||
142 | |||
143 | break; |
||
144 | case LogLevel::EMERGENCY: |
||
145 | $symbol = 'fa-skull-crossbones'; |
||
146 | |||
147 | break; |
||
148 | default: |
||
149 | $symbol = 'fa-question-circle'; |
||
150 | |||
151 | break; |
||
152 | } |
||
153 | |||
154 | return sprintf( |
||
155 | '<i class="fas fa-fw %s" title="%s"></i>', |
||
156 | $symbol, |
||
157 | $context->getLevelString() |
||
158 | ); |
||
159 | }, |
||
160 | ]); |
||
161 | |||
162 | $dataTable->add('id', TextColumn::class, [ |
||
163 | 'label' => $this->translator->trans('log.id'), |
||
164 | 'visible' => false, |
||
165 | ]); |
||
166 | |||
167 | $dataTable->add('timestamp', LocaleDateTimeColumn::class, [ |
||
168 | 'label' => $this->translator->trans('log.timestamp'), |
||
169 | 'timeFormat' => 'medium', |
||
170 | ]); |
||
171 | |||
172 | $dataTable->add('type', TextColumn::class, [ |
||
173 | 'label' => $this->translator->trans('log.type'), |
||
174 | 'propertyPath' => 'type', |
||
175 | 'render' => function (string $value, AbstractLogEntry $context) { |
||
|
|||
176 | return $this->translator->trans('log.type.'.$value); |
||
177 | }, |
||
178 | ]); |
||
179 | |||
180 | $dataTable->add('level', TextColumn::class, [ |
||
181 | 'label' => $this->translator->trans('log.level'), |
||
182 | 'visible' => $options['mode'] === 'system_log', |
||
183 | 'propertyPath' => 'levelString', |
||
184 | 'render' => function (string $value, AbstractLogEntry $context) { |
||
185 | return $value; |
||
186 | }, |
||
187 | ]); |
||
188 | |||
189 | $dataTable->add('user', TextColumn::class, [ |
||
190 | 'label' => $this->translator->trans('log.user'), |
||
191 | 'render' => function ($value, AbstractLogEntry $context) { |
||
192 | $user = $context->getUser(); |
||
193 | |||
194 | return sprintf( |
||
195 | '<a href="%s">%s</a>', |
||
196 | $this->urlGenerator->generate('user_info', ['id' => $user->getID()]), |
||
197 | $user->getFullName(true) |
||
198 | ); |
||
199 | }, |
||
200 | ]); |
||
201 | |||
202 | $dataTable->add('target_type', TextColumn::class, [ |
||
203 | 'label' => $this->translator->trans('log.target_type'), |
||
204 | 'visible' => false, |
||
205 | 'render' => function ($value, AbstractLogEntry $context) { |
||
206 | $class = $context->getTargetClass(); |
||
207 | if (null !== $class) { |
||
208 | return $this->elementTypeNameGenerator->getLocalizedTypeLabel($class); |
||
209 | } |
||
210 | |||
211 | return ''; |
||
212 | }, |
||
213 | ]); |
||
214 | |||
215 | $dataTable->add('target', LogEntryTargetColumn::class, [ |
||
216 | 'label' => $this->translator->trans('log.target'), |
||
217 | ]); |
||
218 | |||
219 | $dataTable->add('extra', LogEntryExtraColumn::class, [ |
||
220 | 'label' => $this->translator->trans('log.extra'), |
||
221 | ]); |
||
222 | |||
223 | $dataTable->add('timeTravel', IconLinkColumn::class,[ |
||
224 | 'label' => '', |
||
225 | 'icon' => 'fas fa-fw fa-eye', |
||
226 | 'href' => function ($value, AbstractLogEntry $context) { |
||
227 | if ( |
||
228 | ($context instanceof TimeTravelInterface |
||
229 | && $context->hasOldDataInformations()) |
||
230 | || $context instanceof CollectionElementDeleted |
||
231 | ) { |
||
232 | try { |
||
233 | $target = $this->logRepo->getTargetElement($context); |
||
234 | if($target !== null) { |
||
235 | $str = $this->entityURLGenerator->timeTravelURL($target, $context->getTimestamp()); |
||
236 | return $str; |
||
237 | } |
||
238 | } catch (EntityNotSupportedException $exception) { |
||
239 | return null; |
||
240 | } |
||
241 | } |
||
242 | return null; |
||
243 | }, |
||
244 | 'disabled' => function ($value, AbstractLogEntry $context) { |
||
245 | return |
||
246 | !$this->security->isGranted('@tools.timetravel') |
||
247 | || !$this->security->isGranted('show_history', $context->getTargetClass()); |
||
248 | } |
||
249 | |||
250 | ]); |
||
251 | |||
252 | $dataTable->add('actionRevert', RevertLogColumn::class, [ |
||
253 | 'label' => '' |
||
254 | ]); |
||
255 | |||
256 | $dataTable->addOrderBy('timestamp', DataTable::SORT_DESCENDING); |
||
257 | |||
258 | $dataTable->createAdapter(ORMAdapter::class, [ |
||
259 | 'entity' => AbstractLogEntry::class, |
||
260 | 'query' => function (QueryBuilder $builder) use ($options): void { |
||
261 | $this->getQuery($builder, $options); |
||
262 | }, |
||
297 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.