ProductTaxonPositionPropertyBuilder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A consumeEvent() 0 10 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\SyliusElasticsearchPlugin\PropertyBuilder;
12
13
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface;
14
use Elastica\Document;
15
use FOS\ElasticaBundle\Event\PostTransformEvent;
16
use Sylius\Component\Core\Model\ProductInterface;
17
18
final class ProductTaxonPositionPropertyBuilder extends AbstractBuilder
19
{
20
    /** @var ConcatedNameResolverInterface */
21
    private $taxonPositionNameResolver;
22
23
    public function __construct(ConcatedNameResolverInterface $taxonPositionNameResolver)
24
    {
25
        $this->taxonPositionNameResolver = $taxonPositionNameResolver;
26
    }
27
28
    public function consumeEvent(PostTransformEvent $event): void
29
    {
30
        $this->buildProperty(
31
            $event,
32
            ProductInterface::class,
33
            function (ProductInterface $product, Document $document): void {
34
                foreach ($product->getProductTaxons() as $taxon) {
35
                    $document->set(
36
                        $this->taxonPositionNameResolver->resolvePropertyName($taxon->getTaxon()->getCode()),
37
                        $taxon->getPosition()
38
                    );
39
                }
40
            }
41
        );
42
    }
43
}
44