Passed
Push — master ( 9db5ce...9e9229 )
by Rougin
01:41
created

Builder::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Rougin\Windstorm\Doctrine;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\Query\QueryBuilder;
7
use Rougin\Windstorm\Doctrine\Builder\DeleteQuery;
8
use Rougin\Windstorm\Doctrine\Builder\InsertQuery;
9
use Rougin\Windstorm\Doctrine\Builder\SelectQuery;
10
use Rougin\Windstorm\Doctrine\Builder\UpdateQuery;
11
12
/**
13
 * Query Builder
14
 *
15
 * @package Windstorm
16
 * @author  Rougin Gutib <[email protected]>
17
 */
18
class Builder extends QueryBuilder
19
{
20
    /**
21
     * @var \Doctrine\DBAL\Platforms\AbstractPlatform
22
     */
23
    protected $platform;
24
25
    /**
26
     * Initializes the platform instance.
27
     *
28
     * @param \Doctrine\DBAL\Connection|\Doctrine\DBAL\Platforms\AbstractPlatform $platform
29
     */
30 108
    public function __construct($platform)
31
    {
32 108
        if ($platform instanceof Connection)
33 72
        {
34
            $platform = $platform->getDatabasePlatform();
35
        }
36
37 108
        $this->platform = $platform;
38 108
    }
39
40
    /**
41
     * Returns the complete SQL string.
42
     *
43
     * @return string
44
     */
45 102
    public function getSql()
46
    {
47 102
        $first = $this->getFirstResult();
48
49 102
        $max = $this->getMaxResults();
50
51 102
        $parts = $this->getQueryParts();
52
53 102
        switch ($this->getType())
54
        {
55 102
            case self::INSERT:
56 3
                $sql = new InsertQuery($parts);
57
58 3
                break;
59 99
            case self::DELETE:
60 6
                $sql = new DeleteQuery($parts);
61
62 6
                break;
63 93
            case self::UPDATE:
64 3
                $sql = new UpdateQuery($parts);
65
66 35
                break;
67 90
            case self::SELECT:
68 60
            default:
69 90
                $sql = new SelectQuery($parts, $this->platform, $max, $first);
70
71 90
                break;
72 68
        }
73
74 102
        return (string) $sql->get();
75
    }
76
}
77