Passed
Push — v2 ( 9b853e...868892 )
by Daniel
04:58
created

PasswordRequestAction::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 9
ccs 0
cts 6
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Component Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentBundle\Action\User;
15
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\HttpFoundation\Response;
18
use Symfony\Component\Routing\Annotation\Route;
19
20
/**
21
 * @author Daniel West <[email protected]>
22
 */
23
class PasswordRequestAction extends AbstractPasswordAction
24
{
25
    /**
26
     * @Route("/request/{username}", name="password_reset_request", methods={"get"})
27
     */
28
    public function __invoke(Request $request, string $username): Response
29
    {
30
        $user = $this->userRepository->findOneBy(['email' => $username]);
31
        if (!$user) {
32
            return $this->getResponse($request, null, Response::HTTP_NOT_FOUND);
33
        }
34
        $this->passwordManager->requestResetEmail($user);
35
36
        return $this->getResponse($request);
37
    }
38
}
39