Conditions | 11 |
Paths | 59 |
Total Lines | 52 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
27 | public function showEntityHistoryAction(Request $request, Reader $reader, string $entity, $id = null): Response |
||
28 | { |
||
29 | $entity = UrlHelper::paramToNamespace($entity); |
||
30 | |||
31 | if (!$reader->getProvider()->isAuditable($entity)) { |
||
32 | throw $this->createNotFoundException(); |
||
33 | } |
||
34 | |||
35 | $supportedFilters = Query::getSupportedFilters(); |
||
|
|||
36 | $form = $this->createForm(FilterForm::class); |
||
37 | |||
38 | $form->handleRequest($request); |
||
39 | |||
40 | try { |
||
41 | $page = (int) $form->get('page')->getData(); |
||
42 | $page = $page < 1 ? 1 : $page; |
||
43 | $query = $reader->createQuery($entity, [ |
||
44 | 'object_id' => $id, |
||
45 | 'page' => $page, |
||
46 | 'page_size' => Reader::PAGE_SIZE, |
||
47 | ]); |
||
48 | |||
49 | if ($form->isSubmitted() && $form->isValid()) { |
||
50 | $min = $form->get('created_at_start')->getData(); |
||
51 | $max = $form->get('created_at_end')->getData(); |
||
52 | |||
53 | if ($min || $max) { |
||
54 | $query->addFilter(new DateRangeFilter('created_at', $min, $max)); |
||
55 | } |
||
56 | foreach ($form->all() as $field) { |
||
57 | $data = $field->getData(); |
||
58 | if (!$data || \in_array($field->getName(), ['page', 'created_at_start', 'created_at_end'])) { |
||
59 | continue; |
||
60 | } |
||
61 | dump($field->getName()); |
||
62 | dump($data); |
||
63 | $query->addFilter(new SimpleFilter($field->getName(), $data)); |
||
64 | } |
||
65 | } |
||
66 | |||
67 | $pager = $reader->paginate($query, $page, Reader::PAGE_SIZE); |
||
68 | } catch (AccessDeniedException $e) { |
||
69 | throw $this->createAccessDeniedException(); |
||
70 | } |
||
71 | |||
72 | return $this->render('@DHAuditor/Audit/entity_history.html.twig', [ |
||
73 | 'id' => $id, |
||
74 | 'entity' => $entity, |
||
75 | 'paginator' => $pager, |
||
76 | 'supportedFilters' => $supportedFilters, |
||
77 | 'form' => $form->createView(), |
||
78 | 'page' => $form->get('page')->getData(), |
||
79 | ]); |
||
82 |