Passed
Pull Request — master (#360)
by Mateusz
08:07
created

RenderProductPagesRuntime   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 17
c 4
b 0
f 0
dl 0
loc 40
rs 10
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 has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.io and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusCmsPlugin\Twig\Runtime;
14
15
use BitBag\SyliusCmsPlugin\Repository\PageRepositoryInterface;
16
use BitBag\SyliusCmsPlugin\Sorter\SectionsSorterInterface;
17
use Sylius\Component\Channel\Context\ChannelContextInterface;
18
use Sylius\Component\Core\Model\ProductInterface;
19
use Twig\Environment;
20
21
final class RenderProductPagesRuntime implements RenderProductPagesRuntimeInterface
22
{
23
    /** @var PageRepositoryInterface */
24
    private $pageRepository;
25
26
    /** @var ChannelContextInterface */
27
    private $channelContext;
28
29
    /** @var Environment */
30
    private $templatingEngine;
31
32
    /** @var SectionsSorterInterface */
33
    private $sectionsSorter;
34
35
    public function __construct(
36
        PageRepositoryInterface $pageRepository,
37
        ChannelContextInterface $channelContext,
38
        Environment $templatingEngine,
39
        SectionsSorterInterface $sectionsSorter
40
    ) {
41
        $this->pageRepository = $pageRepository;
42
        $this->channelContext = $channelContext;
43
        $this->templatingEngine = $templatingEngine;
44
        $this->sectionsSorter = $sectionsSorter;
45
    }
46
47
    public function renderProductPages(ProductInterface $product, string $sectionCode = null): string
48
    {
49
        $channelCode = $this->channelContext->getChannel()->getCode();
50
51
        if (null !== $sectionCode) {
52
            $pages = $this->pageRepository->findByProductAndSectionCode($product, $sectionCode, $channelCode);
0 ignored issues
show
Bug introduced by
The call to BitBag\SyliusCmsPlugin\R...ProductAndSectionCode() has too few arguments starting with date. ( Ignorable by Annotation )

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

52
            /** @scrutinizer ignore-call */ 
53
            $pages = $this->pageRepository->findByProductAndSectionCode($product, $sectionCode, $channelCode);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
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

52
            $pages = $this->pageRepository->findByProductAndSectionCode($product, $sectionCode, /** @scrutinizer ignore-type */ $channelCode);
Loading history...
53
        } else {
54
            $pages = $this->pageRepository->findByProduct($product, $channelCode);
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

54
            $pages = $this->pageRepository->findByProduct($product, /** @scrutinizer ignore-type */ $channelCode);
Loading history...
Bug introduced by
The call to BitBag\SyliusCmsPlugin\R...erface::findByProduct() has too few arguments starting with date. ( Ignorable by Annotation )

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

54
            /** @scrutinizer ignore-call */ 
55
            $pages = $this->pageRepository->findByProduct($product, $channelCode);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
55
        }
56
57
        $data = $this->sectionsSorter->sortBySections($pages);
58
59
        return $this->templatingEngine->render('@BitBagSyliusCmsPlugin/Shop/Product/_pagesBySection.html.twig', [
60
            'data' => $data,
61
        ]);
62
    }
63
}
64