Completed
Pull Request — master (#137)
by
unknown
15:28
created

CustomerController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 59
rs 10
c 2
b 0
f 1
wmc 6
lcom 1
cbo 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B customerLoginAction() 0 56 6
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Symfony\Component\HttpFoundation\Request;
7
use AppBundle\Entity\Customer;
8
use Symfony\Component\HttpFoundation\JsonResponse;
9
10
class CustomerController extends Controller
11
{
12
    public function customerLoginAction(Request $request)
13
    {
14
        $em = $this->getDoctrine()->getManager();
15
        $apiKeyHead = $request->headers->get('API-Key-Token');
16
        $facebookToken = $request->request->get('social_token');
17
        $apiKey = uniqid('token_');
18
        $firstNameHead = $request->request->get('first_name');
19
        $lastNameHead = $request->request->get('last_name');
20
        $emailHead = $request->request->get('email');
21
22
        $ValidatorResult = $this->get('service_customers_login_validator')
23
            ->resultOptions($this->getUser(), $apiKeyHead, $facebookToken, $firstNameHead, $lastNameHead, $emailHead);
24
25
        switch ($ValidatorResult) {
26
            case 'social token true':
27
                $UserFacebook = $this->get('service_facebook_sdk')
28
                    ->getUserFacebook($facebookToken);
29
                $userFindApiKey = $em->getRepository('AppBundle:Customer')
30
                    ->findUsernameByApiKey($apiKeyHead);
31
                $userFindApiKey->setEmail($UserFacebook->getEmail());
32
                $userFindApiKey->setFacebookID($UserFacebook->getId());
33
                $userFindApiKey->setFirstname($UserFacebook->getFirstName());
34
                $userFindApiKey->setLastname($UserFacebook->getLastName());
35
                $userFindApiKey->setApiKey($apiKey);
36
                $em->flush();
37
38
                return new JsonResponse('costumer');
39
40
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
41
            case 'Invalid email/first_name/last_name':
42
                return new JsonResponse('401');
43
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
44
            case 'customer input of the form':
45
                $userFindApiKey = $em->getRepository('AppBundle:Customer')
46
                    ->findUsernameByApiKey($apiKeyHead);
47
                $userFindApiKey->setFirstname($firstNameHead);
48
                $userFindApiKey->setLastname($lastNameHead);
49
                $userFindApiKey->setEmail($emailHead);
50
                $em->flush();
51
52
                return new JsonResponse('customer');
53
             break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
54
            case 'not valid apiKey':
55
                return new JsonResponse('403');
56
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
57
            case 'new costomer':
58
                $costumer = new Customer();
59
                $costumer->setUsername('customer');
60
                $costumer->setApiKey($apiKey);
61
                $em->persist($costumer);
62
                $em->flush();
63
64
                return new JsonResponse('customer');
65
             break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
66
        }
67
    }
68
}
69