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

From::toString()   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 From implements Snippet, NeedTableAware
8
{
9
    private
10
        $tableName;
11
12 44
    public function __construct($table, $alias = null)
13
    {
14 44
        if(! $table instanceof TableName)
15 44
        {
16 42
            $table = new TableName($table, $alias);
17 40
        }
18
19 42
        $this->tableName = $table;
20 42
    }
21
22 38
    public function toString()
23
    {
24 38
        return sprintf('FROM %s', $this->tableName->toString());
25
    }
26
27 6
    public function hasNeededTable($tableName)
28
    {
29 6
        if($this->tableName->getName() === $tableName || $this->tableName->getAlias() === $tableName)
30 6
        {
31 4
            return true;
32
        }
33
34 2
        return false;
35
    }
36
}
37