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

CustomerController::customersLoginAction()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 65
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 36
nc 3
nop 1
dl 0
loc 65
rs 9.3571
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
8
class CustomerController extends Controller
9
{
10
11
    public function customersLoginAction(Request $request)
12
    {
13
        $apiKeyHead= $request->headers->get('apikey');
14
        $accessToken = $request->headers->get('token');
15
16
        if ($accessToken){
17
18
19
20
        $UserFacebook = $this->get('service_facebook_sdk');
21
        $UserFacebook->setValue($accessToken);
22
23
        $UserFacebook = $UserFacebook->getValue();
24
        //dump($UserFacebook);
25
        echo $UserFacebook->getId();
26
27
        $Key=rand(100000,500000);
28
        $apiKey=(string) $Key;
29
30
        $em=$this->getDoctrine()->getManager();
31
        $userFind = $em->getRepository('AppBundle:Customer')
32
            ->findUserByFacebookId($UserFacebook->getId());
33
        if($userFind){
34
35
36
            $userRefreshApikey = $em->getRepository('AppBundle:Customer')
37
                ->find($userFind[0]['id']);
38
            $userRefreshApikey->setApiKey($apiKey);
39
            $em->persist($userRefreshApikey);
40
            $em->flush($userRefreshApikey);
41
42
        }
43
        else {
44
            $em=$this->getDoctrine()->getManager();
45
            $userFindApiKey = $em->getRepository('AppBundle:Customer')
46
                ->findUsernameByApiKey($apiKeyHead);
47
48
            $userRefreshAll= $em->getRepository('AppBundle:Customer')
49
                ->find($userFindApiKey[0]['id']);
50
51
            dump($userFindApiKey);
0 ignored issues
show
Bug introduced by
The call to dump() misses a required argument $valid.

This check looks for function calls that miss required arguments.

Loading history...
52
53
54
55
            $userRefreshAll->setEmail($UserFacebook->getEmail());
56
            $userRefreshAll->setFacebookID($UserFacebook->getId());
57
            $Key = rand(100000, 500000);
58
            $apiKey = (string)$Key;
59
            $userRefreshAll->setApiKey($apiKey);
60
            $em = $this->getDoctrine()->getManager();
61
            $em->persist($userRefreshAll);
62
            $em->flush();
63
64
         }
65
66
        }
67
        else{
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
68
            //add first, last name or refreshAll
69
70
        }
71
72
73
74
        return $this->render(':default:login.html.twig');
75
    }
76
77
    }
78