Completed
Pull Request — master (#137)
by
unknown
12:25
created

CustomerController::customersLoginAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 54
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 25
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 54
rs 9.6716

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)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
12
    {
13
        $em = $this->getDoctrine()->getManager();
14
        //$apiKeyHead= $request->headers->get('apikey');
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
15
        //$accessToken = $request->headers->get('token');
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
16
17
        /*if ($accessToken){
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
18
            $UserFacebook = $this->get('service_facebook_sdk')->setValue($accessToken)->getValue();
19
20
            $apiKey=uniqid('token_');
21
          */
22
            $userFind = $em->getRepository('AppBundle:Customer')
23
                ->findUserByFacebook('1607601072588116');
24
25
            if($userFind){
26
                $userRefreshApikey = $em->getRepository('AppBundle:Customer')
27
                    ->find($userFind[0]['id']);
28
                $userRefreshApikey->setApiKey($apiKey);
0 ignored issues
show
Bug introduced by
The variable $apiKey seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
29
                $em->persist($userRefreshApikey);
30
                $em->flush($userRefreshApikey);
31
    
32
            }
33
            else {
34
                $userFindApiKey = $em->getRepository('AppBundle:Customer')
35
                    ->findUsernameByApiKey($apiKeyHead);
0 ignored issues
show
Bug introduced by
The variable $apiKeyHead does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
36
    
37
                $userRefreshAll= $em->getRepository('AppBundle:Customer')
38
                    ->find($userFindApiKey[0]['id']);
39
    
40
                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...
41
    
42
    
43
    
44
                $userRefreshAll->setEmail($UserFacebook->getEmail());
0 ignored issues
show
Bug introduced by
The variable $UserFacebook does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
45
                $userRefreshAll->setFacebookID($UserFacebook->getId());
46
                $Key = rand(100000, 500000);
47
                $apiKey = (string)$Key;
48
                $ugserRefreshAll->setApiKey($apiKey);
0 ignored issues
show
Bug introduced by
The variable $ugserRefreshAll does not exist. Did you mean $userRefreshAll?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
49
                $em = $this->getDoctrine()->getManager();
50
                $em->persist($userRefreshAll);
51
                $em->flush();
52
    
53
             }
54
55
        //}
56
       // else{
57
            //add first, last name or refreshAll
58
59
       // }
60
61
62
63
        return $this->render(':default:login.html.twig');
64
    }
65
66
    }
67