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

CustomerController::customersLoginAction()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 26
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 3
eloc 20
c 2
b 0
f 1
nc 3
nop 1
dl 0
loc 26
rs 8.8571
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
    public function customersLoginAction(Request $request)
11
    {
12
        $em = $this->getDoctrine()->getManager();
13
        $apiKeyHead = $request->headers->get('API-Key-Token');
14
        $facebookToken = $request->headers->get('social_token');
15
        $apiKey = uniqid('token_');
16
        if ($facebookToken) {
17
            $UserFacebook = $this->get('service_facebook_sdk')->setValue($facebookToken)->getValue();
18
            $userFind = $em->getRepository('AppBundle:Customer')
19
              ->findUserByFacebookId($UserFacebook - getId());
20
            if ($userFind) {
21
                $userFind->setApiKey($apiKey);
22
                $em->flush();
23
            } else {
24
                $userFindApiKey = $em->getRepository('AppBundle:Customer')
25
                   ->findUsernameByApiKey($apiKeyHead);
26
                $userFindApiKey->setEmail($UserFacebook->getEmail());
0 ignored issues
show
Bug introduced by
The method getEmail cannot be called on $UserFacebook (of type integer|double).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
27
                $userFindApiKey->setFacebookID($UserFacebook->getId());
0 ignored issues
show
Bug introduced by
The method getId cannot be called on $UserFacebook (of type integer|double).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
28
                $em->flush();
29
            }
30
        } 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...
31
            //add first, last name or refreshAll
32
        }
33
34
        return $this->render(':default:login.html.twig');
35
    }
36
}
37