Completed
Push — develop ( 32afc4...f78f16 )
by Bartko
03:00
created

Zend2DbAdapter::setDefaultDbSelect()   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 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace StefanoTree\NestedSet\Adapter;
3
4
use StefanoDb\Adapter\Adapter as DbAdapter;
5
use StefanoTree\NestedSet\NodeInfo;
6
use StefanoTree\NestedSet\Options;
7
use Zend\Db;
8
9
class Zend2DbAdapter
10
    implements AdapterInterface
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
11
{
12
    private $options;
13
14
    private $dbAdapter;
15
16
    private $defaultDbSelect = null;
17
18 38
    public function __construct(Options $options, DbAdapter $dbAdapter)
19
    {
20 38
        $this->options = $options;
21 38
        $this->dbAdapter = $dbAdapter;
22 38
    }
23
24
    /**
25
     * @return Options
26
     */
27 37
    private function getOptions()
28
    {
29 37
        return $this->options;
30
    }
31
32
    /**
33
     * @return DbAdapter
34
     */
35 34
    private function getDbAdapter()
36
    {
37 34
        return $this->dbAdapter;
38
    }
39
40
    /**
41
     * Data cannot contain keys like idColumnName, levelColumnName, ...
42
     *
43
     * @param array $data
44
     * @return array
45
     */
46 2
    private function cleanData(array $data)
47
    {
48 2
        $options = $this->getOptions();
49
50
        $disallowedDataKeys = array(
51 2
            $options->getIdColumnName(),
52 2
            $options->getLeftColumnName(),
53 2
            $options->getRightColumnName(),
54 2
            $options->getLevelColumnName(),
55 2
            $options->getParentIdColumnName(),
56 2
            $options->getScopeColumnName(),
57 2
        );
58
59 2
        return array_diff_key($data, array_flip($disallowedDataKeys));
60
    }
61
62
    /**
63
     * @param Db\Sql\Select $dbSelect
64
     * @return void
65
     */
66 1
    public function setDefaultDbSelect(Db\Sql\Select $dbSelect)
67
    {
68 1
        $this->defaultDbSelect = $dbSelect;
69 1
    }
70
71
    /**
72
     * Return clone of default db select
73
     * @return Db\Sql\Select
74
     */
75 36
    public function getDefaultDbSelect()
76
    {
77 36
        $options = $this->getOptions();
78
79 36
        if (null == $this->defaultDbSelect) {
80 35
            $this->defaultDbSelect = new Db\Sql\Select($options->getTableName());
81 35
        }
82
83 36
        $dbSelect = clone $this->defaultDbSelect;
84
85 36
        return $dbSelect;
86
    }
87
88 14
    public function lockTree($scope)
89
    {
90 14
        $options = $this->getOptions();
91
92 14
        $dbAdapter = $this->getDbAdapter();
93
94 14
        $select = $this->getDefaultDbSelect();
95 14
        $select->columns(array(
96 14
            'i' => $options->getIdColumnName(),
97 14
        ));
98
99 14
        if ($options->getScopeColumnName()) {
100 4
            $select->where(array(
101 4
                $options->getScopeColumnName() => $scope,
102 4
            ));
103 4
        }
104
105 14
        $sql = $select->getSqlString($dbAdapter->getPlatform()) . ' FOR UPDATE';
106
107 14
        $dbAdapter->query($sql, DbAdapter::QUERY_MODE_EXECUTE);
108 14
    }
109
110 15
    public function beginTransaction()
111
    {
112 15
        $this->getDbAdapter()
113 15
             ->begin();
114 15
    }
115
116 14
    public function commitTransaction()
117
    {
118 14
        $this->getDbAdapter()
119 14
             ->commit();
120 14
    }
121
122 1
    public function rollbackTransaction()
123
    {
124 1
        $this->getDbAdapter()
125 1
             ->rollback();
126 1
    }
127
128 2
    public function update($nodeId, array $data)
129
    {
130 2
        $options = $this->getOptions();
131
132 2
        $dbAdapter = $this->getDbAdapter();
133
134 2
        $data = $this->cleanData($data);
135
136 2
        $update = new Db\Sql\Update($options->getTableName());
137 2
        $update->set($data)
138 2
               ->where(array(
139 2
                    $options->getIdColumnName() => $nodeId,
140 2
               ));
141
142 2
        $dbAdapter->query($update->getSqlString($dbAdapter->getPlatform()),
143 2
                DbAdapter::QUERY_MODE_EXECUTE);
144 2
    }
145
146 9
    public function insert(NodeInfo $nodeInfo, array $data)
147
    {
148 9
        $options = $this->getOptions();
149
150 9
        $dbAdapter = $this->getDbAdapter();
151
152 9
        $data[$options->getParentIdColumnName()] = $nodeInfo->getParentId();
153 9
        $data[$options->getLevelColumnName()]    = $nodeInfo->getLevel();
154 9
        $data[$options->getLeftColumnName()]     = $nodeInfo->getLeft();
155 9
        $data[$options->getRightColumnName()]    = $nodeInfo->getRight();
156
157 9
        if ($options->getScopeColumnName()) {
158 3
            $data[$options->getScopeColumnName()] = $nodeInfo->getScope();
159 3
        }
160
161 9
        $insert = new Db\Sql\Insert($options->getTableName());
162 9
        $insert->values($data);
163 9
        $dbAdapter->query($insert->getSqlString($dbAdapter->getPlatform()),
164 9
            DbAdapter::QUERY_MODE_EXECUTE);
165
166 9
        $lastGeneratedValue = $dbAdapter->getDriver()
167 9
                                        ->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...
168
169 9
        return $lastGeneratedValue;
170
    }
171
172 3
    public function delete($leftIndex, $rightIndex, $scope=null)
173
    {
174 2
        $options = $this->getOptions();
175
176 2
        $dbAdapter = $this->getDbAdapter();
177
178 2
        $delete = new Db\Sql\Delete($options->getTableName());
179 2
        $delete->where
180 2
               ->greaterThanOrEqualTo($options->getLeftColumnName(), $leftIndex)
181 2
               ->AND
182 2
               ->lessThanOrEqualTo($options->getRightColumnName(), $rightIndex);
183
184 3
        if ($options->getScopeColumnName()) {
185 1
            $delete->where
186 2
                   ->AND
187 1
                   ->equalTo($options->getScopeColumnName(), $scope);
188 1
        }
189
190 2
        $dbAdapter->query($delete->getSqlString($dbAdapter->getPlatform()),
191 2
            DbAdapter::QUERY_MODE_EXECUTE);
192 2
    }
193
194 12
    public function moveLeftIndexes($fromIndex, $shift, $scope=null)
195
    {
196 12
        $options = $this->getOptions();
197
198 12
        if (0 == $shift) {
199
            return;
200
        }
201
202 12
        $dbAdapter = $this->getDbAdapter();
203 12
        $dbPlatform = $dbAdapter->getPlatform();
204
205 12
        $sql = 'UPDATE ' . $dbPlatform->quoteIdentifier($options->getTableName())
206 12
                . ' SET '
207 12
                    . $dbPlatform->quoteIdentifier($options->getLeftColumnName()) . ' = '
208 12
                        . $dbPlatform->quoteIdentifier($options->getLeftColumnName()) . ' + :shift'
209 12
                . ' WHERE '
210 12
                    . $dbPlatform->quoteIdentifier($options->getLeftColumnName()) . ' > :fromIndex';
211
212 12
        if ($options->getScopeColumnName()) {
213 3
            $sql .= ' AND ' . $dbPlatform->quoteIdentifier($options->getScopeColumnName()) . ' = ' . $dbPlatform->quoteValue($scope);
214 3
        }
215
216
        $binds = array(
217 12
            ':shift' => $shift,
218 12
            ':fromIndex' => $fromIndex,
219 12
        );
220
221 12
        $dbAdapter->query($sql)
0 ignored issues
show
Bug introduced by
The method execute does only exist in Zend\Db\Adapter\Driver\StatementInterface, but not in Zend\Db\Adapter\Driver\R...tSet\ResultSetInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
222 12
                  ->execute($binds);
223 12
    }
224
225 12
    public function moveRightIndexes($fromIndex, $shift, $scope=null)
226
    {
227 12
        $options = $this->getOptions();
228
229 12
        if (0 == $shift) {
230
            return;
231
        }
232
233 12
        $dbAdapter = $this->getDbAdapter();
234 12
        $dbPlatform = $dbAdapter->getPlatform();
235
236 12
        $sql = 'UPDATE ' . $dbPlatform->quoteIdentifier($options->getTableName())
237 12
                . ' SET '
238 12
                    . $dbPlatform->quoteIdentifier($options->getRightColumnName()) . ' = '
239 12
                        . $dbPlatform->quoteIdentifier($options->getRightColumnName()) . ' + :shift'
240 12
                . ' WHERE '
241 12
                    . $dbPlatform->quoteIdentifier($options->getRightColumnName()) . ' > :fromIndex';
242
243 12
        if ($options->getScopeColumnName()) {
244 3
            $sql .= ' AND ' . $dbPlatform->quoteIdentifier($options->getScopeColumnName()) . ' = ' . $dbPlatform->quoteValue($scope);
245 3
        }
246
247
        $binds = array(
248 12
            ':shift' => $shift,
249 12
            ':fromIndex' => $fromIndex,
250 12
        );
251
252 12
        $dbAdapter->query($sql)
0 ignored issues
show
Bug introduced by
The method execute does only exist in Zend\Db\Adapter\Driver\StatementInterface, but not in Zend\Db\Adapter\Driver\R...tSet\ResultSetInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
253 12
                  ->execute($binds);
254 12
    }
255
256 33
    public function updateParentId($nodeId, $newParentId)
257
    {
258 4
        $options = $this->getOptions();
259
260 4
        $dbAdapter = $this->getDbAdapter();
261
262 4
        $update = new Db\Sql\Update($options->getTableName());
263 4
        $update->set(array(
264 4
                    $options->getParentIdColumnName() => $newParentId,
265 33
               ))
266 4
               ->where(array(
267 4
                   $options->getIdColumnName() => $nodeId,
268 4
               ));
269
270 4
        $dbAdapter->query($update->getSqlString($dbAdapter->getPlatform()),
271 4
            DbAdapter::QUERY_MODE_EXECUTE);
272 4
    }
273
274 5
    public function updateLevels($leftIndexFrom, $rightIndexTo, $shift, $scope=null)
275
    {
276 5
        $options = $this->getOptions();
277
278 5
        if (0 == $shift) {
279 1
            return;
280
        }
281
282 4
        $dbAdapter = $this->getDbAdapter();
283 4
        $dbPlatform = $dbAdapter->getPlatform();
284
285 4
        $sql = 'UPDATE ' . $dbPlatform->quoteIdentifier($options->getTableName())
286 4
            . ' SET '
287 4
                . $dbPlatform->quoteIdentifier($options->getLevelColumnName()) . ' = '
288 4
                    . $dbPlatform->quoteIdentifier($options->getLevelColumnName()) . ' + :shift'
289 4
            . ' WHERE '
290 4
                . $dbPlatform->quoteIdentifier($options->getLeftColumnName()) . ' >= :leftFrom'
291 4
                . ' AND ' . $dbPlatform->quoteIdentifier($options->getRightColumnName()) . ' <= :rightTo';
292
293 4
        if ($options->getScopeColumnName()) {
294
            $sql .= ' AND ' . $dbPlatform->quoteIdentifier($options->getScopeColumnName()) . ' = ' . $dbPlatform->quoteValue($scope);
295
        }
296
297
        $binds = array(
298 4
            ':shift' => $shift,
299 4
            ':leftFrom' => $leftIndexFrom,
300 4
            ':rightTo' => $rightIndexTo,
301 4
        );
302
303 4
        $dbAdapter->query($sql)
0 ignored issues
show
Bug introduced by
The method execute does only exist in Zend\Db\Adapter\Driver\StatementInterface, but not in Zend\Db\Adapter\Driver\R...tSet\ResultSetInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
304 4
                  ->execute($binds);
305 4
    }
306
307 5
    public function moveBranch($leftIndexFrom, $rightIndexTo, $shift, $scope=null)
308
    {
309 5
        if (0 == $shift) {
310
            return;
311
        }
312
313 5
        $options = $this->getOptions();
314
315 5
        $dbAdapter = $this->getDbAdapter();
316 5
        $dbPlatform = $dbAdapter->getPlatform();
317
318 5
        $sql = 'UPDATE ' . $dbPlatform->quoteIdentifier($options->getTableName())
319 5
            . ' SET '
320 5
                . $dbPlatform->quoteIdentifier($options->getLeftColumnName()) . ' = '
321 5
                    . $dbPlatform->quoteIdentifier($options->getLeftColumnName()) . ' + :shift, '
322 5
                . $dbPlatform->quoteIdentifier($options->getRightColumnName()) . ' = '
323 5
                    . $dbPlatform->quoteIdentifier($options->getRightColumnName()) . ' + :shift'
324 5
            . ' WHERE '
325 5
                . $dbPlatform->quoteIdentifier($options->getLeftColumnName()) . ' >= :leftFrom'
326 5
                . ' AND ' . $dbPlatform->quoteIdentifier($options->getRightColumnName()) . ' <= :rightTo';
327
328 5
        if ($options->getScopeColumnName()) {
329 1
            $sql .= ' AND ' . $dbPlatform->quoteIdentifier($options->getScopeColumnName()) . ' = ' . $dbPlatform->quoteValue($scope);
330 1
        }
331
332
        $binds = array(
333 5
            ':shift' => $shift,
334 5
            ':leftFrom' => $leftIndexFrom,
335 5
            ':rightTo' => $rightIndexTo,
336 5
        );
337
338 5
        $dbAdapter->query($sql)
0 ignored issues
show
Bug introduced by
The method execute does only exist in Zend\Db\Adapter\Driver\StatementInterface, but not in Zend\Db\Adapter\Driver\R...tSet\ResultSetInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
339 5
                  ->execute($binds);
340 5
    }
341
342 8
    public function getRoots($scope=null)
343
    {
344 8
        $options = $this->getOptions();
345
346 8
        $dbAdapter = $this->getDbAdapter();
347
348 8
        $select = $this->getDefaultDbSelect();
349 8
        $select->where
350 8
            ->equalTo($options->getParentIdColumnName(),  0);
351
352 8
        if (null != $scope && $options->getScopeColumnName()) {
353 2
            $select->where
354 2
                ->equalTo($options->getScopeColumnName(), $scope);
355 2
        }
356
357 8
        $result = $dbAdapter->query($select->getSqlString($dbAdapter->getPlatform()),
358 8
            DbAdapter::QUERY_MODE_EXECUTE);
359
360 8
        return $result->toArray();
361
    }
362
363 7
    public function getRoot($scope=null)
364
    {
365 7
        $roots = $this->getRoots($scope);
366
367 7
        return (0 < count($roots)) ?  $roots[0] : array();
368
    }
369
370 25
    public function getNode($nodeId)
371
    {
372 25
        $options = $this->getOptions();
373
374 25
        $nodeId = (int) $nodeId;
375
376 25
        $dbAdapter = $this->getDbAdapter();
377
378 25
        $select = $this->getDefaultDbSelect()
379 25
                       ->where(array($options->getIdColumnName() =>  $nodeId));
380
381 25
        $result = $dbAdapter->query($select->getSqlString($dbAdapter->getPlatform()),
382 25
                DbAdapter::QUERY_MODE_EXECUTE);
383
384 25
        $array = $result->toArray();
385
386 25
        if (0 < count($array)) {
387 24
            return $array[0];
388
        }
389 7
    }
390
391
    /**
392
     * @param array $data
393
     * @return NodeInfo
394
     */
395 22
    private function _buildNodeInfoObject(array $data)
396
    {
397 22
        $options = $this->getOptions();
398
399 22
        $id        = $data[$options->getIdColumnName()];
400 22
        $parentId  = $data[$options->getParentIdColumnName()];
401 22
        $level     = $data[$options->getLevelColumnName()];
402 22
        $left      = $data[$options->getLeftColumnName()];
403 22
        $right     = $data[$options->getRightColumnName()];
404
405 22
        if (isset($data[$options->getScopeColumnName()])) {
406 9
            $scope = $data[$options->getScopeColumnName()];
407 9
        } else {
408 13
            $scope = null;
409
        }
410
411 22
        return new NodeInfo($id, $parentId, $level, $left, $right, $scope);
412
    }
413
414 23
    public function getNodeInfo($nodeId)
415
    {
416 23
        $data = $this->getNode($nodeId);
417
418 23
        $result = ($data) ? $this->_buildNodeInfoObject($data) : null;
419
420 23
        return $result;
421
    }
422
423 3
    public function getChildrenNodeInfo($parentNodeId)
424
    {
425 3
        $dbAdapter = $this->getDbAdapter();
426 3
        $options = $this->getOptions();
427
428
        $columns = array(
429 3
            $options->getIdColumnName(),
430 3
            $options->getLeftColumnName(),
431 3
            $options->getRightColumnName(),
432 3
            $options->getParentIdColumnName(),
433 3
            $options->getLevelColumnName(),
434 3
        );
435
436 3
        if ($options->getScopeColumnName()) {
437 3
            $columns[] = $options->getScopeColumnName();
438 3
        }
439
440 3
        $select = $this->getDefaultDbSelect();
441 3
        $select->columns($columns);
442 3
        $select->order($options->getLeftColumnName());
443 3
        $select->where(array(
444 3
            $options->getParentIdColumnName() => $parentNodeId
445 3
        ));
446
447 3
        $data= $dbAdapter->query($select->getSqlString($dbAdapter->getPlatform()),
448 3
            DbAdapter::QUERY_MODE_EXECUTE);
449
450 3
        $result = array();
451
452 3
        foreach ($data->toArray() as $nodeData) {
453 3
            $result[] = $this->_buildNodeInfoObject($nodeData);
454 3
        }
455
456 3
        return $result;
457
    }
458
459 1
    public function updateNodeMetadata(NodeInfo $nodeInfo)
460
    {
461 1
        $dbAdapter = $this->getDbAdapter();
462 1
        $options = $this->getOptions();
463
464 1
        $update = new Db\Sql\Update($options->getTableName());
465
466 1
        $update->set(array(
467 1
            $options->getRightColumnName() => $nodeInfo->getRight(),
468 1
            $options->getLeftColumnName() => $nodeInfo->getLeft(),
469 1
            $options->getLevelColumnName() => $nodeInfo->getLevel(),
470 1
        ));
471
472 1
        $update->where(array(
473 1
            $options->getIdColumnName() => $nodeInfo->getId(),
474 1
        ));
475
476 1
        $dbAdapter->query($update->getSqlString($dbAdapter->getPlatform()),
477 1
            DbAdapter::QUERY_MODE_EXECUTE);
478 1
    }
479
480
481 2
    public function getPath($nodeId, $startLevel = 0, $excludeLastNode = false)
482
    {
483 2
        $options = $this->getOptions();
484
485 2
        $startLevel = (int) $startLevel;
486
487
        // node does not exist
488 2
        if (!$nodeInfo = $this->getNodeInfo($nodeId)) {
489 1
            return;
490
        }
491
492 2
        $dbAdapter = $this->getDbAdapter();
493
494 2
        $select = $this->getDefaultDbSelect();
495
496 2
        if ($options->getScopeColumnName()) {
497 1
            $select->where
498 1
                ->equalTo($options->getScopeColumnName(), $nodeInfo->getScope());
499 1
        }
500
501 2
        $select->where
502 2
               ->lessThanOrEqualTo($options->getLeftColumnName(), $nodeInfo->getLeft())
503 2
               ->AND
504 2
               ->greaterThanOrEqualTo($options->getRightColumnName(), $nodeInfo->getRight());
505
506 2
        $select->order($options->getLeftColumnName() . ' ASC');
507
508 2
        if (0 < $startLevel) {
509 1
            $select->where
510 1
                   ->greaterThanOrEqualTo($options->getLevelColumnName(), $startLevel);
511 1
        }
512
513 2
        if (true == $excludeLastNode) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
514 1
            $select->where
515 1
                   ->lessThan($options->getLevelColumnName(), $nodeInfo->getLevel());
516 1
        }
517
518 2
        $result = $dbAdapter->query($select->getSqlString($dbAdapter->getPlatform()),
519 2
            DbAdapter::QUERY_MODE_EXECUTE);
520
521 2
        return $result->toArray();
522
    }
