Completed
Push — master ( 7e2c41...06ecd1 )
by Beniamin
02:28
created

TableComponentTrait::addRootTable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
crap 2
1
<?php
2
3
/**
4
 * This file is part of Phuria SQL Builder package.
5
 *
6
 * Copyright (c) 2016 Beniamin Jonatan Šimko
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phuria\SQLBuilder\QueryBuilder\Component;
13
14
use Phuria\SQLBuilder\QueryBuilder\BuilderInterface;
15
use Phuria\SQLBuilder\Table\AbstractTable;
16
use Phuria\SQLBuilder\TableFactory\TableFactoryInterface;
17
18
/**
19
 * @author Beniamin Jonatan Šimko <[email protected]>
20
 */
21
trait TableComponentTrait
22
{
23
    /**
24
     * @var AbstractTable[] $tables
25
     */
26
    private $rootTables = [];
27
28
    /**
29
     * @return TableFactoryInterface
30
     */
31
    abstract protected function getTableFactory();
32
33
    /**
34
     * @return BuilderInterface
35
     */
36
    abstract public function getQueryBuilder();
37
38
    /**
39
     * @param mixed  $table
40
     * @param string $alias
0 ignored issues
show
Documentation introduced by
Should the type for parameter $alias not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
41
     *
42
     * @return AbstractTable
43
     */
44 1
    public function addRootTable($table, $alias = null)
45
    {
46 1
        $this->rootTables[] = $table = $this->getTableFactory()->createNewTable($table, $this->getQueryBuilder());
47
48 1
        if ($alias) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $alias of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
49 1
            $table->setAlias($alias);
50 1
        }
51
52 1
        return $table;
53
    }
54
55
    /**
56
     * @return AbstractTable[]
57
     */
58 1
    public function getRootTables()
59
    {
60 1
        return $this->rootTables;
61
    }
62
}