FilterConditionFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 39
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A registerEventSubscriber() 0 4 1
A create() 0 11 1
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