UserCheckController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 48
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isUserExistsByUsername() 0 12 2
A isUserExistsByEmail() 0 12 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
     *
17
     * @param string         $username
18
     * @param UserRepository $repository
19
     *
20
     * @return JsonResponse
21
     */
22 2
    public function isUserExistsByUsername(string $username, UserRepository $repository)
23
    {
24 2
        $isUserExists = $repository->isUserExists([
25 2
            'username' => $username,
26
        ]);
27
28 2
        if ($isUserExists === true) {
29 1
            return new JsonResponse();
30
        }
31
32 1
        return new JsonResponse([], 404);
33
    }
34
35
    /**
36
     * Check is user exists by email.
37
     *
38
     * @Route("/api/users/email/{email}", methods={"GET"})
39
     *
40
     * @param string         $email
41
     * @param UserRepository $repository
42
     *
43
     * @return JsonResponse
44
     */
45 2
    public function isUserExistsByEmail(string $email, UserRepository $repository)
46
    {
47 2
        $isUserExists = $repository->isUserExists([
48 2
            'email' => $email,
49
        ]);
50
51 2
        if ($isUserExists === true) {
52 1
            return new JsonResponse();
53
        }
54
55 1
        return new JsonResponse([], 404);
56
    }
57
}
58