523
524 3
    public function getDescendants($nodeId = 1, $startLevel = 0, $levels = null, $excludeBranch = null)
525
    {
526 3
        $options = $this->getOptions();
527
528 3
        if (!$nodeInfo = $this->getNodeInfo($nodeId)) {
529 2
            return;
530
        }
531
532 3
        $dbAdapter = $this->getDbAdapter();
533 3
        $select = $this->getDefaultDbSelect();
534 3
        $select->order($options->getLeftColumnName() . ' ASC');
535
536 3
        if ($options->getScopeColumnName()) {
537 1
            $select->where
538 1
                   ->equalTo($options->getScopeColumnName(), $nodeInfo->getScope());
539 1
        }
540
541 3
        if (0 != $startLevel) {
542 2
            $level = $nodeInfo->getLevel() + (int) $startLevel;
543 2
            $select->where
544 2
                   ->greaterThanOrEqualTo($options->getLevelColumnName(), $level);
545 2
        }
546
547 3
        if (null != $levels) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $levels of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison !== instead.
Loading history...
548 2
            $endLevel = $nodeInfo->getLevel() + (int) $startLevel + abs($levels);
549 2
            $select->where
550 2
                   ->lessThan($options->getLevelColumnName(), $endLevel);
551 2
        }
552
553 3
        if (null != $excludeBranch && null != ($excludeNodeInfo = $this->getNodeInfo($excludeBranch))) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $excludeBranch of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison !== instead.
