Completed
Push — master ( a98c98...92b268 )
by Bartko
02:00
created

Doctrine2DBAL::executeSelectSQL()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
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 Doctrine\DBAL\Connection as DbConnection;
8
use StefanoTree\NestedSet\Options;
9
10
class Doctrine2DBAL implements AdapterInterface
11
{
12
    private $connection;
13
    private $options;
14
15
    /**
16
     * @param Options      $options
17
     * @param DbConnection $connection
18
     */
19 9
    public function __construct(Options $options, DbConnection $connection)
20
    {
21 9
        $this->connection = $connection;
22 9
        $this->options = $options;
23 9
    }
24
25
    /**
26
     * @return DbConnection
27
     */
28 7
    private function getConnection(): DbConnection
29
    {
30 7
        return $this->connection;
31
    }
32
33
    /**
34
     * @return Options
35
     */
36 1
    public function getOptions(): Options
37
    {
38 1
        return $this->options;
39
    }
40
41 4
    public function beginTransaction(): void
42
    {
43 4
        $this->getConnection()
44 4
            ->beginTransaction();
45 4
    }
46
47 2
    public function commitTransaction(): void
48
    {
49 2
        $this->getConnection()
50 2
            ->commit();
51 2
    }
52
53 2
    public function rollbackTransaction(): void
54
    {
55 2
        $this->getConnection()
56 2
            ->rollBack();
57 2
    }
58
59 4
    public function isInTransaction(): bool
60
    {
61 4
        return 0 === $this->getConnection()->getTransactionNestingLevel() ? false : true;
62
    }
63
64 1
    public function canHandleNestedTransaction(): bool
65
    {
66 1
        return true;
67
    }
68
69 1
    public function quoteIdentifier(string $columnName): string
70
    {
71 1
        return $this->getConnection()
72 1
            ->quoteIdentifier($columnName);
73
    }
74
75 1
    public function executeInsertSQL(string $sql, array $params = array())
76
    {
77 1
        $options = $this->getOptions();
78 1
        $this->executeSQL($sql, $params);
79
80 1
        if (array_key_exists($options->getIdColumnName(), $params)) {
81
            return $params[$options->getIdColumnName()];
82
        } else {
83 1
            return $this->getConnection()
84 1
                        ->lastInsertId($options->getSequenceName());
85
        }
86
    }
87
88 2
    public function executeSQL(string $sql, array $params = array()): void
89
    {
90 2
        $this->getConnection()
91 2
             ->executeQuery($sql, $params);
92 2
    }
93
94 2
    public function executeSelectSQL(string $sql, array $params = array()): array
95
    {
96 2
        return $this->getConnection()
97 2
             ->executeQuery($sql, $params)
98 2
            ->fetchAll();
99
    }
100
}
101