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

From   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

3 Methods

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