Completed
Push — master ( a0c302...199c16 )
by Valentyn
03:15
created

UserCheckController::isUserExistsByUsername()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
crap 2
1
<?php
2
3
namespace App\Users\Controller;
4
5
use App\Controller\BaseController;
6
use App\Users\Repository\UserRepository;
7
use Symfony\Component\HttpFoundation\JsonResponse;
8
use Symfony\Component\Routing\Annotation\Route;
9
10
class UserCheckController extends BaseController
11
{
12
    /**
13
     * Check is user exists by username
14
     *
15
     * @Route("/api/users/username/{username}", methods={"GET"})
16
     * @param string $username
17
     * @param UserRepository $repository
18
     * @return JsonResponse
19
     */
20 2
    public function isUserExistsByUsername(string $username, UserRepository $repository)
21
    {
22 2
        $isUserExists = $repository->isUserExists([
23 2
            'username' => $username,
24
        ]);
25
26 2
        if ($isUserExists === true) {
27 1
            return new JsonResponse();
28
        }
29
30 1
        return new JsonResponse([], 404);
31
    }
32
33
    /**
34
     * Check is user exists by email
35
     *
36
     * @Route("/api/users/email/{email}", methods={"GET"})
37
     * @param string $email
38
     * @param UserRepository $repository
39
     * @return JsonResponse
40
     */
41 2
    public function isUserExistsByEmail(string $email, UserRepository $repository)
42
    {
43 2
        $isUserExists = $repository->isUserExists([
44 2
            'email' => $email,
45
        ]);
46
47 2
        if ($isUserExists === true) {
48 1
            return new JsonResponse();
49
        }
50
51 1
        return new JsonResponse([], 404);
52
    }
53
}