Loading history...
554 1
            $select->where
555 1
                   ->NEST
556 1
                   ->between($options->getLeftColumnName(),
557 1
                        $nodeInfo->getLeft(), $excludeNodeInfo->getLeft() - 1)
558 1
                   ->OR
559 1
                   ->between($options->getLeftColumnName(),
560 1
                        $excludeNodeInfo->getRight() + 1, $nodeInfo->getRight())
561 1
                   ->UNNEST
562 1
                   ->AND
563 1
                   ->NEST
564 1
                   ->between($options->getRightColumnName(),
565 1
                        $excludeNodeInfo->getRight() + 1, $nodeInfo->getRight())
566 1
                   ->OR
567 1
                   ->between($options->getRightColumnName(),
568 1
                        $nodeInfo->getLeft(), $excludeNodeInfo->getLeft() - 1)
569 1
                   ->UNNEST;
570 1
        } else {
571 3
            $select->where
572 3
                   ->greaterThanOrEqualTo($options->getLeftColumnName(), $nodeInfo->getLeft())
573 3
                   ->AND
574 3
                   ->lessThanOrEqualTo($options->getRightColumnName(), $nodeInfo->getRight());
575
        }
576
577 3
        $result =  $dbAdapter->query($select->getSqlString($dbAdapter->getPlatform()),
578 3
            DbAdapter::QUERY_MODE_EXECUTE);
579
580 3
        $resultArray = $result->toArray();
581
582 3
        if (0 < count($resultArray)) {
583 3
            return $resultArray;
584
        }
585 1
    }
586
}
587