Completed
Pull Request — master (#46)
by
unknown
16:04 queued 02:09
created

TranslatableAdminExtension   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 6
c 4
b 1
f 2
lcom 1
cbo 4
dl 0
loc 53
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTranslatableListener() 0 10 2
A getManagerFromAdmin() 0 10 2
A alterObject() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the Sonata package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\TranslationBundle\Admin\Extension\Gedmo;
13
14
use Gedmo\Translatable\TranslatableListener;
15
use Sonata\AdminBundle\Admin\AdminInterface;
16
use Sonata\TranslationBundle\Admin\Extension\AbstractTranslatableAdminExtension;
17
18
/**
19
 * @author Nicolas Bastien <[email protected]>
20
 */
21
class TranslatableAdminExtension extends AbstractTranslatableAdminExtension
22
{
23
    /**
24
     * @var TranslatableListener
25
     */
26
    protected $translatableListener;
27
28
    /**
29
     * @param AdminInterface $admin
30
     *
31
     * @return TranslatableListener
32
     */
33
    protected function getTranslatableListener(AdminInterface $admin)
34
    {
35
        if ($this->translatableListener == null) {
36
            $this->translatableListener = $this->getContainer($admin)->get(
37
                'stof_doctrine_extensions.listener.translatable'
38
            );
39
        }
40
41
        return $this->translatableListener;
42
    }
43
    
44
    /**
45
     * @param AdminInterface $admin
46
     * 
47
     * @return \Doctrine\Common\Persistence\ObjectManager
48
     */
49
    protected function getManagerFromAdmin(AdminInterface $admin)
50
    {
51
        $service = $this->getContainer($admin)->get($admin->getManagerType());
52
        
53
        if (!$service) {
54
            $service = $this->getContainer($admin)->get('doctrine');
55
        }
56
        
57
        return $service->getManager();
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function alterObject(AdminInterface $admin, $object)
64
    {
65
        if ($this->getTranslatableChecker()->isTranslatable($object)) {
66
            $this->getTranslatableListener($admin)->setTranslatableLocale($this->getTranslatableLocale($admin));
67
            $this->getTranslatableListener($admin)->setTranslationFallback('');
0 ignored issues
show
Documentation introduced by
'' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
68
69
            $this->getManagerFromAdmin($admin)->refresh($object);
70
            $object->setLocale($this->getTranslatableLocale($admin));
71
        }
72
    }
73
}
74