StatementTrait::hasNamedPlaceholders()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace BenTools\SimpleDBAL\Model;
4
5
use BenTools\SimpleDBAL\Contract\StatementInterface;
6
7
trait StatementTrait
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $values;
13
14
    /**
15
     * @inheritDoc
16
     */
17
    public function getValues(): ?array
18
    {
19
        return $this->values;
20
    }
21
22
    /**
23
     * @inheritDoc
24
     */
25
    public function withValues(array $values = null): StatementInterface
26
    {
27
        $clone = clone $this;
28
        $clone->values = $values;
0 ignored issues
show
Documentation Bug introduced by
It seems like $values can be null. However, the property $values is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

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

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
29
        return $clone;
30
    }
31
32
    /**
33
     * @return bool
34
     */
35
    protected function hasValues(): bool
36
    {
37
        return !empty($this->values);
38
    }
39
40
    /**
41
     * @return bool
42
     */
43
    protected function hasAnonymousPlaceholders(): bool
44
    {
45
        return $this->hasValues() && 0 === array_keys($this->values)[0];
46
    }
47
48
    /**
49
     * @return bool
50
     */
51
    protected function hasNamedPlaceholders(): bool
52
    {
53
        return $this->hasValues() && 'string' === gettype(array_keys($this->values)[0]);
54
    }
55
}
56