Completed
Push — master ( c94c1b...986a44 )
by Beniamin
02:22
created

UnderQuery   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 91.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 92
ccs 22
cts 24
cp 0.9167
rs 10
c 1
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A getContainer() 0 4 1
A getConnection() 0 4 1
A createQueryBuilder() 0 8 1
A createSelect() 0 4 1
A createUpdate() 0 4 1
A createDelete() 0 4 1
A createInsert() 0 4 1
A createInsertSelect() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of UnderQuery 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;
13
14
use Interop\Container\ContainerInterface;
15
use Phuria\UnderQuery\Connection\ConnectionInterface;
16
use Phuria\UnderQuery\DependencyInjection\ContainerFactory;
17
use Phuria\UnderQuery\QueryBuilder\DeleteBuilder;
18
use Phuria\UnderQuery\QueryBuilder\InsertBuilder;
19
use Phuria\UnderQuery\QueryBuilder\InsertSelectBuilder;
20
use Phuria\UnderQuery\QueryBuilder\QueryBuilderFacade;
21
use Phuria\UnderQuery\QueryBuilder\SelectBuilder;
22
use Phuria\UnderQuery\QueryBuilder\UpdateBuilder;
23
use Phuria\UnderQuery\QueryCompiler\QueryCompilerInterface;
24
25
/**
26
 * @author Beniamin Jonatan Šimko <[email protected]>
27
 */
28
class UnderQuery
29
{
30
    /**
31
     * @var ContainerInterface
32
     */
33
    private $container;
34
35
    /**
36
     * @var ConnectionInterface|null
37
     */
38
    private $connection;
39
40
    /**
41
     * @param ConnectionInterface|null $connection
42
     * @param ContainerInterface|null  $container
43
     */
44 2
    public function __construct(ConnectionInterface $connection = null, ContainerInterface $container = null)
45
    {
46 2
        $this->container = $container ?: (new ContainerFactory())->create();
47 2
        $this->connection = $connection;
48 2
    }
49
50
    /**
51
     * @return ContainerInterface
52
     */
53 2
    public function getContainer()
54
    {
55 2
        return $this->container;
56
    }
57
58
    /**
59
     * @return null|ConnectionInterface
60
     */
61
    public function getConnection()
62
    {
63
        return $this->connection;
64
    }
65
66
    /**
67
     * @param string $class
68
     *
69
     * @return QueryCompilerInterface
70
     */
71 1
    private function createQueryBuilder($class)
72
    {
73 1
        return new $class(new QueryBuilderFacade(
74 1
            $this->getContainer()->get('phuria.under_query.table_factory'),
75 1
            $this->getContainer()->get('phuria.under_query.query_compiler'),
76 1
            $this->connection
77 1
        ));
78
    }
79
80
    /**
81
     * @return SelectBuilder
0 ignored issues
show
Documentation introduced by
Should the return type not be QueryCompilerInterface?

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...
82
     */
83 1
    public function createSelect()
84
    {
85 1
        return $this->createQueryBuilder(SelectBuilder::class);
86
    }
87
88
    /**
89
     * @return UpdateBuilder
0 ignored issues
show
Documentation introduced by
Should the return type not be QueryCompilerInterface?

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...
90
     */
91 1
    public function createUpdate()
92
    {
93 1
        return $this->createQueryBuilder(UpdateBuilder::class);
94
    }
95
96
    /**
97
     * @return DeleteBuilder
0 ignored issues
show
Documentation introduced by
Should the return type not be QueryCompilerInterface?

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...
98
     */
99 1
    public function createDelete()
100
    {
101 1
        return $this->createQueryBuilder(DeleteBuilder::class);
102
    }
103
104
    /**
105
     * @return InsertBuilder
0 ignored issues
show
Documentation introduced by
Should the return type not be QueryCompilerInterface?

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...
106
     */
107 1
    public function createInsert()
108
    {
109 1
        return $this->createQueryBuilder(InsertBuilder::class);
110
    }
111
112
    /**
113
     * @return InsertSelectBuilder
0 ignored issues
show
Documentation introduced by
Should the return type not be QueryCompilerInterface?

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...
114
     */
115 1
    public function createInsertSelect()
116
    {
117 1
        return $this->createQueryBuilder(InsertSelectBuilder::class);
118
    }
119
}