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

TableName   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 38
c 0
b 0
f 0
wmc 6
lcom 1
cbo 0
ccs 16
cts 16
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A toString() 0 9 2
A getName() 0 4 1
A getAlias() 0 4 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