TableName::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4286
cc 2
eloc 5
nc 2
nop 2
crap 2
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 73
    public function __construct($tableName, $alias = null)
14
    {
15 73
        if(empty($tableName))
16 73
        {
17 6
            throw new \InvalidArgumentException('Empty table name.');
18
        }
19
20 67
        $this->tableName = $tableName;
21
22 67
        $this->alias = (string) $alias;
23 67
    }
24
25 65
    public function toString()
26
    {
27 65
        if(empty($this->alias))
28 65
        {
29 32
            return $this->tableName;
30
        }
31
32 35
        return sprintf('%s AS %s', $this->tableName, $this->alias);
33
    }
34
}
35