Table::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 6/3/14
5
 * Time: 12:07 AM.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace NilPortugues\Sql\QueryBuilder\Syntax;
12
13
/**
14
 * Class Table.
15
 */
16
class Table
17
{
18
    /**
19
     * @var string
20
     */
21
    protected $name;
22
23
    /**
24
     * @var string
25
     */
26
    protected $alias;
27
28
    /**
29
     * @var string
30
     */
31
    protected $schema;
32
33
    /**
34
     * @var bool
35
     */
36
    protected $view = false;
37
38
    /**
39
     * @param        $name
40
     * @param string $schema
41
     */
42
    public function __construct($name, $schema = null)
43
    {
44
        $this->name = $name;
45
46
        if (!is_null($schema)) {
47
            $this->schema = $schema;
48
        }
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    public function __toString()
55
    {
56
        return (string) $this->name;
57
    }
58
59
    /**
60
     * @param bool $view
61
     *
62
     * @return $this
63
     */
64
    public function setView($view)
65
    {
66
        $this->view = $view;
67
68
        return $this;
69
    }
70
71
    /**
72
     * @return bool
73
     */
74
    public function isView()
75
    {
76
        return $this->view;
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function getName()
83
    {
84
        return $this->name;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getAlias()
91
    {
92
        return $this->alias;
93
    }
94
95
    /**
96
     * @return string
97
     */
98
    public function getCompleteName()
99
    {
100
        $alias = ($this->alias) ? " AS {$this->alias}" : '';
101
        $schema = ($this->schema) ? "{$this->schema}." : '';
102
103
        return $schema.$this->name.$alias;
104
    }
105
106
    /**
107
     * @param string $alias
108
     *
109
     * @return $this
110
     */
111
    public function setAlias($alias)
112
    {
113
        $this->alias = $alias;
114
115
        return $this;
116
    }
117
118
    /**
119
     * @return string
120
     */
121
    public function getSchema()
122
    {
123
        return $this->schema;
124
    }
125
126
    /**
127
     * @param string
128
     * @param string $schema
129
     *
130
     * @return $this
131
     */
132
    public function setSchema($schema)
133
    {
134
        $this->schema = $schema;
135
136
        return $this;
137
    }
138
}
139