Completed
Push — master ( 663845...79fb76 )
by Igor
18s queued 13s
created

OrderViewRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllPaginated() 0 14 2
A __construct() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusLagersystemPlugin\ViewRepository\Order;
6
7
use Pagerfanta\Adapter\DoctrineORMAdapter;
8
use Pagerfanta\Pagerfanta;
9
use Setono\SyliusLagersystemPlugin\Factory\Order\OrderViewFactoryInterface;
10
use Setono\SyliusLagersystemPlugin\Factory\PageViewFactoryInterface;
11
use Setono\SyliusLagersystemPlugin\Model\PaginatorDetails;
12
use Setono\SyliusLagersystemPlugin\Repository\OrderRepositoryInterface;
13
use Setono\SyliusLagersystemPlugin\View\PageView;
14
15
class OrderViewRepository implements OrderViewRepositoryInterface
16
{
17
    /** @var OrderRepositoryInterface */
18
    protected $orderRepository;
19
20
    /** @var PageViewFactoryInterface */
21
    protected $pageViewFactory;
22
23
    /** @var OrderViewFactoryInterface */
24
    protected $orderViewFactory;
25
26
    public function __construct(
27
        OrderRepositoryInterface $orderRepository,
28
        PageViewFactoryInterface $pageViewFactory,
29
        OrderViewFactoryInterface $orderViewFactory
30
    ) {
31
        $this->orderRepository = $orderRepository;
32
        $this->pageViewFactory = $pageViewFactory;
33
        $this->orderViewFactory = $orderViewFactory;
34
    }
35
36
    public function getAllPaginated(PaginatorDetails $paginatorDetails): PageView
37
    {
38
        $queryBuilder = $this->orderRepository->createLagersystemListQueryBuilder();
39
40
        $pagerfanta = new Pagerfanta(new DoctrineORMAdapter($queryBuilder));
41
        $pagerfanta->setMaxPerPage($paginatorDetails->limit());
42
        $pagerfanta->setCurrentPage($paginatorDetails->page());
43
44
        $pageView = $this->pageViewFactory->create($pagerfanta, $paginatorDetails->route(), $paginatorDetails->parameters());
45
        foreach ($pagerfanta->getCurrentPageResults() as $currentPageResult) {
46
            $pageView->items[] = $this->orderViewFactory->create($currentPageResult);
47
        }
48
49
        return $pageView;
50
    }
51
}
52