AbstractBuilder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 23
rs 10
c 2
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildProperty() 0 15 4
A getSubscribedEvents() 0 4 1
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