Completed
Push — master ( fd0af8...9bd62a )
by Nicolas
04:23
created

TranslatableAdminExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4286
cc 1
eloc 3
nc 1
nop 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
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)
30
    {
31
        parent::__construct($translatableChecker);
32
        $this->translatableListener = $translatableListener;
33
    }
34
35
    /**
36
     * @param AdminInterface $admin
0 ignored issues
show
Bug introduced by
There is no parameter named $admin. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
37
     *
38
     * @return TranslatableListener
39
     */
40
    protected function getTranslatableListener()
41
    {
42
        return $this->translatableListener;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function alterObject(AdminInterface $admin, $object)
49
    {
50
        if ($this->getTranslatableChecker()->isTranslatable($object)) {
51
            $this->getTranslatableListener()->setTranslatableLocale($this->getTranslatableLocale($admin));
52
            $this->getTranslatableListener()->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...
53
54
            $this->getContainer($admin)->get('doctrine')->getManager()->refresh($object);
55
            $object->setLocale($this->getTranslatableLocale($admin));
56
        }
57
    }
58
}
59