Completed
Push — 1.6-dev ( 4f019b )
by Alexis
09:21
created

ConnectionFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createConnection() 0 12 2
A getDbNameFromEnv() 0 4 1
1
<?php
2
3
namespace Liip\FunctionalTestBundle\Factory;
4
5
use Doctrine\Bundle\DoctrineBundle\ConnectionFactory as BaseConnectionFactory;
6
use Doctrine\Common\EventManager;
7
use Doctrine\DBAL\Configuration;
8
9
/**
10
 * Creates a connection taking the db name from the env with
11
 * a unique number defined by current process ID.
12
 */
13
class ConnectionFactory extends BaseConnectionFactory
14
{
15
    /**
16
     * Create a connection by name.
17
     *
18
     * @param array         $params
19
     * @param Configuration $config
20
     * @param EventManager  $eventManager
21
     * @param array         $mappingTypes
22
     *
23
     * @return \Doctrine\DBAL\Connection
24
     */
25
    public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = array())
26
    {
27
        $dbName = $this->getDbNameFromEnv($params['dbname']);
28
29
        if ($params['driver'] === 'pdo_sqlite') {
30
            $params['path'] = str_replace('__DBNAME__', $dbName, $params['path']);
31
        } else {
32
            $params['dbname'] = $dbName;
33
        }
34
35
        return parent::createConnection($params, $config, $eventManager, $mappingTypes);
36
    }
37
38
    private function getDbNameFromEnv($dbName)
0 ignored issues
show
Unused Code introduced by
The parameter $dbName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
    {
40
        return 'dbTest'.getenv('TEST_TOKEN');
41
    }
42
}
43