Completed
Push — master ( e3cbb2...a5ac50 )
by Beniamin
02:59
created

QueryBuilderFactory::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 2
eloc 2
nc 2
nop 1
crap 6
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;
13
14
use Interop\Container\ContainerInterface;
15
use Phuria\SQLBuilder\DependencyInjection\InternalContainer;
16
use Phuria\SQLBuilder\QueryBuilder\DeleteBuilder;
17
use Phuria\SQLBuilder\QueryBuilder\InsertBuilder;
18
use Phuria\SQLBuilder\QueryBuilder\InsertSelectBuilder;
19
use Phuria\SQLBuilder\QueryBuilder\SelectBuilder;
20
use Phuria\SQLBuilder\QueryBuilder\UpdateBuilder;
21
22
/**
23
 * @author Beniamin Jonatan Šimko <[email protected]>
24
 */
25
class QueryBuilderFactory
26
{
27
    /**
28
     * @var ContainerInterface $container
29
     */
30
    private $container;
31
32
    /**
33
     * @param ContainerInterface $container
34
     */
35
    public function __construct(ContainerInterface $container)
36
    {
37
        $this->container = $container ?: new InternalContainer();
0 ignored issues
show
Documentation Bug introduced by
It seems like $container ?: new \Phuri...ion\InternalContainer() can also be of type object<Phuria\SQLBuilder...tion\InternalContainer>. However, the property $container is declared as type object<Interop\Container\ContainerInterface>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
38
    }
39
40
    /**
41
     * @return ContainerInterface
42
     */
43
    public function getContainer()
44
    {
45
        return $this->container;
46
    }
47
48
    /**
49
     * @return SelectBuilder
50
     */
51
    public function select()
52
    {
53
        return new SelectBuilder($this->container);
54
    }
55
56
    /**
57
     * @return UpdateBuilder
58
     */
59
    public function update()
60
    {
61
        return new UpdateBuilder($this->container);
62
    }
63
64
    /**
65
     * @return DeleteBuilder
66
     */
67
    public function delete()
68
    {
69
        return new DeleteBuilder($this->container);
70
    }
71
72
    /**
73
     * @return InsertBuilder
74
     */
75
    public function insert()
76
    {
77
        return new InsertBuilder($this->container);
78
    }
79
80
    /**
81
     * @return InsertSelectBuilder
82
     */
83
    public function insertSelect()
84
    {
85
        return new InsertSelectBuilder($this->container);
86
    }
87
}