EmulatedStatement   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 49
c 0
b 0
f 0
wmc 7
lcom 1
cbo 3
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getWrappedStatement() 0 4 1
A bind() 0 4 1
A getRunnableQuery() 0 7 2
A createResult() 0 6 2
1
<?php
2
3
namespace BenTools\SimpleDBAL\Model\Adapter\Mysqli;
4
5
use BenTools\SimpleDBAL\Contract\ResultInterface;
6
7
class EmulatedStatement extends Statement
8
{
9
    /**
10
     * @inheritDoc
11
     */
12
    public function __construct(MysqliAdapter $connection, array $values = null, $queryString)
13
    {
14
        $this->connection          = $connection;
15
        $this->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...
16
        $this->queryString         = $queryString;
17
    }
18
19
    /**
20
     * @inheritDoc
21
     */
22
    public function getWrappedStatement()
23
    {
24
        throw new \RuntimeException("Wrapped statement is unavailable on emulated statements.");
25
    }
26
27
    /**
28
     * @inheritDoc
29
     */
30
    public function bind(): void
31
    {
32
        $this->runnableQueryString = $this->preview();
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function getRunnableQuery()
39
    {
40
        if (null === $this->runnableQueryString) {
41
            throw new \RuntimeException("Unbound query, run bind() before.");
42
        }
43
        return $this->runnableQueryString;
44
    }
45
46
    /**
47
     * @inheritDoc
48
     */
49
    public function createResult(): ResultInterface
50
    {
51
        $this->bind();
52
        $mysqliResult = $this->getConnection()->getWrappedConnection()->query($this->getRunnableQuery());
53
        return new Result($this->getConnection()->getWrappedConnection(), $mysqliResult instanceof \mysqli_result ? $mysqliResult : null);
0 ignored issues
show
Bug introduced by
It seems like $this->getConnection()->getWrappedConnection() targeting BenTools\SimpleDBAL\Mode...:getWrappedConnection() can also be of type object<PDO>; however, BenTools\SimpleDBAL\Mode...i\Result::__construct() does only seem to accept object<mysqli>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
54
    }
55
}
56