AdminController::localeAction()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 2
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace FSi\Bundle\AdminBundle\Controller;
13
14
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
15
use Symfony\Component\HttpFoundation\RedirectResponse;
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\HttpFoundation\Response;
18
use Symfony\Component\Routing\RouterInterface;
19
20
class AdminController
21
{
22
    /**
23
     * @var EngineInterface
24
     */
25
    private $templating;
26
27
    /**
28
     * @var RouterInterface
29
     */
30
    private $router;
31
32
    /**
33
     * @var string
34
     */
35
    private $indexActionTemplate;
36
37
    public function __construct(EngineInterface $templating, RouterInterface $router, string $indexActionTemplate)
38
    {
39
        $this->templating = $templating;
40
        $this->router = $router;
41
        $this->indexActionTemplate = $indexActionTemplate;
42
    }
43
44
    public function indexAction(): Response
45
    {
46
        return $this->templating->renderResponse($this->indexActionTemplate);
47
    }
48
49
    public function localeAction(string $_locale, Request $request): RedirectResponse
50
    {
51
        $request->getSession()->set('admin_locale', $_locale);
52
53
        return new RedirectResponse(
54
            $request->query->has('redirect_uri')
55
                ? $request->query->get('redirect_uri')
56
                : $this->router->generate('fsi_admin')
57
        );
58
    }
59
}
60