Completed
Push — master ( bf07e5...f61ec4 )
by Beniamin
02:20
created

QueryBuilder::createQueryBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
crap 1
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\SQLBuilder;
13
14
use Phuria\SQLBuilder\DependencyInjection\InternalContainer;
15
use Phuria\SQLBuilder\QueryBuilder\DeleteBuilder;
16
use Phuria\SQLBuilder\QueryBuilder\InsertBuilder;
17
use Phuria\SQLBuilder\QueryBuilder\InsertSelectBuilder;
18
use Phuria\SQLBuilder\QueryBuilder\SelectBuilder;
19
use Phuria\SQLBuilder\QueryBuilder\UpdateBuilder;
20
use Symfony\Component\DependencyInjection\ContainerInterface;
21
22
/**
23
 * @author Beniamin Jonatan Šimko <[email protected]>
24
 */
25
class QueryBuilder
26
{
27
    /**
28
     * @var ContainerInterface $container
29
     */
30
    private $container;
31
32
    /**
33
     * @param ContainerInterface|null $container
34
     */
35 6
    public function __construct(ContainerInterface $container = null)
36
    {
37 6
        $this->container = $container ?: new InternalContainer();
38 6
    }
39
40
    /**
41
     * @return ContainerInterface
42
     */
43
    public function getContainer()
44
    {
45
        return $this->container;
46
    }
47
48
    /**
49
     * @param string $class
50
     *
51
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be object?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
52
     */
53 34
    private function createQueryBuilder($class)
54
    {
55 34
        $parameterClass = $this->container->getParameter('phuria.sql_builder.parameter_manager.class');
56
57 34
        return new $class(
58 34
            $this->container->get('phuria.sql_builder.table_factory'),
59 34
            $this->container->get('phuria.sql_builder.query_compiler'),
60
            new $parameterClass
61 34
        );
62
    }
63
64
    /**
65
     * @return SelectBuilder
66
     */
67 26
    public function select()
68
    {
69 26
        return $this->createQueryBuilder(SelectBuilder::class);
70
    }
71
72
    /**
73
     * @return UpdateBuilder
74
     */
75 4
    public function update()
76
    {
77 4
        return $this->createQueryBuilder(UpdateBuilder::class);
78
    }
79
80
    /**
81
     * @return DeleteBuilder
82
     */
83 2
    public function delete()
84
    {
85 2
        return $this->createQueryBuilder(DeleteBuilder::class);
86
    }
87
88
    /**
89
     * @return InsertBuilder
90
     */
91 2
    public function insert()
92
    {
93 2
        return $this->createQueryBuilder(InsertBuilder::class);
94
    }
95
96
    /**
97
     * @return InsertSelectBuilder
98
     */
99 1
    public function insertSelect()
100
    {
101 1
        return $this->createQueryBuilder(InsertSelectBuilder::class);
102
    }
103
}