Completed
Pull Request — 2.x (#281)
by
unknown
02:07
created

LocaleSwitcherBlockService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\TranslationBundle\Block;
15
16
use Sonata\BlockBundle\Block\BlockContextInterface;
17
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
18
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
19
use Symfony\Component\HttpFoundation\Response;
20
use Symfony\Component\OptionsResolver\OptionsResolver;
21
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
22
23
/**
24
 * @author Nicolas Bastien <[email protected]>
25
 */
26
class LocaleSwitcherBlockService extends AbstractBlockService
27
{
28
    /**
29
     * @var bool
30
     */
31
    private $showCountryFlags;
32
33
    public function __construct(?string $name = null, EngineInterface $templating = null, ?bool $showCountryFlags = false)
34
    {
35
        parent::__construct($name, $templating);
36
        $this->showCountryFlags = $showCountryFlags;
37
    }
38
39
    /**
40
     * NEXT_MAJOR: remove this method.
41
     *
42
     * @deprecated since 3.x, will be removed in 4.0
43
     */
44
    public function setDefaultSettings(OptionsResolverInterface $resolver)
45
    {
46
        $this->configureSettings($resolver);
0 ignored issues
show
Documentation introduced by
$resolver is of type object<Symfony\Component...tionsResolverInterface>, but the function expects a object<Symfony\Component...solver\OptionsResolver>.

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...
47
    }
48
49
    public function configureSettings(OptionsResolver $resolver)
50
    {
51
        $resolver->setDefaults(
52
            [
53
                'admin' => null,
54
                'object' => null,
55
                'template' => '@SonataTranslation/Block/block_locale_switcher.html.twig',
56
                'locale_switcher_route' => null,
57
                'locale_switcher_route_parameters' => [],
58
                'locale_switcher_show_country_flags' => $this->showCountryFlags,
59
            ]
60
        );
61
    }
62
63
    public function execute(BlockContextInterface $blockContext, Response $response = null)
64
    {
65
        return $this->renderPrivateResponse($blockContext->getTemplate(), [
66
            'block_context' => $blockContext,
67
            'block' => $blockContext->getBlock(),
68
        ], $response);
69
    }
70
}
71