| Conditions | 3 |
| Paths | 2 |
| Total Lines | 51 |
| Code Lines | 27 |
| 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 |
||
| 47 | public function index( |
||
| 48 | Request $request, |
||
| 49 | ImageRepository $imageRepository, |
||
| 50 | PaginatorInterface $paginator |
||
| 51 | ): Response { |
||
| 52 | /** @var ImageFilterData $filterData */ |
||
| 53 | $filterData = new ImageFilterData( |
||
| 54 | $imageRepository->getEarliestImageCaptureDate(), |
||
| 55 | $imageRepository->getLatestImageCaptureDate(), |
||
| 56 | ); |
||
| 57 | |||
| 58 | // These are overrides that can be sent by links set up on our |
||
| 59 | // charts on the Statistics page. If we get a location, star |
||
| 60 | // rating or start & end dates via those, we override our defaults. |
||
| 61 | $filterData->overrideLocationFromUrlParam((string) $request->query->get('location')); |
||
| 62 | $filterData->overrideRatingFromUrlParam($request->query->getInt('rating', -1)); |
||
| 63 | $filterData->overrideStartDateFromUrlParam((string) $request->query->get('periodStartDate')); |
||
| 64 | $filterData->overrideEndDateFromUrlParam((string) $request->query->get('periodEndDate')); |
||
| 65 | |||
| 66 | // Filtering form for the top of the page |
||
| 67 | $locationChoices = $this->getLocationChoices($imageRepository); |
||
| 68 | $filterForm = $this->createForm( |
||
| 69 | ImageFilterType::class, |
||
| 70 | $filterData, |
||
| 71 | [ |
||
| 72 | 'locations' => array_combine($locationChoices, array_values($locationChoices)), |
||
| 73 | 'csrf_protection' => false // We're just a GET request, and nothing bad happens no matter what you do. |
||
| 74 | ] |
||
| 75 | ); |
||
| 76 | |||
| 77 | $filterForm->handleRequest($request); |
||
| 78 | if ($filterForm->isSubmitted() && $filterForm->isValid()) { |
||
| 79 | $filterData = $filterForm->getData(); |
||
| 80 | }; |
||
| 81 | |||
| 82 | $qb = $imageRepository->getReversePaginatorQueryBuilder(); |
||
| 83 | |||
| 84 | $this->filterQuery($filterData, $qb); |
||
| 85 | |||
| 86 | $query = $qb->getQuery(); |
||
| 87 | |||
| 88 | $page = $request->query->getInt('page', 1); |
||
| 89 | $pagination = $paginator->paginate( |
||
| 90 | $query, |
||
| 91 | $page, |
||
| 92 | 20 |
||
| 93 | ); |
||
| 94 | |||
| 95 | return $this->render('image/index.html.twig', [ |
||
| 96 | 'image_pagination' => $pagination, |
||
| 97 | 'filter_form' => $filterForm->createView() |
||
| 98 | ]); |
||
| 160 |