RenderProductPagesRuntime   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 40
rs 10
c 4
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A renderProductPages() 0 14 2
1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusCmsPlugin\Twig\Runtime;
12
13
use BitBag\SyliusCmsPlugin\Repository\PageRepositoryInterface;
14
use BitBag\SyliusCmsPlugin\Sorter\SectionsSorterInterface;
15
use Sylius\Component\Channel\Context\ChannelContextInterface;
16
use Sylius\Component\Core\Model\ProductInterface;
17
use Twig\Environment;
18
use Webmozart\Assert\Assert;
19
20
final class RenderProductPagesRuntime implements RenderProductPagesRuntimeInterface
21
{
22
    /** @var PageRepositoryInterface */
23
    private $pageRepository;
24
25
    /** @var ChannelContextInterface */
26
    private $channelContext;
27
28
    /** @var Environment */
29
    private $templatingEngine;
30
31
    /** @var SectionsSorterInterface */
32
    private $sectionsSorter;
33
34
    public function __construct(
35
        PageRepositoryInterface $pageRepository,
36
        ChannelContextInterface $channelContext,
37
        Environment $templatingEngine,
38
        SectionsSorterInterface $sectionsSorter
39
    ) {
40
        $this->pageRepository = $pageRepository;
41
        $this->channelContext = $channelContext;
42
        $this->templatingEngine = $templatingEngine;
43
        $this->sectionsSorter = $sectionsSorter;
44
    }
45
46
    public function renderProductPages(ProductInterface $product, string $sectionCode = null): string
47
    {
48
        $channelCode = $this->channelContext->getChannel()->getCode();
49
        Assert::notNull($channelCode, 'Channel code for channel is null');
50
        if (null !== $sectionCode) {
51
            $pages = $this->pageRepository->findByProductAndSectionCode($product, $sectionCode, $channelCode, null);
0 ignored issues
show
Bug introduced by
It seems like $channelCode can also be of type null; however, parameter $channelCode of BitBag\SyliusCmsPlugin\R...ProductAndSectionCode() 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

51
            $pages = $this->pageRepository->findByProductAndSectionCode($product, $sectionCode, /** @scrutinizer ignore-type */ $channelCode, null);
Loading history...
52
        } else {
53
            $pages = $this->pageRepository->findByProduct($product, $channelCode, null);
0 ignored issues
show
Bug introduced by
It seems like $channelCode can also be of type null; however, parameter $channelCode of BitBag\SyliusCmsPlugin\R...erface::findByProduct() 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

53
            $pages = $this->pageRepository->findByProduct($product, /** @scrutinizer ignore-type */ $channelCode, null);
Loading history...
54
        }
55
56
        $data = $this->sectionsSorter->sortBySections($pages);
57
58
        return $this->templatingEngine->render('@BitBagSyliusCmsPlugin/Shop/Product/_pagesBySection.html.twig', [
59
            'data' => $data,
60
        ]);
61
    }
62
}
63