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

Doctrine2DBAL   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Test Coverage

Coverage 97.3%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 29
c 1
b 1
f 0
dl 0
loc 89
rs 10
ccs 36
cts 37
cp 0.973
wmc 14

12 Methods

Rating   Name   Duplication   Size   Complexity  
A rollbackTransaction() 0 4 1
A __construct() 0 4 1
A commitTransaction() 0 4 1
A isInTransaction() 0 3 2
A executeSelectSQL() 0 5 1
A getConnection() 0 3 1
A beginTransaction() 0 4 1
A getOptions() 0 3 1
A canHandleNestedTransaction() 0 3 1
A quoteIdentifier() 0 4 1
A executeSQL() 0 4 1
A executeInsertSQL() 0 10 2
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