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

CustomerController::customerLoginAction()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 56
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 47
nc 6
nop 1
dl 0
loc 56
rs 8.7592
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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