DataSourceFactory::create()   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
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 4
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