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

ProductVariantViewRepository::getAllPaginated()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
nc 2
nop 2
dl 0
loc 15
rs 9.9666
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusLagersystemPlugin\ViewRepository\Product;
6
7
use Pagerfanta\Adapter\DoctrineORMAdapter;
8
use Pagerfanta\Pagerfanta;
9
use Setono\SyliusLagersystemPlugin\Factory\PageViewFactoryInterface;
10
use Setono\SyliusLagersystemPlugin\Factory\Product\ProductVariantViewFactoryInterface;
11
use Setono\SyliusLagersystemPlugin\Model\PaginatorDetails;
12
use Setono\SyliusLagersystemPlugin\Repository\ProductVariantRepositoryInterface;
13
use Setono\SyliusLagersystemPlugin\View\PageView;
14
use Webmozart\Assert\Assert;
15
16
class ProductVariantViewRepository implements ProductVariantViewRepositoryInterface
17
{
18
    /** @var ProductVariantRepositoryInterface */
19
    protected $productVariantRepository;
20
21
    /** @var PageViewFactoryInterface */
22
    protected $pageViewFactory;
23
24
    /** @var ProductVariantViewFactoryInterface */
25
    protected $productVariantViewFactory;
26
27
    public function __construct(
28
        ProductVariantRepositoryInterface $productVariantRepository,
29
        PageViewFactoryInterface $pageViewFactory,
30
        ProductVariantViewFactoryInterface $productVariantViewFactory
31
    ) {
32
        $this->productVariantRepository = $productVariantRepository;
33
        $this->pageViewFactory = $pageViewFactory;
34
        $this->productVariantViewFactory = $productVariantViewFactory;
35
    }
36
37
    public function getAllPaginated(PaginatorDetails $paginatorDetails, ?string $localeCode): PageView
38
    {
39
        Assert::notNull($localeCode);
40
        $queryBuilder = $this->productVariantRepository->createLagersystemListQueryBuilder($localeCode);
0 ignored issues
show
Bug introduced by
It seems like $localeCode can also be of type null; however, parameter $locale of Setono\SyliusLagersystem...ystemListQueryBuilder() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
        $queryBuilder = $this->productVariantRepository->createLagersystemListQueryBuilder(/** @scrutinizer ignore-type */ $localeCode);
Loading history...
41
42
        $pagerfanta = new Pagerfanta(new DoctrineORMAdapter($queryBuilder));
43
        $pagerfanta->setMaxPerPage($paginatorDetails->limit());
44
        $pagerfanta->setCurrentPage($paginatorDetails->page());
45
46
        $pageView = $this->pageViewFactory->create($pagerfanta, $paginatorDetails->route(), $paginatorDetails->parameters());
47
        foreach ($pagerfanta->getCurrentPageResults() as $currentPageResult) {
48
            $pageView->items[] = $this->productVariantViewFactory->create($currentPageResult, $localeCode);
0 ignored issues
show
Bug introduced by
It seems like $localeCode can also be of type null; however, parameter $localeCode of Setono\SyliusLagersystem...toryInterface::create() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
            $pageView->items[] = $this->productVariantViewFactory->create($currentPageResult, /** @scrutinizer ignore-type */ $localeCode);
Loading history...
49
        }
50
51
        return $pageView;
52
    }
53
}
54