Completed
Push — master ( fa4f9a...8a9929 )
by Beniamin
03:39
created

QueryCompiler   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 81.25%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 50
ccs 13
cts 16
cp 0.8125
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A addCompiler() 0 6 1
A canHandleQuery() 0 4 1
A compile() 0 10 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\QueryBuilder\QueryCompiler;
13
14
use Phuria\QueryBuilder\QueryBuilder;
15
16
/**
17
 * @author Beniamin Jonatan Šimko <[email protected]>
18
 */
19
class QueryCompiler implements QueryCompilerInterface
20
{
21
    /**
22
     * @var \SplPriorityQueue|QueryCompilerInterface[] $compilers
23
     */
24
    private $compilers = [];
25
26 27
    public function __construct()
27
    {
28 27
        $this->compilers = new \SplPriorityQueue();
29
30 27
        $this->addCompiler(new SelectQueryCompiler());
31 27
        $this->addCompiler(new UpdateQueryCompiler());
32 27
    }
33
34
    /**
35
     * @param QueryCompilerInterface $compiler
36
     * @param int                    $priority
37
     *
38
     * @return $this
39
     */
40 27
    public function addCompiler(QueryCompilerInterface $compiler, $priority = 0)
41
    {
42 27
        $this->compilers->insert($compiler, $priority);
43
44 27
        return $this;
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    public function canHandleQuery(QueryBuilder $qb)
51
    {
52
        return true;
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58 24
    public function compile(QueryBuilder $qb)
59
    {
60 24
        foreach ($this->compilers as $compiler) {
61 24
            if ($compiler->canHandleQuery($qb)) {
62 24
                return $compiler->compile($qb);
63
            }
64 2
        }
65
66
        return null;
67
    }
68
}