Completed
Pull Request — master (#19)
by Benjamin
06:09
created

NodeRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 8
Bugs 3 Features 0
Metric Value
wmc 4
c 8
b 3
f 0
lcom 0
cbo 1
dl 0
loc 42
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findAllWithLocale() 0 12 1
B findTranslation() 0 26 3
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