Completed
Push — master ( b97768...587712 )
by Bartko
31:36
created

Zend2::getAncestors()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 24
cts 24
cp 1
rs 8.9528
c 0
b 0
f 0
cc 5
nc 9
nop 3
crap 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace StefanoTree\NestedSet\Adapter;
6
7
use StefanoTree\NestedSet\Options;
8
use Zend\Db\Adapter\Adapter as DbAdapter;
9
10
class Zend2 implements AdapterInterface
11
{
12
    private $connection;
13
    private $options;
14
15
    /**
16 115
     * @param Options   $options
17
     * @param DbAdapter $connection
18 115
     */
19 115
    public function __construct(Options $options, DbAdapter $connection)
20 115
    {
21
        $this->connection = $connection;
22
        $this->options = $options;
23
    }
24
25 115
    /**
26
     * @return DbAdapter
27 115
     */
28 115
    private function getConnection(): DbAdapter
29
    {
30
        return $this->connection;
31
    }
32
33 107
    /**
34
     * @return Options
35 107
     */
36
    public function getOptions(): Options
37
    {
38
        return $this->options;
39
    }
40
41
    public function beginTransaction(): void
42
    {
43 87
        $this->getConnection()
44
             ->getDriver()
45 87
             ->getConnection()
46
             ->beginTransaction();
47
    }
48
49
    public function commitTransaction(): void
50
    {
51
        $this->getConnection()
52
             ->getDriver()
53 30
             ->getConnection()
54
             ->commit();
55 30
    }
56
57
    public function rollbackTransaction(): void
58
    {
59
        $this->getConnection()
60
             ->getDriver()
61 32
             ->getConnection()
62
             ->rollback();
63 32
    }
64
65 32
    public function isInTransaction(): bool
66
    {
67 32
        return $this->getConnection()
68 32
             ->getDriver()
69 32
             ->getConnection()
70
             ->inTransaction();
71
    }
72 32
73
    public function canHandleNestedTransaction(): bool
74 32
    {
75 32
        return true;
76
    }
77
78
    public function quoteIdentifier(string $columnName): string
79
    {
80 32
        return $this->getConnection()
81
                    ->getPlatform()
82 32
                    ->quoteIdentifierChain(explode('.', $columnName));
83 32
    }
84 32
85 32
    public function executeInsertSQL(string $sql, array $params = array())
86 32
    {
87
        $options = $this->getOptions();
88
        $this->executeSQL($sql, $params);
89
90
        if (array_key_exists($options->getIdColumnName(), $params)) {
91 17
            return $params[$options->getIdColumnName()];
92
        } else {
93 17
            $lastGeneratedValue = $this->getConnection()
94 17
                                       ->getDriver()
95 17
                                       ->getLastGeneratedValue($options->getSequenceName());
0 ignored issues
show
Unused Code introduced by
The call to DriverInterface::getLastGeneratedValue() has too many arguments starting with $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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
96 17
97 17
            return $lastGeneratedValue;
98
        }
99
    }
100
101
    public function executeSQL(string $sql, array $params = array()): void
102 16
    {
103
        $this->getConnection()
104 16
             ->query($sql, $params);
105 16
    }
106 16
107 16
    public function executeSelectSQL(string $sql, array $params = array()): array
108 16
    {
109
        return $this->getConnection()
110
                    ->query($sql, $params)
111
                    ->toArray();
112
    }
113
}
114