Completed
Push — master ( 6e6249...28ec7c )
by Benjamin
23:40 queued 02:04
created

NodeRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B findTranslation() 0 28 3
1
<?php
2
3
namespace Alpixel\Bundle\CMSBundle\Entity\Repository;
4
5
use Alpixel\Bundle\CMSBundle\Entity\NodeInterface;
6
use Doctrine\ORM\EntityRepository;
7
8
class NodeRepository extends EntityRepository
9
{
10
    public function findTranslation(NodeInterface $nodeItem, $locale)
11
    {
12
        $node = $nodeItem->getNode();
0 ignored issues
show
Bug introduced by
The method getNode() does not seem to exist on object<Alpixel\Bundle\CM...e\Entity\NodeInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
13
14
        $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...
15
16
        // We are checking if the node is the translation provider or translated
17
        // from an other node
18
        if ($node->getTranslationSource() !== null) {
19
            $nodeSource = $node->getTranslationSource();
20
            if($nodeSource->getLocale() == $locale) {
21
                return $nodeSource;
22
            }
23
        } else {
24
            $nodeSource = $node;
25
        }
26
27
        return $this->createQueryBuilder('n')
28
                    ->addSelect('n')
29
                    ->andWhere('n.translationSource = :source')
30
                    ->andWhere('n.locale = :locale')
31
                    ->setParameters([
32
                        'source' => $nodeSource,
33
                        'locale' => $locale
34
                    ])
35
                    ->getQuery()
36
                    ->getOneOrNullResult();
37
        }
38
}
39