Completed
Push — master ( 5a8e55...7a79d7 )
by Benjamin
07:38 queued 05:28
created

NodeRepository::findAllWithLocale()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 10
nc 1
nop 1
1
<?php
2
3
namespace Alpixel\Bundle\CMSBundle\Entity\Repository;
4
5
use Alpixel\Bundle\CMSBundle\Entity\Node;
6
use Doctrine\ORM\EntityRepository;
7
8
class NodeRepository extends EntityRepository
9
{
10
    public function findAllWithLocale($locale)
11
    {
12
        return $this
13
            ->getEntityManager()
14
            ->createQueryBuilder('n')
15
            ->andWhere('n.published = true')
16
            ->andWhere('n.locale = :locale')
17
            ->setParameter('locale', $locale)
18
            ->orderBy('n.position', 'ASC')
19
            ->getQuery()
20
            ->getResult();
21
    }
22
23
    public function findTranslation(Node $node, $locale)
24
    {
25
        $nodeSource = null;
0 ignored issues
show
Unused Code introduced by
$nodeSource is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
26
27
        // We are checking if the node is the translation provider or translated
28
        // from an other node
29
        if ($node->getTranslationSource() !== null) {
30
            $nodeSource = $node->getTranslationSource();
31
            if ($nodeSource->getLocale() == $locale) {
32
                return $nodeSource;
33
            }
34
        } else {
35
            $nodeSource = $node;
36
        }
37
38
        return $this->createQueryBuilder('n')
39
                    ->addSelect('n')
40
                    ->andWhere('n.translationSource = :source')
41
                    ->andWhere('n.locale = :locale')
42
                    ->setParameters([
43
                        'source' => $nodeSource,
44
                        'locale' => $locale,
45
                    ])
46
                    ->getQuery()
47
                    ->getOneOrNullResult();
48
    }
49
}
50