Completed
Push — v4-develop ( 528a0a )
by Bartko
02:29
created

Zend2::getDescendants()   B

Complexity

Conditions 8
Paths 33

Size

Total Lines 60

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 43
CRAP Score 8

Importance

Changes 0
Metric Value
dl 0
loc 60
ccs 43
cts 43
cp 1
rs 7.6282
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 StefanoTree\NestedSet\Options;
8
use Zend\Db\Adapter\Adapter as DbAdapter;
9
10
class Zend2 implements AdapterInterface
11
{
12
    private $connection;
13
    private $options;
14
15
    /**
16
     * @param Options   $options
17
     * @param DbAdapter $connection
18
     */
19 119
    public function __construct(Options $options, DbAdapter $connection)
20
    {
21 119
        $this->connection = $connection;
22 119
        $this->options = $options;
23 119
    }
24
25
    /**
26
     * @return DbAdapter
27
     */
28 114
    private function getConnection(): DbAdapter
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 36
    public function beginTransaction(): void
42
    {
43 36
        $this->getConnection()
44 36
             ->getDriver()
45 36
             ->getConnection()
46 36
             ->beginTransaction();
47 36
    }
48
49 19
    public function commitTransaction(): void
50
    {
51 19
        $this->getConnection()
52 19
             ->getDriver()
53 19
             ->getConnection()
54 19
             ->commit();
55 19
    }
56
57 18
    public function rollbackTransaction(): void
58
    {
59 18
        $this->getConnection()
60 18
             ->getDriver()
61 18
             ->getConnection()
62 18
             ->rollback();
63 18
    }
64
65 4
    public function isInTransaction(): bool
66
    {
67 4
        return $this->getConnection()
68 4
             ->getDriver()
69 4
             ->getConnection()
70 4
             ->inTransaction();
71
    }
72
73 32
    public function canHandleNestedTransaction(): bool
74
    {
75 32
        return true;
76
    }
77
78 107
    public function quoteIdentifier(string $columnName): string
79
    {
80 107
        return $this->getConnection()
81 107
                    ->getPlatform()
82 107
                    ->quoteIdentifierChain(explode('.', $columnName));
83
    }
84
85 15
    public function executeInsertSQL(string $sql, array $params = array())
86
    {
87 15
        $options = $this->getOptions();
88 15
        $this->executeSQL($sql, $params);
89
90 15
        if (array_key_exists($options->getIdColumnName(), $params)) {
91 2
            return $params[$options->getIdColumnName()];
92
        } else {
93 13
            $lastGeneratedValue = $this->getConnection()
94 13
                                       ->getDriver()
95 13
                                       ->getLastGeneratedValue($options->getSequenceName());
0 ignored issues
show
Unused Code introduced by
The call to DriverInterface::getLastGeneratedValue() has too many arguments starting with $options->getSequenceName().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
96
97 13
            return $lastGeneratedValue;
98
        }
99
    }
100
101 60
    public function executeSQL(string $sql, array $params = array()): void
102
    {
103 60
        $this->getConnection()
104 60
             ->query($sql, $params);
105 60
    }
106
107 86
    public function executeSelectSQL(string $sql, array $params = array()): array
108
    {
109 86
        return $this->getConnection()
110 86
                    ->query($sql, $params)
111 86
                    ->toArray();
112
    }
113
}
114