| Conditions | 3 |
| Paths | 2 |
| Total Lines | 55 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 11 | public function customersLoginAction(Request $request) |
||
| 12 | { |
||
| 13 | $em = $this->getDoctrine()->getManager(); |
||
| 14 | $apiKeyHead= $request->headers->get('apikey'); |
||
|
|
|||
| 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_'); |
||
| 21 | |||
| 22 | $userFind = $em->getRepository('AppBundle:Customer') |
||
| 23 | ->findUserByFacebookId($UserFacebook->getId()); |
||
| 24 | dump($userFind); |
||
| 25 | die(); |
||
| 26 | if($userFind){ |
||
| 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); |
||
| 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{ |
||
| 58 | //add first, last name or refreshAll |
||
| 59 | |||
| 60 | } |
||
| 61 | |||
| 62 | |||
| 63 | |||
| 64 | return $this->render(':default:login.html.twig'); |
||
| 65 | } |
||
| 66 | |||
| 68 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.