Code Duplication    Length = 34-34 lines in 2 locations

src/Controller/Product/ShowProductCatalogByTaxonCodeAction.php 1 location

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

src/Controller/Product/ShowProductCatalogByTaxonSlugAction.php 1 location

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