ProductVariantIndexAction::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 6
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusLagersystemPlugin\Controller\Product;
6
7
use FOS\RestBundle\View\View;
8
use FOS\RestBundle\View\ViewHandlerInterface;
9
use Setono\SyliusLagersystemPlugin\Model\PaginatorDetails;
10
use Setono\SyliusLagersystemPlugin\ViewRepository\Product\ProductVariantViewRepositoryInterface;
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\HttpFoundation\Response;
13
14
final class ProductVariantIndexAction
15
{
16
    /** @var ViewHandlerInterface */
17
    private $viewHandler;
18
19
    /** @var ProductVariantViewRepositoryInterface */
20
    private $productVariantViewRepository;
21
22
    public function __construct(
23
        ViewHandlerInterface $viewHandler,
24
        ProductVariantViewRepositoryInterface $productVariantViewRepository
25
    ) {
26
        $this->viewHandler = $viewHandler;
27
        $this->productVariantViewRepository = $productVariantViewRepository;
28
    }
29
30
    public function __invoke(Request $request): Response
31
    {
32
        $page = $this->productVariantViewRepository->getAllPaginated(
33
            new PaginatorDetails($request->attributes->get('_route'), $request->query->all()),
34
            $request->query->get('locale')
35
        );
36
37
        return $this->viewHandler->handle(
38
            View::create(
39
                $page,
40
                Response::HTTP_OK
41
            )
42
        );
43
    }
44
}
45