Answer the question
In order to leave comments, you need to log in
Should the Request be passed to a service and/or a ValueObject, or just specific types?
I want to write clean code, but one that will meet the main standards.
1. Do I need to forward the request to the service and get the parameters I need in the service method and pass them to the ValueObject?
2. Do I need to pass $request to the ValueObject constructor?
I would like to receive detailed answers about my code. What can be improved here?
/**
* @Route("/{page}", name="vacancies", methods={"GET"}, defaults={"page" = 1}, requirements={"page"="\d+"})
* ...
*/
public function index(Request $request): Response
{
$form = $this->vacancyService->createForm();
$form->handleRequest($request);
$vacancies = $this->vacancyService->search(new VacancySearchValueObject(
$request->query->all()['vacancy_search'] ?? []),
new PaginationValueObject($request->attributes->get('page', null))
);
return $this->render('vacancy/index.html.twig', [
'vacancies' => $vacancies,
'searchForm' => $form->createView(),
'companies' => $this->companyService->getList()
]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question