Completed
Pull Request — master (#137)
by
unknown
11:18
created

CustomerController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B loginAction() 0 58 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
    /**
13
     * @param Request $request
14
     * @return bool|JsonResponse
15
     */
16
    public function loginAction(Request $request)
17
    {
18
        $em = $this->getDoctrine()->getManager();
19
        $apiKeyFromRequest = $request->headers->get('API-Key-Token');
20
        $socialNetwork = $request->request->get('social_network');
21
        $socialToken = $request->request->get('social_token');
22
        $apiKey = uniqid('token_');
23
        $firstName = $request->request->get('first_name');
24
        $lastName = $request->request->get('last_name');
25
        $email = $request->request->get('email');
26
27
        $validatorResult = $this->get('service_customers_login_validator')
28
            ->resultOptions($this->getUser(), $apiKeyFromRequest, $socialNetwork, $firstName, $lastName, $email);
29
30
        switch ($validatorResult) {
31
            case 'social network true':
32
                $UserFacebook = $this->get('service_facebook_sdk')
33
                    ->getUserFacebook($socialToken);
34
                $userFindApiKey = $em->getRepository('AppBundle:Customer')
0 ignored issues
show
Bug introduced by
The method findOneByApiKey() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findOneBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
35
                    ->findOneByApiKey($apiKeyFromRequest);
36
                $userFindApiKey->setEmail($UserFacebook->getEmail());
37
                $userFindApiKey->setFacebookId($UserFacebook->getId());
38
                $userFindApiKey->setFirstName($UserFacebook->getFirstName());
39
                $userFindApiKey->setLastName($UserFacebook->getLastName());
40
                $userFindApiKey->setApiKey($apiKey);
41
                $em->flush();
42
43
                return new JsonResponse('customer');
44
                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...
45
            case 'Invalid email/first_name/last_name':
46
                return new JsonResponse('401');
47
                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...
48
            case 'customer input of the form':
49
                $userFindApiKey = $em->getRepository('AppBundle:Customer')
0 ignored issues
show
Bug introduced by
The method findOneByApiKey() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findOneBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
50
                    ->findOneByApiKey($apiKeyFromRequest);
51
                $userFindApiKey->setFirstName($firstName);
52
                $userFindApiKey->setLastName($lastName);
53
                $userFindApiKey->setEmail($email);
54
                $em->flush();
55
56
                return new JsonResponse('customer');
57
                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...
58
            case 'not valid apiKey':
59
                return new JsonResponse('403');
60
                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...
61
            case 'new customer':
62
                $customer = new Customer();
63
                $customer->setUsername('customer');
64
                $customer->setApiKey($apiKey);
65
                $em->persist($customer);
66
                $em->flush();
67
68
                return new JsonResponse('customer');
69
                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...
70
            default:
71
                return new JsonResponse('default');
72
        }
73
    }
74
}
75