Code Duplication    Length = 31-32 lines in 2 locations

src/Controller/Product/ShowProductReviewsByCodeAction.php 1 location

@@ 15-45 (lines=31) @@
12
use Symfony\Component\HttpFoundation\Response;
13
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
14
15
final class ShowProductReviewsByCodeAction
16
{
17
    /** @var ViewHandlerInterface */
18
    private $viewHandler;
19
20
    /** @var ProductReviewsViewRepositoryInterface */
21
    private $productReviewsViewRepository;
22
23
    public function __construct(
24
        ViewHandlerInterface $viewHandler,
25
        ProductReviewsViewRepositoryInterface $productReviewsViewRepository
26
    ) {
27
        $this->viewHandler = $viewHandler;
28
        $this->productReviewsViewRepository = $productReviewsViewRepository;
29
    }
30
31
    public function __invoke(Request $request): Response
32
    {
33
        if (!$request->query->has('channel')) {
34
            throw new NotFoundHttpException('Cannot find product without channel provided');
35
        }
36
37
        $page = $this->productReviewsViewRepository->getByProductCode(
38
            $request->attributes->get('code'),
39
            $request->query->get('channel'),
40
            new PaginatorDetails($request->attributes->get('_route'), $request->query->all())
41
        );
42
43
        return $this->viewHandler->handle(View::create($page, Response::HTTP_OK));
44
    }
45
}
46

src/Controller/Product/ShowProductReviewsBySlugAction.php 1 location

@@ 15-46 (lines=32) @@
12
use Symfony\Component\HttpFoundation\Response;
13
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
14
15
final class ShowProductReviewsBySlugAction
16
{
17
    /** @var ViewHandlerInterface */
18
    private $viewHandler;
19
20
    /** @var ProductReviewsViewRepositoryInterface */
21
    private $productReviewsViewRepository;
22
23
    public function __construct(
24
        ViewHandlerInterface $viewHandler,
25
        ProductReviewsViewRepositoryInterface $productReviewsViewRepository
26
    ) {
27
        $this->viewHandler = $viewHandler;
28
        $this->productReviewsViewRepository = $productReviewsViewRepository;
29
    }
30
31
    public function __invoke(Request $request): Response
32
    {
33
        if (!$request->query->has('channel')) {
34
            throw new NotFoundHttpException('Cannot find product without channel provided');
35
        }
36
37
        $page = $this->productReviewsViewRepository->getByProductSlug(
38
            $request->attributes->get('slug'),
39
            $request->query->get('channel'),
40
            new PaginatorDetails($request->attributes->get('_route'), $request->query->all()),
41
            $request->query->get('locale')
42
        );
43
44
        return $this->viewHandler->handle(View::create($page, Response::HTTP_OK));
45
    }
46
}
47