Code Duplication    Length = 34-35 lines in 2 locations

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

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