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

Zend1::executeSQL()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
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_Abstract as ZendDbAdapter;
9
10
class Zend1 implements AdapterInterface
11
{
12
    private $connection;
13
    private $options;
14
15
    /**
16 56
     * @param Options       $options
17
     * @param ZendDbAdapter $connection
18 56
     */
19 56
    public function __construct(Options $options, ZendDbAdapter $connection)
20 56
    {
21
        $this->connection = $connection;
22
        $this->options = $options;
23
    }
24
25 56
    /**
26
     * @return ZendDbAdapter
27 56
     */
28 56
    private function getConnection(): ZendDbAdapter
29
    {
30
        return $this->connection;
31
    }
32
33 53
    /**
34
     * @return Options
35 53
     */
36
    public function getOptions(): Options
37
    {
38
        return $this->options;
39
    }
40
41
    public function beginTransaction(): void
42
    {
43 32
        $this->getConnection()
44
             ->beginTransaction();
45 32
    }
46 32
47 32
    public function commitTransaction(): void
48
    {
49
        $this->getConnection()
50
             ->commit();
51
    }
52
53
    public function rollbackTransaction(): void
54
    {
55 17
        $this->getConnection()
56
             ->rollBack();
57 17
    }
58
59
    public function isInTransaction(): bool
60
    {
61
        return $this->getConnection()
62
                    ->getConnection()
63 1
                    ->inTransaction();
64
    }
65 1
66
    public function canHandleNestedTransaction(): bool
67 1
    {
68
        return false;
69 1
    }
70 1
71 1
    public function quoteIdentifier(string $columnName): string
72 1
    {
73
        return $this->getConnection()
74 1
                    ->quoteIdentifier($columnName);
75 1
    }
76
77
    public function executeInsertSQL(string $sql, array $params = array())
78
    {
79
        $options = $this->getOptions();
80 1
        $this->executeSQL($sql, $params);
81
82 1
        if (array_key_exists($options->getIdColumnName(), $params)) {
83 1
            return $params[$options->getIdColumnName()];
84
        } else {
85
            if ('' != $options->getSequenceName()) {
86
                $lastGeneratedValue = $this->getConnection()
87
                                           ->lastSequenceId($options->getSequenceName());
88 1
            } else {
89
                $lastGeneratedValue = $this->getConnection()
90 1
                                           ->lastInsertId();
91 1
            }
92
93
            return $lastGeneratedValue;
94
        }
95
    }
96 1
97
    public function executeSQL(string $sql, array $params = array()): void
98 1
    {
99 1
        $this->getConnection()
100
             ->query($sql, $params);
101
    }
102
103
    public function executeSelectSQL(string $sql, array $params = array()): array
104 3
    {
105
        return $this->getConnection()
106 3
                    ->query($sql, $params)
107
                    ->fetchAll();
108 3
    }
109
}
110