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

From::hasNeededTable()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

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