AbstractBuilder::buildProperty()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 15
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
nc 2
nop 3
dl 0
loc 15
rs 10
c 2
b 0
f 0
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 FOS\ElasticaBundle\Event\PostTransformEvent;
14
use Sylius\Component\Resource\Model\ToggleableInterface;
15
16
abstract class AbstractBuilder implements PropertyBuilderInterface
17
{
18
    public function buildProperty(
19
        PostTransformEvent $event,
20
        string $supportedModelClass,
21
        callable $callback
22
    ): void
23
    {
24
        $model = $event->getObject();
25
26
        if (!$model instanceof $supportedModelClass || ($model instanceof ToggleableInterface && !$model->isEnabled())) {
27
            return;
28
        }
29
30
        $document = $event->getDocument();
31
32
        $callback($model, $document);
33
    }
34
35
    public static function getSubscribedEvents(): array
36
    {
37
        return [
38
            PostTransformEvent::class => 'consumeEvent',
39
        ];
40
    }
41
}
42