Passed
Push — master ( 9b03f8...7af85f )
by Dāvis
03:01
created

BaseAdmin2   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 33
loc 33
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRedis() 10 10 2
A postUpdate() 4 4 1
A getTranslationFilter() 12 12 2

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 Sludio\HelperBundle\Translatable\Admin;
4
5
use Sonata\AdminBundle\Admin\Admin;
6
7 View Code Duplication
class BaseAdmin2 extends Admin
0 ignored issues
show
Deprecated Code introduced by
The class Sonata\AdminBundle\Admin\Admin has been deprecated: since version 3.1, to be removed in 4.0. Use Sonata\AdminBundle\AbstractAdmin instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

7
class BaseAdmin2 extends /** @scrutinizer ignore-deprecated */ Admin
Loading history...
Duplication introduced by
This class 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...
8
{
9
    protected function getRedis()
10
    {
11
        global $kernel;
12
13
        if ('AppCache' == get_class($kernel)) {
14
            $kernel = $kernel->getKernel();
15
        }
16
17
        return $kernel->getContainer()->get('snc_redis.'.$kernel->getContainer()
18
                ->getParameter('sludio_helper.redis.translation'))
19
            ;
20
    }
21
22
    public function postUpdate($object)
23
    {
24
        $this->getRedis()->del($object->getClassName().':translations:'.$object->getId());
25
        $this->getRedis()->del($object->getClassName().':translations:'.$object->getId().':checked');
26
    }
27
28
    public function getTranslationFilter($queryBuilder, $alias, $field, $value)
29
    {
30
        if (!isset($value['value'])) {
31
            return;
32
        }
33
        $queryBuilder->leftJoin('Sludio:Translation', 't', 'WITH', 't.foreignKey = '.$alias.'.id');
34
        $queryBuilder->andWhere("t.field = '$field'");
35
        $queryBuilder->andWhere("t.objectClass = '".$objectClass = $this->getClass()."'");
0 ignored issues
show
Unused Code introduced by
The assignment to $objectClass is dead and can be removed.
Loading history...
36
        $queryBuilder->andWhere("t.content LIKE '%".$value['value']."%'");
37
        $queryBuilder->setFirstResult(0);
38
39
        return true;
40
    }
41
}
42