Passed
Branch master (9026fd)
by Bartko
02:45
created

Doctrine2DBAL::rollbackTransaction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
ccs 3
cts 3
cp 1
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
    }
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
    }
46
47 2
    public function commitTransaction(): void
48
    {
49 2
        $this->getConnection()
50 2
            ->commit();
51
    }
52
53 2
    public function rollbackTransaction(): void
54
    {
55 2
        $this->getConnection()
56 2
            ->rollBack();
57
    }
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()
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getConnect...ons->getSequenceName()) also could return the type false which is incompatible with the return type mandated by StefanoTree\NestedSet\Ad...ace::executeInsertSQL() of integer|string.
Loading history...
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
    }
93
94 2
    public function executeSelectSQL(string $sql, array $params = array()): array
95
    {
96 2
        return $this->getConnection()
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\ForwardCom...lity\Result::fetchAll() has been deprecated: Use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead. ( Ignorable by Annotation )

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

96
        return /** @scrutinizer ignore-deprecated */ $this->getConnection()

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
97 2
            ->executeQuery($sql, $params)
98 2
            ->fetchAll();
99
    }
100
}
101