Completed
Pull Request — master (#11)
by Romain
02:27
created

TableName::getAlias()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Muffin\Queries\Snippets;
4
5
use Muffin\Snippet;
6
7
class TableName implements Snippet
8
{
9
    private
10
        $tableName,
11
        $alias;
12
13 84
    public function __construct($tableName, $alias = null)
14
    {
15 84
        if(empty($tableName))
16 84
        {
17 6
            throw new \InvalidArgumentException('Empty table name.');
18
        }
19
20 78
        $this->tableName = $tableName;
21
22 78
        $this->alias = (string) $alias;
23 78
    }
24
25 73
    public function toString()
26
    {
27 73
        if(empty($this->alias))
28 73
        {
29 38
            return $this->tableName;
30
        }
31
32 37
        return sprintf('%s AS %s', $this->tableName, $this->alias);
33
    }
34
35 9
    public function getName()
36
    {
37 9
        return $this->tableName;
38
    }
39
40 4
    public function getAlias()
41
    {
42 4
        return $this->alias;
43
    }
44
}
45