Test Setup Failed
Branch master (10fdc5)
by Beniamin
35:44
created

QueryFactory::buildQuery()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 3
1
<?php
2
3
/**
4
 * This file is part of Phuria SQL Builder package.
5
 *
6
 * Copyright (c) 2016 Beniamin Jonatan Šimko
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phuria\UnderQuery\Query;
13
14
use Phuria\UnderQuery\Connection\ConnectionInterface;
15
use Phuria\UnderQuery\Connection\ConnectionManagerInterface;
16
use Phuria\UnderQuery\Parameter\ParameterCollection;
17
18
/**
19
 * @author Beniamin Jonatan Šimko <[email protected]>
20
 */
21
class QueryFactory implements QueryFactoryInterface
22
{
23
    /**
24
     * @var ConnectionManagerInterface
25
     */
26
    private $connectionManager;
27
28
    /**
29
     * @param ConnectionManagerInterface $connectionManager
30
     */
31
    public function __construct(ConnectionManagerInterface $connectionManager)
32
    {
33
        $this->connectionManager = $connectionManager;
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function buildQuery($SQL, array $parameters, $connectionHint = null)
40
    {
41
        if ($connectionHint instanceof ConnectionInterface) {
42
            $connection = $connectionHint;
43
        } else {
44
            $connection = $this->connectionManager->getConnection($connectionHint);
45
        }
46
47
        return new Query($SQL, new ParameterCollection($parameters), $connection);
48
    }
49
}
50