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

UserCheckController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
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 44
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
     * @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
}