Code Duplication    Length = 34-34 lines in 2 locations

src/Controller/Product/ShowProductCatalogByTaxonCodeAction.php 1 location

@@ 15-48 (lines=34) @@
12
use Symfony\Component\HttpFoundation\Response;
13
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
14
15
final class ShowProductCatalogByTaxonCodeAction
16
{
17
    /** @var ViewHandlerInterface */
18
    private $viewHandler;
19
20
    /** @var ProductCatalogViewRepositoryInterface */
21
    private $productCatalogQuery;
22
23
    public function __construct(
24
        ViewHandlerInterface $viewHandler,
25
        ProductCatalogViewRepositoryInterface $productCatalogQuery
26
    ) {
27
        $this->viewHandler = $viewHandler;
28
        $this->productCatalogQuery = $productCatalogQuery;
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
        try {
38
            return $this->viewHandler->handle(View::create($this->productCatalogQuery->findByTaxonCode(
39
                $request->attributes->get('code'),
40
                $request->query->get('channel'),
41
                new PaginatorDetails($request->attributes->get('_route'), $request->query->all()),
42
                $request->query->get('locale')
43
            ), Response::HTTP_OK));
44
        } catch (\InvalidArgumentException $exception) {
45
            throw new NotFoundHttpException($exception->getMessage());
46
        }
47
    }
48
}
49

src/Controller/Product/ShowProductCatalogByTaxonSlugAction.php 1 location

@@ 15-48 (lines=34) @@
12
use Symfony\Component\HttpFoundation\Response;
13
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
14
15
final class ShowProductCatalogByTaxonSlugAction
16
{
17
    /** @var ViewHandlerInterface */
18
    private $viewHandler;
19
20
    /** @var ProductCatalogViewRepositoryInterface */
21
    private $productCatalogQuery;
22
23
    public function __construct(
24
        ViewHandlerInterface $viewHandler,
25
        ProductCatalogViewRepositoryInterface $productCatalogQuery
26
    ) {
27
        $this->viewHandler = $viewHandler;
28
        $this->productCatalogQuery = $productCatalogQuery;
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
        try {
38
            return $this->viewHandler->handle(View::create($this->productCatalogQuery->findByTaxonSlug(
39
                $request->attributes->get('taxonSlug'),
40
                $request->query->get('channel'),
41
                new PaginatorDetails($request->attributes->get('_route'), $request->query->all()),
42
                $request->query->get('locale')
43
            ), Response::HTTP_OK));
44
        } catch (\InvalidArgumentException $exception) {
45
            throw new NotFoundHttpException($exception->getMessage());
46
        }
47
    }
48
}
49