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

Doctrine2DBAL::getDescendants()   B

Complexity

Conditions 8
Paths 33

Size

Total Lines 54

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 33
CRAP Score 8

Importance

Changes 0
Metric Value
dl 0
loc 54
ccs 33
cts 33
cp 1
rs 7.7591
c 0
b 0
f 0
cc 8
nc 33
nop 4
crap 8

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
    public function __construct(Options $options, DbConnection $connection)
20 56
    {
21
        $this->connection = $connection;
22 56
        $this->options = $options;
23 56
    }
24 56
25
    /**
26
     * @return DbConnection
27
     */
28
    private function getConnection(): DbConnection
29 56
    {
30
        return $this->connection;
31 56
    }
32 56
33
    /**
34
     * @return Options
35
     */
36
    public function getOptions(): Options
37 53
    {
38
        return $this->options;
39 53
    }
40
41
    public function beginTransaction(): void
42
    {
43
        $this->getConnection()
44
            ->beginTransaction();
45
    }
46
47 32
    public function commitTransaction(): void
48
    {
49 32
        $this->getConnection()
50 32
            ->commit();
51
    }
52 32
53 32
    public function rollbackTransaction(): void
54
    {
55 32
        $this->getConnection()
56
            ->rollBack();
57
    }
58
59
    public function isInTransaction(): bool
60
    {
61
        return 0 === $this->getConnection()->getTransactionNestingLevel() ? false : true;
62
    }
63 17
64
    public function canHandleNestedTransaction(): bool
65 17
    {
66
        return true;
67
    }
68
69
    public function quoteIdentifier(string $columnName): string
70
    {
71 1
        return $this->getConnection()
72
            ->quoteIdentifier($columnName);
73 1
    }
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 1
        } else {
83 1
            return $this->getConnection()
84
                        ->lastInsertId($options->getSequenceName());
85
        }
86
    }
87
88 1
    public function executeSQL(string $sql, array $params = array()): void
89
    {
90 1
        $this->getConnection()
91 1
             ->executeQuery($sql, $params);
92 1
    }
93
94
    public function executeSelectSQL(string $sql, array $params = array()): array
95
    {
96
        return $this->getConnection()
97 1
             ->executeQuery($sql, $params)
98
            ->fetchAll();
99 1
    }
100
}
101