GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

InsertQueryBuilder::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php declare (strict_types=1);
2
/**
3
 * @license MIT
4
 * @author Samuel Adeshina <[email protected]>
5
 */
6
namespace EmmetBlue\Core\Builder\QueryBuilder;
7
8
/**
9
 * class InsertQueryBuilder.
10
 * Builds an insert query.
11
 *
12
 * {@see QueryBuilder}
13
 *
14
 * @author Samuel Adeshina <[email protected]>
15
 *
16
 * @since 28/05/2016
17
 */
18
class InsertQueryBuilder extends QueryBuilder
19
{
20
    /**
21
     * @var \EmmetBlue\Core\Abstraction\QueryBuilder
22
     */
23
    protected $queryBuilder;
24
25
    /**
26
     * @param string|null $tableName
27
     */
28
    public function __construct(string $tableName = null)
29
    {
30
        $insertKeyword = (is_null($tableName)) ? 'INSERT' : 'INSERT INTO '.$tableName;
31
        $this->queryBuilder = $this->build($insertKeyword);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->build($insertKeyword) of type object<EmmetBlue\Core\Bu...ryBuilder\QueryBuilder> is incompatible with the declared type object<EmmetBlue\Core\Abstraction\QueryBuilder> of property $queryBuilder.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     *
37
     * @param string   $tableName
38
     * @param string[] $tableColumns Optional, provide this to specify the
39
     *                               columns that should be acted on
40
     *
41
     * @return \EmmetBlue\Core\Abstraction\InsertQueryBuilder
42
     */
43
    public function into(string $tableName, array $tableColumns = [])
44
    {
45
        $intoKeyword = 'INTO '.$tableName;
46
47
        if (!empty($tableColumns)) {
48
            $intoKeyword .= $this->wrapString(self::getImplodedString($tableColumns), '(', ')');
49
        }
50
51
        $this->queryBuilder = $this->queryBuilder->build($intoKeyword);
52
53
        return $this;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     *
59
     * @param string[] $inputValues
60
     *
61
     * @return \EmmetBlue\Core\Abstraction\InsertQueryBuilder
62
     */
63
    public function values(array $inputValues)
64
    {
65
        $valuesKeyword = 'VALUES ';
66
        $isMultidimentional = is_array($inputValues[0]);
67
68
        if (!$isMultidimentional) {
69
            $valuesKeyword .= $this->wrapString(self::getImplodedString($inputValues), '(', ')');
70
        } else {
71
            $tempValuesKeywords = [];
72
            foreach ($inputValues as $inputValue) {
73
                $tempValuesKeywords[] = $this->wrapString(self::getImplodedString($inputValue), '(', ')');
0 ignored issues
show
Bug introduced by
It seems like $inputValue defined by $inputValue on line 72 can also be of type string; however, EmmetBlue\Core\Builder\Q...er::getImplodedString() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
74
            }
75
76
            $valuesKeyword .= self::getImplodedString($tempValuesKeywords);
77
            unset($tempValuesKeywords);
78
        }
79
80
        $this->queryBuilder = $this->queryBuilder->build($valuesKeyword);
81
82
        return $this;
83
    }
84
}
85