Completed
Push — master ( 9a443c...3b7699 )
by Grégoire
12s
created

LocaleSwitcherBlockService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
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(
34
        ?string $name = null,
35
        EngineInterface $templating = null,
36
        ?bool $showCountryFlags = false
37
    ) {
38
        parent::__construct($name, $templating);
39
        $this->showCountryFlags = $showCountryFlags;
40
    }
41
42
    /**
43
     * NEXT_MAJOR: remove this method.
44
     *
45
     * @deprecated since 3.x, will be removed in 4.0
46
     */
47
    public function setDefaultSettings(OptionsResolverInterface $resolver): void
48
    {
49
        $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...
50
    }
51
52
    public function configureSettings(OptionsResolver $resolver): void
53
    {
54
        $resolver->setDefaults(
55
            [
56
                'admin' => null,
57
                'object' => null,
58
                'template' => '@SonataTranslation/Block/block_locale_switcher.html.twig',
59
                'locale_switcher_route' => null,
60
                'locale_switcher_route_parameters' => [],
61
                'locale_switcher_show_country_flags' => $this->showCountryFlags,
62
            ]
63
        );
64
    }
65
66
    public function execute(BlockContextInterface $blockContext, Response $response = null)
67
    {
68
        return $this->renderPrivateResponse($blockContext->getTemplate(), [
69
            'block_context' => $blockContext,
70
            'block' => $blockContext->getBlock(),
71
        ], $response);
72
    }
73
}
74