ProductVariantIndexAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 27
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 11 1
A __construct() 0 6 1
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