Completed
Push — master ( 316ddc...4c01ea )
by Beniamin
02:32
created

QueryBuilder::select()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
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 34
    public function __construct(ContainerInterface $container = null)
36
    {
37 34
        $this->container = $container ?: new InternalContainer();
38 34
    }
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 34
        $referenceClass = $this->container->getParameter('phuria.sql_builder.reference_manager.class');
57
58 34
        return new $class(
59 34
            $this->container->get('phuria.sql_builder.table_factory'),
60 34
            $this->container->get('phuria.sql_builder.query_compiler'),
61 34
            new $parameterClass,
62
            new $referenceClass
63 34
        );
64
    }
65
66
    /**
67
     * @return SelectBuilder
68
     */
69 26
    public function select()
70
    {
71 26
        return $this->createQueryBuilder(SelectBuilder::class);
72
    }
73
74
    /**
75
     * @return UpdateBuilder
76
     */
77 4
    public function update()
78
    {
79 4
        return $this->createQueryBuilder(UpdateBuilder::class);
80
    }
81
82
    /**
83
     * @return DeleteBuilder
84
     */
85 2
    public function delete()
86
    {
87 2
        return $this->createQueryBuilder(DeleteBuilder::class);
88
    }
89
90
    /**
91
     * @return InsertBuilder
92
     */
93 2
    public function insert()
94
    {
95 2
        return $this->createQueryBuilder(InsertBuilder::class);
96
    }
97
98
    /**
99
     * @return InsertSelectBuilder
100
     */
101 1
    public function insertSelect()
102
    {
103 1
        return $this->createQueryBuilder(InsertSelectBuilder::class);
104
    }
105
}