Code Duplication    Length = 34-35 lines in 2 locations

src/Kunstmaan/NodeBundle/Repository/NodeRepository.php 2 locations

@@ 350-384 (lines=35) @@
347
     *
348
     * @return Node[]
349
     */
350
    public function getAllParents(Node $node = null, $lang = null)
351
    {
352
        if (\is_null($node)) {
353
            return array();
354
        }
355
356
        $qb = $this->createQueryBuilder('node');
357
358
        // Directly hydrate the nodeTranslation and nodeVersion
359
        $qb->select('node', 't', 'v')
360
            ->innerJoin('node.nodeTranslations', 't')
361
            ->leftJoin(
362
                't.publicNodeVersion',
363
                'v',
364
                'WITH',
365
                't.publicNodeVersion = v.id'
366
            )
367
            ->where('node.deleted = 0');
368
369
        if ($lang) {
370
            $qb->andWhere('t.lang = :lang')
371
                ->setParameter('lang', $lang);
372
        }
373
374
        $qb->andWhere(
375
            $qb->expr()->andX(
376
                $qb->expr()->lte('node.lft', $node->getLeft()),
377
                $qb->expr()->gte('node.rgt', $node->getRight())
378
            )
379
        );
380
381
        $qb->addOrderBy('node.lft', 'ASC');
382
383
        return $qb->getQuery()->getResult();
384
    }
385
386
    /**
387
     * Get the root node of a given node.
@@ 394-427 (lines=34) @@
391
     *
392
     * @return Node
393
     */
394
    public function getRootNodeFor(Node $node = null, $lang = null)
395
    {
396
        if (\is_null($node)) {
397
            return null;
398
        }
399
400
        $qb = $this->createQueryBuilder('node');
401
402
        // Directly hydrate the nodeTranslation and nodeVersion
403
        $qb->select('node', 't', 'v')
404
            ->innerJoin('node.nodeTranslations', 't')
405
            ->leftJoin(
406
                't.publicNodeVersion',
407
                'v',
408
                'WITH',
409
                't.publicNodeVersion = v.id'
410
            )
411
            ->where('node.deleted = 0')
412
            ->andWhere('node.parent IS NULL');
413
414
        if ($lang) {
415
            $qb->andWhere('t.lang = :lang')
416
                ->setParameter('lang', $lang);
417
        }
418
419
        $qb->andWhere(
420
            $qb->expr()->andX(
421
                $qb->expr()->lte('node.lft', $node->getLeft()),
422
                $qb->expr()->gte('node.rgt', $node->getRight())
423
            )
424
        );
425
426
        return $qb->getQuery()->getOneOrNullResult();
427
    }
428
429
    /**
430
     * @return Node[]