Completed
Pull Request — master (#165)
by Paul
03:21
created

DataSourceFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 36
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createService() 0 17 3
1
<?php
2
/**
3
 * This file is part of the PPI Framework.
4
 *
5
 * @copyright   Copyright (c) 2011-2016 Paul Dragoonis <[email protected]>
6
 * @license     http://opensource.org/licenses/mit-license.php MIT
7
 *
8
 * @link        http://www.ppi.io
9
 */
10
11
namespace PPI\Framework\ServiceManager\Factory;
12
13
use PPI\Framework\DataSource\ConnectionManager;
14
use Zend\ServiceManager\FactoryInterface;
15
use Zend\ServiceManager\ServiceLocatorInterface;
16
17
/**
18
 * DataSource Factory.
19
 *
20
 * @author     Vítor Brandão <[email protected]>
21
 * @author     Paul Dragoonis <[email protected]>
22
 */
23
class DataSourceFactory implements FactoryInterface
24
{
25
    protected $connectionClassMap = array(
26
        'laravel'          => 'PPI\Framework\DataSource\Connection\Laravel',
27
        'doctrine_dbal'    => 'PPI\Framework\DataSource\Connection\DoctrineDBAL',
28
        'doctrine_mongdb'  => 'PPI\Framework\DataSource\Connection\DoctrineMongoDB',
29
        'fuelphp'          => 'PPI\Framework\DataSource\Connection\FuelPHP',
30
        'monga'            => 'PPI\Framework\DataSource\Connection\Monga',
31
        'zend_db'          => 'PPI\Framework\DataSource\Connection\ZendDb',
32
    );
33
34
    /**
35
     * Create and return the datasource service.
36
     *
37
     * @param ServiceLocatorInterface $serviceLocator
38
     *
39
     * @return \PPI\Framework\DataSource\DataSource;
0 ignored issues
show
Documentation introduced by
The doc-type \PPI\Framework\DataSource\DataSource; could not be parsed: Expected "|" or "end of type", but got ";" at position 36. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
40
     */
41
    public function createService(ServiceLocatorInterface $serviceLocator)
42
    {
43
        $config         = $serviceLocator->get('ApplicationConfig');
44
        $allConnections = $libraryToConnMap = $configMap = array();
0 ignored issues
show
Unused Code introduced by
$libraryToConnMap is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
45
46
        // Early return
47
        if (!isset($config['datasource']['connections'])) {
48
            return new ConnectionManager($allConnections, $this->connectionClassMap);
49
        }
50
51
        foreach ($config['datasource']['connections'] as $name => $config) {
52
            $allConnections[$name]                = $config;
53
            $configMap[$config['library']][$name] = $config;
54
        }
55
56
        return new ConnectionManager($allConnections, $this->connectionClassMap);
57
    }
58
}
59