Passed
Push — master ( bf9a0c...154e98 )
by Mikołaj
03:44
created

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace BitBag\SyliusElasticsearchPlugin\PropertyBuilder;
4
5
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface;
6
use Elastica\Document;
7
use FOS\ElasticaBundle\Event\TransformEvent;
8
use Sylius\Component\Core\Model\ProductInterface;
9
10
final class ProductMainTaxonPositionPropertyBuilder extends AbstractBuilder
11
{
12
    /** @var ConcatedNameResolverInterface */
13
    private $taxonPositionNameResolver;
14
15
    public function __construct(ConcatedNameResolverInterface $taxonPositionNameResolver)
16
    {
17
        $this->taxonPositionNameResolver = $taxonPositionNameResolver;
18
    }
19
20
    public function consumeEvent(TransformEvent $event): void
21
    {
22
        $this->buildProperty($event, ProductInterface::class,
23
            function (ProductInterface $product, Document $document): void {
24
                $mainTaxon = $product->getMainTaxon();
25
26
                if (null === $mainTaxon) {
27
                    return;
28
                }
29
30
                $document->set(
31
                    $this->taxonPositionNameResolver->resolvePropertyName($mainTaxon->getCode()),
0 ignored issues
show
Bug introduced by
It seems like $mainTaxon->getCode() can also be of type null; however, parameter $suffix of BitBag\SyliusElasticsear...::resolvePropertyName() 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

31
                    $this->taxonPositionNameResolver->resolvePropertyName(/** @scrutinizer ignore-type */ $mainTaxon->getCode()),
Loading history...
32
                    $mainTaxon->getPosition()
33
                );
34
            }
35
        );
36
    }
37
}
38