Completed
Pull Request — master (#1)
by Romain
02:07
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
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Puzzle\QueryBuilder\Queries\Snippets;
6
7
use Puzzle\QueryBuilder\Snippet;
8
9
class TableName implements Snippet
10
{
11
    private
12
        $tableName,
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
13
        $alias;
14
15 84
    public function __construct(?string $tableName, ?string $alias = null)
16
    {
17 84
        if(empty($tableName))
18
        {
19 6
            throw new \InvalidArgumentException('Empty table name.');
20
        }
21
22 78
        $this->tableName = $tableName;
23
24 78
        $this->alias = (string) $alias;
25 78
    }
26
27 73
    public function toString(): string
28
    {
29 73
        if(empty($this->alias))
30
        {
31 38
            return $this->tableName;
32
        }
33
34 37
        return sprintf('%s AS %s', $this->tableName, $this->alias);
35
    }
36
37 9
    public function getName(): string
38
    {
39 9
        return $this->tableName;
40
    }
41
42 4
    public function getAlias(): string
43
    {
44 4
        return $this->alias;
45
    }
46
}
47