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

CustomerController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A customersLoginAction() 0 55 3
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
        $em = $this->getDoctrine()->getManager();
14
        $apiKeyHead= $request->headers->get('apikey');
0 ignored issues
show
Unused Code introduced by
$apiKeyHead is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
15
        $accessToken = $request->headers->get('token');
16
17
        if ($accessToken){
18
            $UserFacebook = $this->get('service_facebook_sdk')->setValue($accessToken)->getValue();
19
20
            $apiKey=uniqid('token_');
0 ignored issues
show
Unused Code introduced by
$apiKey is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
21
                
22
            $userFind = $em->getRepository('AppBundle:Customer')
23
                ->findUserByFacebookId($UserFacebook->getId());
24
            dump($userFind);
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...
25
            die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method customersLoginAction() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
26
            if($userFind){
0 ignored issues
show
Unused Code introduced by
if ($userFind) { $us...l); $em->flush(); } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
27
                $userRefreshApikey = $em->getRepository('AppBundle:Customer')
28
                    ->find($userFind[0]['id']);
29
                $userRefreshApikey->setApiKey($apiKey);
30
                $em->persist($userRefreshApikey);
31
                $em->flush($userRefreshApikey);
32
    
33
            }
34
            else {
35
                $userFindApiKey = $em->getRepository('AppBundle:Customer')
36
                    ->findUsernameByApiKey($apiKeyHead);
37
    
38
                $userRefreshAll= $em->getRepository('AppBundle:Customer')
39
                    ->find($userFindApiKey[0]['id']);
40
    
41
                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...
42
    
43
    
44
    
45
                $userRefreshAll->setEmail($UserFacebook->getEmail());
46
                $userRefreshAll->setFacebookID($UserFacebook->getId());
47
                $Key = rand(100000, 500000);
48
                $apiKey = (string)$Key;
49
                $ugserRefreshAll->setApiKey($apiKey);
50
                $em = $this->getDoctrine()->getManager();
51
                $em->persist($userRefreshAll);
52
                $em->flush();
53
    
54
             }
55
56
        }
57
        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...
58
            //add first, last name or refreshAll
59
60
        }
61
62
63
64
        return $this->render(':default:login.html.twig');
65
    }
66
67
    }
68