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

ProductMainTaxonPositionPropertyBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A consumeEvent() 0 13 2
A __construct() 0 3 1
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