Completed
Pull Request — master (#180)
by Łukasz
05:27 queued 02:14
created

ShowProductReviewsBySlugAction::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
3
namespace Sylius\ShopApiPlugin\Controller\Product;
4
5
use FOS\RestBundle\View\View;
6
use FOS\RestBundle\View\ViewHandlerInterface;
7
use Sylius\ShopApiPlugin\Model\PaginatorDetails;
8
use Sylius\ShopApiPlugin\ViewRepository\ProductReviewsViewRepositoryInterface;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
12
13 View Code Duplication
final class ShowProductReviewsBySlugAction
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    /** @var ViewHandlerInterface */
16
    private $viewHandler;
17
18
    /** @var ProductReviewsViewRepositoryInterface */
19
    private $productReviewsViewRepository;
20
21
    public function __construct(
22
        ViewHandlerInterface $viewHandler,
23
        ProductReviewsViewRepositoryInterface $productReviewsViewRepository
24
    ) {
25
        $this->viewHandler = $viewHandler;
26
        $this->productReviewsViewRepository = $productReviewsViewRepository;
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
        $page = $this->productReviewsViewRepository->getByProductSlug(
36
            $request->attributes->get('slug'),
37
            $request->query->get('locale'),
38
            $request->query->get('channel'),
39
            new PaginatorDetails($request->attributes->get('_route'), $request->query->all())
40
        );
41
42
        return $this->viewHandler->handle(View::create($page, Response::HTTP_OK));
43
    }
44
}
45