| Conditions | 6 |
| Paths | 6 |
| Total Lines | 58 |
| Code Lines | 50 |
| 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 |
||
| 16 | public function loginAction(Request $request) |
||
| 17 | { |
||
| 18 | $em = $this->getDoctrine()->getManager(); |
||
| 19 | $apiKeyFromRequest = $request->headers->get('API-Key-Token'); |
||
| 20 | $socialNetwork = $request->request->get('social_network'); |
||
| 21 | $socialToken = $request->request->get('social_token'); |
||
| 22 | $apiKey = uniqid('token_'); |
||
| 23 | $firstName = $request->request->get('first_name'); |
||
| 24 | $lastName = $request->request->get('last_name'); |
||
| 25 | $email = $request->request->get('email'); |
||
| 26 | |||
| 27 | $validatorResult = $this->get('service_customers_login_validator') |
||
| 28 | ->resultOptions($this->getUser(), $apiKeyFromRequest, $socialNetwork, $firstName, $lastName, $email); |
||
| 29 | |||
| 30 | switch ($validatorResult) { |
||
| 31 | case 'social network true': |
||
| 32 | $UserFacebook = $this->get('service_facebook_sdk') |
||
| 33 | ->getUserFacebook($socialToken); |
||
| 34 | $userFindApiKey = $em->getRepository('AppBundle:Customer') |
||
|
|
|||
| 35 | ->findOneByApiKey($apiKeyFromRequest); |
||
| 36 | $userFindApiKey->setEmail($UserFacebook->getEmail()); |
||
| 37 | $userFindApiKey->setFacebookId($UserFacebook->getId()); |
||
| 38 | $userFindApiKey->setFirstName($UserFacebook->getFirstName()); |
||
| 39 | $userFindApiKey->setLastName($UserFacebook->getLastName()); |
||
| 40 | $userFindApiKey->setApiKey($apiKey); |
||
| 41 | $em->flush(); |
||
| 42 | |||
| 43 | return new JsonResponse('customer'); |
||
| 44 | break; |
||
| 45 | case 'Invalid email/first_name/last_name': |
||
| 46 | return new JsonResponse('401'); |
||
| 47 | break; |
||
| 48 | case 'customer input of the form': |
||
| 49 | $userFindApiKey = $em->getRepository('AppBundle:Customer') |
||
| 50 | ->findOneByApiKey($apiKeyFromRequest); |
||
| 51 | $userFindApiKey->setFirstName($firstName); |
||
| 52 | $userFindApiKey->setLastName($lastName); |
||
| 53 | $userFindApiKey->setEmail($email); |
||
| 54 | $em->flush(); |
||
| 55 | |||
| 56 | return new JsonResponse('customer'); |
||
| 57 | break; |
||
| 58 | case 'not valid apiKey': |
||
| 59 | return new JsonResponse('403'); |
||
| 60 | break; |
||
| 61 | case 'new customer': |
||
| 62 | $customer = new Customer(); |
||
| 63 | $customer->setUsername('customer'); |
||
| 64 | $customer->setApiKey($apiKey); |
||
| 65 | $em->persist($customer); |
||
| 66 | $em->flush(); |
||
| 67 | |||
| 68 | return new JsonResponse('customer'); |
||
| 69 | break; |
||
| 70 | default: |
||
| 71 | return new JsonResponse('default'); |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.