SecurityController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 10
rs 10
c 1
b 0
f 0
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\AdminSecurityBundle\Controller;
13
14
use FSi\Bundle\AdminBundle\Message\FlashMessages;
15
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
16
use Symfony\Component\HttpFoundation\Response;
17
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
18
19
class SecurityController
20
{
21
    /**
22
     * @var EngineInterface
23
     */
24
    private $templating;
25
26
    /**
27
     * @var AuthenticationUtils
28
     */
29
    private $authenticationUtils;
30
31
    /**
32
     * @var FlashMessages
33
     */
34
    private $flashMessages;
35
36
    /**
37
     * @var string
38
     */
39
    private $loginActionTemplate;
40
41
    public function __construct(
42
        EngineInterface $templating,
43
        AuthenticationUtils $authenticationUtils,
44
        FlashMessages $flashMessages,
45
        string $loginActionTemplate
46
    ) {
47
        $this->templating = $templating;
48
        $this->authenticationUtils = $authenticationUtils;
49
        $this->flashMessages = $flashMessages;
50
        $this->loginActionTemplate = $loginActionTemplate;
51
    }
52
53
    public function loginAction(): Response
54
    {
55
        $error = $this->authenticationUtils->getLastAuthenticationError();
56
        if ($error) {
57
            $this->flashMessages->error(
58
                $error->getMessageKey(),
59
                $error->getMessageData(),
60
                'security'
61
            );
62
        }
63
64
        return $this->templating->renderResponse(
65
            $this->loginActionTemplate,
66
            ['last_username' => $this->authenticationUtils->getLastUsername()]
67
        );
68
    }
69
}
70