Connection::__call()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Reduce\Db;
4
5
use Doctrine\DBAL\Connection as DBAL;
6
use Doctrine\DBAL\Driver;
7
use Doctrine\DBAL\Configuration;
8
use Doctrine\Common\EventManager;
9
10
class Connection extends DBAL
11
{    
12
    protected $single = false;
13
    
14 11
    public function __construct(array $params, Driver $driver, Configuration $config = null,
15
            EventManager $eventManager = null)
16
    {
17 11
        parent::__construct($params, $driver, $config, $eventManager);
18 11
    }
19
    
20 3
    public function __call($name, $args)
21
    {
22 3
        $resultSet = $this->createResultSet($name);
23
        
24 3
        if (count($args)) {
25 1
            call_user_func_array([$resultSet, 'where'], $args);
26
        }
27
        
28 3
        $this->single = false;
29
        
30 3
        return $resultSet;
31
    }
32
    
33 1
    public function __get($name)
34
    {
35 1
        $this->single = true;
36
        
37 1
        return $this->$name();
38
    }
39
    
40 4
    public function createQueryBuilder()
41
    {
42 4
        return new Query\QueryBuilder($this);
43
    }
44
    
45 3
    protected function createResultSet($tableName)
46
    {
47 3
        return new ResultSet($tableName, $this->createQueryBuilder(), $this->single);
48
    }
49
}
50