UnderQuery   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 94.12%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
lcom 1
cbo 7
dl 0
loc 110
ccs 32
cts 34
cp 0.9412
rs 10
c 1
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A getConnection() 0 4 1
A createQueryCompiler() 0 10 1
A createTableFactory() 0 6 1
A createQueryBuilder() 0 4 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 Doctrine\DBAL\Driver\Connection as ConnectionInterface;
15
use Phuria\UnderQuery\QueryBuilder\DeleteBuilder;
16
use Phuria\UnderQuery\QueryBuilder\InsertBuilder;
17
use Phuria\UnderQuery\QueryBuilder\InsertSelectBuilder;
18
use Phuria\UnderQuery\QueryBuilder\QueryBuilderFacade;
19
use Phuria\UnderQuery\QueryBuilder\SelectBuilder;
20
use Phuria\UnderQuery\QueryBuilder\UpdateBuilder;
21
use Phuria\UnderQuery\QueryCompiler\ConcreteCompiler\DeleteCompiler;
22
use Phuria\UnderQuery\QueryCompiler\ConcreteCompiler\InsertCompiler;
23
use Phuria\UnderQuery\QueryCompiler\ConcreteCompiler\SelectCompiler;
24
use Phuria\UnderQuery\QueryCompiler\ConcreteCompiler\UpdateCompiler;
25
use Phuria\UnderQuery\QueryCompiler\QueryCompiler;
26
use Phuria\UnderQuery\QueryCompiler\QueryCompilerInterface;
27
use Phuria\UnderQuery\TableFactory\TableFactory;
28
29
/**
30
 * @author Beniamin Jonatan Šimko <[email protected]>
31
 */
32
class UnderQuery
33
{
34
    /**
35
     * @var QueryCompiler
36
     */
37
    private $queryCompiler;
38
39
    /**
40
     * @var ConnectionInterface|null
41
     */
42
    private $connection;
43
44
    /**
45
     * @param ConnectionInterface|null $connection
46
     */
47 1
    public function __construct(ConnectionInterface $connection = null)
48
    {
49 1
        $this->connection = $connection;
50 1
        $this->queryCompiler = $this->createQueryCompiler();
51 1
        $this->tableFactory = $this->createTableFactory();
0 ignored issues
show
Bug introduced by
The property tableFactory does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
52
53 1
        $this->queryFacade = new QueryBuilderFacade(
0 ignored issues
show
Bug introduced by
The property queryFacade does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
54 1
            $this->tableFactory,
55 1
            $this->queryCompiler,
56 1
            $this->connection
57 1
        );
58 1
    }
59
60
    /**
61
     * @return ConnectionInterface|null
62
     */
63
    public function getConnection()
64
    {
65
        return $this->connection;
66
    }
67
68
    /**
69
     * @return QueryCompiler
70
     */
71 1
    private function createQueryCompiler()
72
    {
73 1
        $queryCompiler = new QueryCompiler();
74 1
        $queryCompiler->addConcreteCompiler(new SelectCompiler());
75 1
        $queryCompiler->addConcreteCompiler(new InsertCompiler());
76 1
        $queryCompiler->addConcreteCompiler(new DeleteCompiler());
77 1
        $queryCompiler->addConcreteCompiler(new UpdateCompiler());
78
79 1
        return $queryCompiler;
80
    }
81
82
    /**
83
     * @return TableFactory
84
     */
85 1
    private function createTableFactory()
86
    {
87 1
        $tableFactory = new TableFactory();
88
89 1
        return $tableFactory;
90
    }
91
92
    /**
93
     * @param string $class
94
     *
95
     * @return QueryCompilerInterface
96
     */
97 1
    private function createQueryBuilder($class)
98
    {
99 1
        return new $class($this->queryFacade);
100
    }
101
102
    /**
103
     * @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...
104
     */
105 1
    public function createSelect()
106
    {
107 1
        return $this->createQueryBuilder(SelectBuilder::class);
108
    }
109
110
    /**
111
     * @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...
112
     */
113 1
    public function createUpdate()
114
    {
115 1
        return $this->createQueryBuilder(UpdateBuilder::class);
116
    }
117
118
    /**
119
     * @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...
120
     */
121 1
    public function createDelete()
122
    {
123 1
        return $this->createQueryBuilder(DeleteBuilder::class);
124
    }
125
126
    /**
127
     * @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...
128
     */
129 1
    public function createInsert()
130
    {
131 1
        return $this->createQueryBuilder(InsertBuilder::class);
132
    }
133
134
    /**
135
     * @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...
136
     */
137 1
    public function createInsertSelect()
138
    {
139 1
        return $this->createQueryBuilder(InsertSelectBuilder::class);
140
    }
141
}