Completed
Push — master ( cf6d5b...ada276 )
by Bartko
02:30 queued 10s
created

Zend1::canHandleNestedTransaction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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