| Conditions | 6 |
| Paths | 6 |
| Total Lines | 56 |
| Code Lines | 47 |
| 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 |
||
| 12 | public function customerLoginAction(Request $request) |
||
| 13 | { |
||
| 14 | $em = $this->getDoctrine()->getManager(); |
||
| 15 | $apiKeyHead = $request->headers->get('API-Key-Token'); |
||
| 16 | $facebookToken = $request->request->get('social_token'); |
||
| 17 | $apiKey = uniqid('token_'); |
||
| 18 | $firstNameHead = $request->request->get('first_name'); |
||
| 19 | $lastNameHead = $request->request->get('last_name'); |
||
| 20 | $emailHead = $request->request->get('email'); |
||
| 21 | |||
| 22 | $ValidatorResult = $this->get('service_customers_login_validator') |
||
| 23 | ->resultOptions($this->getUser(), $apiKeyHead, $facebookToken, $firstNameHead, $lastNameHead, $emailHead); |
||
| 24 | |||
| 25 | switch ($ValidatorResult) { |
||
| 26 | case 'social token true': |
||
| 27 | $UserFacebook = $this->get('service_facebook_sdk') |
||
| 28 | ->getUserFacebook($facebookToken); |
||
| 29 | $userFindApiKey = $em->getRepository('AppBundle:Customer') |
||
| 30 | ->findUsernameByApiKey($apiKeyHead); |
||
| 31 | $userFindApiKey->setEmail($UserFacebook->getEmail()); |
||
| 32 | $userFindApiKey->setFacebookID($UserFacebook->getId()); |
||
| 33 | $userFindApiKey->setFirstname($UserFacebook->getFirstName()); |
||
| 34 | $userFindApiKey->setLastname($UserFacebook->getLastName()); |
||
| 35 | $userFindApiKey->setApiKey($apiKey); |
||
| 36 | $em->flush(); |
||
| 37 | |||
| 38 | return new JsonResponse('costumer'); |
||
| 39 | |||
| 40 | break; |
||
|
|
|||
| 41 | case 'Invalid email/first_name/last_name': |
||
| 42 | return new JsonResponse('401'); |
||
| 43 | break; |
||
| 44 | case 'customer input of the form': |
||
| 45 | $userFindApiKey = $em->getRepository('AppBundle:Customer') |
||
| 46 | ->findUsernameByApiKey($apiKeyHead); |
||
| 47 | $userFindApiKey->setFirstname($firstNameHead); |
||
| 48 | $userFindApiKey->setLastname($lastNameHead); |
||
| 49 | $userFindApiKey->setEmail($emailHead); |
||
| 50 | $em->flush(); |
||
| 51 | |||
| 52 | return new JsonResponse('customer'); |
||
| 53 | break; |
||
| 54 | case 'not valid apiKey': |
||
| 55 | return new JsonResponse('403'); |
||
| 56 | break; |
||
| 57 | case 'new costomer': |
||
| 58 | $costumer = new Customer(); |
||
| 59 | $costumer->setUsername('customer'); |
||
| 60 | $costumer->setApiKey($apiKey); |
||
| 61 | $em->persist($costumer); |
||
| 62 | $em->flush(); |
||
| 63 | |||
| 64 | return new JsonResponse('customer'); |
||
| 65 | break; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | } |
||
| 69 |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.