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

From::hasNeededTable()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.6666
cc 3
eloc 4
nc 2
nop 1
crap 3
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