Completed
Push — master ( d17154...1fc820 )
by Sullivan
11:02 queued 08:59
created

TranslatableAdminExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getTranslatableListener() 0 10 2
A alterObject() 0 11 2
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project 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
use Sonata\TranslationBundle\Checker\TranslatableChecker;
18
19
/**
20
 * @author Nicolas Bastien <[email protected]>
21
 */
22
class TranslatableAdminExtension extends AbstractTranslatableAdminExtension
23
{
24
    /**
25
     * @var TranslatableListener
26
     */
27
    protected $translatableListener;
28
29
    public function __construct(TranslatableChecker $translatableChecker, TranslatableListener $translatableListener = null)
30
    {
31
        parent::__construct($translatableChecker);
32
        $this->translatableListener = $translatableListener;
33
    }
34
35
    /**
36
     * @param AdminInterface $admin Deprecated, set TranslatableListener in the constructor instead.
37
     *
38
     * @return TranslatableListener
39
     */
40
    protected function getTranslatableListener(AdminInterface $admin)
41
    {
42
        if (null === $this->translatableListener) {
43
            $this->translatableListener = $this->getContainer($admin)->get(
44
                'stof_doctrine_extensions.listener.translatable'
45
            );
46
        }
47
48
        return $this->translatableListener;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function alterObject(AdminInterface $admin, $object)
55
    {
56
        if ($this->getTranslatableChecker()->isTranslatable($object)) {
57
            $translatableListener = $this->getTranslatableListener($admin);
58
            $translatableListener->setTranslatableLocale($this->getTranslatableLocale($admin));
59
            $translatableListener->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...
60
61
            $this->getContainer($admin)->get('doctrine')->getManager()->refresh($object);
62
            $object->setLocale($this->getTranslatableLocale($admin));
63
        }
64
    }
65
}
66