FilterConditionFactory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 3
1
<?php
2
namespace Netdudes\DataSourceryBundle\Query;
3
4
use Netdudes\DataSourceryBundle\DataSource\Configuration\Field;
5
use Netdudes\DataSourceryBundle\UQL\Event\InterpreterEvents;
6
use Netdudes\DataSourceryBundle\UQL\Event\PreCreateFilterConditionEvent;
7
use Symfony\Component\EventDispatcher\EventDispatcher;
8
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
9
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10
11
class FilterConditionFactory
12
{
13
    /**
14
     * @var EventDispatcherInterface
15
     */
16
    protected $eventDispatcher;
17
18
    public function __construct()
19
    {
20
        $this->eventDispatcher = new EventDispatcher();
21
    }
22
23
    /**
24
     * @param EventSubscriberInterface $eventSubscriber
25
     */
26
    public function registerEventSubscriber(EventSubscriberInterface $eventSubscriber)
27
    {
28
        $this->eventDispatcher->addSubscriber($eventSubscriber);
29
    }
30
31
    /**
32
     * @param mixed  $value
33
     * @param string $method
34
     * @param Field  $field
35
     *
36
     * @return FilterCondition
37
     */
38
    public function create(Field $field, $method, $value)
39
    {
40
        $event = new PreCreateFilterConditionEvent($field->getDataType(), $value, $method);
41
        $this->eventDispatcher->dispatch(
42
            InterpreterEvents::PRE_CREATE_FILTER_CONDITION,
43
            $event
44
        );
45
        $databaseValue = $event->getDatabaseValue();
46
47
        return new FilterCondition($field->getUniqueName(), $method, $value, $databaseValue);
48
    }
49
}
50