DataSourceFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 53
c 0
b 0
f 0
wmc 4
lcom 2
cbo 4
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createFromConfiguration() 0 7 1
A create() 0 4 1
A createBuilder() 0 4 1
1
<?php
2
namespace Netdudes\DataSourceryBundle\DataSource;
3
4
use Netdudes\DataSourceryBundle\DataSource\Configuration\DataSourceConfigurationInterface;
5
use Netdudes\DataSourceryBundle\DataSource\Driver\DriverInterface;
6
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
7
8
class DataSourceFactory implements DataSourceFactoryInterface
9
{
10
    /**
11
     * @var DataSourceBuilderFactory
12
     */
13
    private $dataSourceBuilderFactory;
14
15
    /**
16
     * @param DriverInterface          $driver
17
     * @param DataSourceBuilderFactory $dataSourceBuilderFactory
18
     */
19
    public function __construct(DriverInterface $driver, DataSourceBuilderFactory $dataSourceBuilderFactory)
20
    {
21
        $this->driver = $driver;
0 ignored issues
show
Bug introduced by
The property driver does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
        $this->dataSourceBuilderFactory = $dataSourceBuilderFactory;
23
    }
24
25
    /**
26
     * @param DataSourceConfigurationInterface $configuration
27
     *
28
     * @return DataSourceInterface
29
     */
30
    public function createFromConfiguration(DataSourceConfigurationInterface $configuration)
31
    {
32
        $builder = $this->createBuilder($configuration->getEntityClass());
33
        $configuration->buildDataSource($builder);
34
35
        return $builder->build();
36
    }
37
38
    /**
39
     * @param                          $entityClass
40
     * @param                          $fields
41
     * @param                          $transformers
42
     * @param EventDispatcherInterface $eventDispatcher
43
     *
44
     * @return DataSource
45
     */
46
    public function create($entityClass, array $fields, array $transformers, EventDispatcherInterface $eventDispatcher)
47
    {
48
        return new DataSource($entityClass, $fields, $transformers, $eventDispatcher, $this->driver);
49
    }
50
51
    /**
52
     * @param $entityClass
53
     *
54
     * @return DataSourceBuilder
55
     */
56
    public function createBuilder($entityClass)
57
    {
58
        return $this->dataSourceBuilderFactory->create($entityClass, $this);
59
    }
60
}
61