Completed
Pull Request — master (#1)
by Romain
02:07
created

From   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

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