Passed
Push — master ( 04c914...3973e0 )
by Bartko
02:23
created

LaminasDb::quoteIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace StefanoTree\NestedSet\Adapter;
6
7
use Laminas\Db\Adapter\Adapter as DbAdapter;
8
use StefanoTree\NestedSet\Options;
9
10
class LaminasDb implements AdapterInterface
11
{
12
    private $connection;
13
    private $options;
14
15
    /**
16
     * @param Options   $options
17
     * @param DbAdapter $connection
18
     */
19
    public function __construct(Options $options, DbAdapter $connection)
20
    {
21
        $this->connection = $connection;
22
        $this->options = $options;
23
    }
24
25
    /**
26
     * @return DbAdapter
27
     */
28
    private function getConnection(): DbAdapter
29
    {
30
        return $this->connection;
31
    }
32
33
    /**
34
     * @return Options
35
     */
36
    public function getOptions(): Options
37
    {
38
        return $this->options;
39
    }
40
41
    public function beginTransaction(): void
42
    {
43
        $this->getConnection()
44
            ->getDriver()
45
            ->getConnection()
46
            ->beginTransaction();
47
    }
48
49
    public function commitTransaction(): void
50
    {
51
        $this->getConnection()
52
            ->getDriver()
53
            ->getConnection()
54
            ->commit();
55
    }
56
57
    public function rollbackTransaction(): void
58
    {
59
        $this->getConnection()
60
            ->getDriver()
61
            ->getConnection()
62
            ->rollback();
63
    }
64
65
    public function isInTransaction(): bool
66
    {
67
        return $this->getConnection()
68
            ->getDriver()
69
            ->getConnection()
70
            ->inTransaction();
0 ignored issues
show
Bug introduced by
The method inTransaction() does not exist on Laminas\Db\Adapter\Driver\ConnectionInterface. Did you maybe mean beginTransaction()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
            ->/** @scrutinizer ignore-call */ inTransaction();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
    }
72
73
    public function canHandleNestedTransaction(): bool
74
    {
75
        return true;
76
    }
77
78
    public function quoteIdentifier(string $columnName): string
79
    {
80
        return $this->getConnection()
81
            ->getPlatform()
82
            ->quoteIdentifierChain(explode('.', $columnName));
83
    }
84
85
    public function executeInsertSQL(string $sql, array $params = array())
86
    {
87
        $options = $this->getOptions();
88
        $this->executeSQL($sql, $params);
89
90
        if (array_key_exists($options->getIdColumnName(), $params)) {
91
            return $params[$options->getIdColumnName()];
92
        } else {
93
            $lastGeneratedValue = $this->getConnection()
94
                ->getDriver()
95
                ->getLastGeneratedValue($options->getSequenceName());
0 ignored issues
show
Unused Code introduced by
The call to Laminas\Db\Adapter\Drive...getLastGeneratedValue() has too many arguments starting with $options->getSequenceName(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

95
                ->/** @scrutinizer ignore-call */ getLastGeneratedValue($options->getSequenceName());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
96
97
            return $lastGeneratedValue;
98
        }
99
    }
100
101
    public function executeSQL(string $sql, array $params = array()): void
102
    {
103
        $this->getConnection()
104
            ->query($sql, $params);
105
    }
106
107
    public function executeSelectSQL(string $sql, array $params = array()): array
108
    {
109
        return $this->getConnection()
110
            ->query($sql, $params)
111
            ->toArray();
0 ignored issues
show
Bug introduced by
The method toArray() does not exist on Laminas\Db\Adapter\Driver\StatementInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

111
            ->/** @scrutinizer ignore-call */ toArray();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
112
    }
113
}
114