AbstractQuery::table()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 4
nop 0
crap 3
1
<?php
2
3
namespace Rougin\Windstorm\Doctrine\Builder;
4
5
/**
6
 * Abstract Query
7
 *
8
 * @package Windstorm
9
 * @author  Rougin Gutib <[email protected]>
10
 */
11
abstract class AbstractQuery
12
{
13
    /**
14
     * @var array
15
     */
16
    protected $parts = array();
17
18
    /**
19
     * Initializes the query instance.
20
     *
21
     * @param array $parts
22
     */
23 30
    public function __construct(array $parts)
24
    {
25 30
        $this->parts = (array) $parts;
26 30
    }
27
28
    /**
29
     * Returns the table name with a specified alias.
30
     *
31
     * @return string
32
     */
33 30
    protected function table()
34
    {
35 30
        $table = $this->parts['from']['table'];
36
37 30
        $alias = null;
38
39 30
        if (isset($this->parts['from']['alias']))
40 20
        {
41 6
            $alias = $this->parts['from']['alias'];
42 4
        }
43
44 30
        $alias = $alias ? ' ' . $alias : '';
45
46 30
        return $table . (string) $alias;
47
    }
48
49
    /**
50
     * Returns the parameters for the WHERE clause.
51
     *
52
     * @return string
53
     */
54 24
    protected function where()
55
    {
56 24
        $where = (string) $this->parts['where'];
57
58 24
        return $where !== '' ? ' WHERE ' . $where : '';
59
    }
60
}
61