BlockRepository   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 52 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 3
dl 26
loc 50
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findBlock() 0 12 1
A findTranslation() 26 26 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Alpixel\Bundle\CMSBundle\Entity\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
use Sonata\BlockBundle\Model\Block;
7
8
class BlockRepository extends EntityRepository
9
{
10
    /**
11
     * @param $type
12
     * @param $locale
13
     *
14
     * @throws \Doctrine\ORM\NonUniqueResultException
15
     *
16
     * @return \Alpixel\Bundle\CMSBundle\Entity\Block
17
     */
18
    public function findBlock($type, $locale)
19
    {
20
        return $this
21
            ->createQueryBuilder('b')
22
            ->andWhere('b.locale = :locale')
23
            ->andWhere('b.slug = :type')
24
            ->setParameter('locale', $locale)
25
            ->setParameter('type', $type)
26
            ->setMaxResults(1)
27
            ->getQuery()
28
            ->getOneOrNullResult();
29
    }
30
31 View Code Duplication
    public function findTranslation(Block $block, $locale)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33
        $source = null;
0 ignored issues
show
Unused Code introduced by
$source 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...
34
35
        // We are checking if the node is the translation provider or translated
36
        // from an other node
37
        if ($block->getTranslationSource() !== null) {
0 ignored issues
show
Bug introduced by
The method getTranslationSource() does not seem to exist on object<Sonata\BlockBundle\Model\Block>.

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...
38
            $source = $block->getTranslationSource();
0 ignored issues
show
Bug introduced by
The method getTranslationSource() does not seem to exist on object<Sonata\BlockBundle\Model\Block>.

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...
39
            if ($source->getLocale() == $locale) {
40
                return $source;
41
            }
42
        } else {
43
            $source = $block;
44
        }
45
46
        return $this->createQueryBuilder('n')
47
            ->addSelect('n')
48
            ->andWhere('n.translationSource = :source')
49
            ->andWhere('n.locale = :locale')
50
            ->setParameters([
51
                'source' => $source,
52
                'locale' => $locale,
53
            ])
54
            ->getQuery()
55
            ->getOneOrNullResult();
56
    }
57
}
58