Completed
Push — master ( a98c98...92b268 )
by Bartko
02:00
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 9
    public function __construct(Options $options, DbAdapter $connection)
20
    {
21 9
        $this->connection = $connection;
22 9
        $this->options = $options;
23 9
    }
24
25
    /**
26
     * @return DbAdapter
27
     */
28 7
    private function getConnection(): DbAdapter
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
             ->getDriver()
45 4
             ->getConnection()
46 4
             ->beginTransaction();
47 4
    }
48
49 2
    public function commitTransaction(): void
50
    {
51 2
        $this->getConnection()
52 2
             ->getDriver()
53 2
             ->getConnection()
54 2
             ->commit();
55 2
    }
56
57 2
    public function rollbackTransaction(): void
58
    {
59 2
        $this->getConnection()
60 2
             ->getDriver()
61 2
             ->getConnection()
62 2
             ->rollback();
63 2
    }
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 1
    public function canHandleNestedTransaction(): bool
74
    {
75 1
        return true;
76
    }
77
78 1
    public function quoteIdentifier(string $columnName): string
79
    {
80 1
        return $this->getConnection()
81 1
                    ->getPlatform()
82 1
                    ->quoteIdentifierChain(explode('.', $columnName));
83
    }
84
85 1
    public function executeInsertSQL(string $sql, array $params = array())
86
    {
87 1
        $options = $this->getOptions();
88 1
        $this->executeSQL($sql, $params);
89
90 1
        if (array_key_exists($options->getIdColumnName(), $params)) {
91
            return $params[$options->getIdColumnName()];
92
        } else {
93 1
            $lastGeneratedValue = $this->getConnection()
94 1
                                       ->getDriver()
95 1
                                       ->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 1
            return $lastGeneratedValue;
98
        }
99
    }
100
101 2
    public function executeSQL(string $sql, array $params = array()): void
102
    {
103 2
        $this->getConnection()
104 2
             ->query($sql, $params);
105 2
    }
106
107 2
    public function executeSelectSQL(string $sql, array $params = array()): array
108
    {
109 2
        return $this->getConnection()
110 2
                    ->query($sql, $params)
111 2
                    ->toArray();
112
    }
113
}
114