AbstractBuilder::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 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