LocaleSwitcherBlockService   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 53
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A setDefaultSettings() 0 4 1
A configureSettings() 0 13 1
A execute() 0 7 1
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
use Twig\Environment;
23
24
/**
25
 * @author Nicolas Bastien <[email protected]>
26
 */
27
class LocaleSwitcherBlockService extends AbstractBlockService
28
{
29
    /**
30
     * @var bool
31
     */
32
    private $showCountryFlags;
33
34
    /**
35
     * NEXT_MAJOR: Remove `$templating` argument.
36
     *
37
     * @param Environment|string $templatingOrDeprecatedName
38
     */
39
    public function __construct(
40
        $templatingOrDeprecatedName = null,
41
        ?EngineInterface $templating = null,
42
        ?bool $showCountryFlags = false
43
    ) {
44
        parent::__construct($templatingOrDeprecatedName, $templating);
45
        $this->showCountryFlags = $showCountryFlags;
46
    }
47
48
    /**
49
     * NEXT_MAJOR: remove this method.
50
     *
51
     * @deprecated since 3.x, will be removed in 4.0
52
     */
53
    public function setDefaultSettings(OptionsResolverInterface $resolver): void
54
    {
55
        $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...
56
    }
57
58
    public function configureSettings(OptionsResolver $resolver): void
59
    {
60
        $resolver->setDefaults(
61
            [
62
                'admin' => null,
63
                'object' => null,
64
                'template' => '@SonataTranslation/Block/block_locale_switcher.html.twig',
65
                'locale_switcher_route' => null,
66
                'locale_switcher_route_parameters' => [],
67
                'locale_switcher_show_country_flags' => $this->showCountryFlags,
68
            ]
69
        );
70
    }
71
72
    public function execute(BlockContextInterface $blockContext, ?Response $response = null)
73
    {
74
        return $this->renderPrivateResponse($blockContext->getTemplate(), [
75
            'block_context' => $blockContext,
76
            'block' => $blockContext->getBlock(),
77
        ], $response);
78
    }
79
}
80