| Conditions | 7 |
| Paths | 11 |
| Total Lines | 65 |
| Code Lines | 36 |
| 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 |
||
| 32 | public function indexAction(Request $request) |
||
| 33 | { |
||
| 34 | $this->denyAccessUnlessGranted('ROLE_USER'); |
||
| 35 | $user = $this->getUser(); |
||
| 36 | |||
| 37 | $fieldNoteService = $this->get(FieldNoteService::class); |
||
| 38 | $dataProvider = $this->get(UploadFieldNotesDataProvider::class); |
||
| 39 | |||
| 40 | $repository = $this->getDoctrine()->getRepository('AppBundle:FieldNote'); |
||
| 41 | $fieldNotes = $repository->findBy([ |
||
| 42 | 'user' => $user->getId() |
||
| 43 | ], [ |
||
| 44 | 'date' => 'ASC', |
||
| 45 | 'id' => 'ASC' |
||
| 46 | ]); |
||
| 47 | |||
| 48 | $form = $this->createForm(UploadFieldNotesType::class, $dataProvider->getData($user->getId())); |
||
| 49 | $form->handleRequest($request); |
||
| 50 | |||
| 51 | if ($form->isSubmitted() && $form->isValid()) { |
||
| 52 | /** |
||
| 53 | * @var UploadedFile $file |
||
| 54 | */ |
||
| 55 | $file = $form->getData()[UploadFieldNotesType::FIELD_FILE]; |
||
| 56 | |||
| 57 | try { |
||
| 58 | $ignoreDate = null; |
||
| 59 | |||
| 60 | if (!empty($form->getData()[UploadFieldNotesType::FIELD_IGNORE])) { |
||
| 61 | $ignoreDate = DateUtil::dateTimeFromMySqlFormat( |
||
| 62 | $form->getData()[UploadFieldNotesType::FIELD_IGNORE_DATE] |
||
| 63 | ); |
||
| 64 | } |
||
| 65 | |||
| 66 | $fieldNoteService->importFromFile($file->getRealPath(), $user->getId(), $ignoreDate); |
||
| 67 | } catch (\Exception $e) { |
||
| 68 | $this->addErrorMessage($e->getMessage()); |
||
| 69 | |||
| 70 | return $this->redirectToRoute('field-notes'); |
||
| 71 | } |
||
| 72 | |||
| 73 | if ($fieldNoteService->hasErrors()) { |
||
| 74 | foreach ($fieldNoteService->getErrors() as $error) { |
||
| 75 | $this->addErrorMessage($error); |
||
| 76 | } |
||
| 77 | |||
| 78 | return $this->redirectToRoute('field-notes'); |
||
| 79 | } |
||
| 80 | |||
| 81 | $this->addSuccessMessage( |
||
| 82 | $this->get('translator')->trans('field_notes.upload.success') |
||
| 83 | ); |
||
| 84 | |||
| 85 | return $this->redirectToRoute('field-notes'); |
||
| 86 | } |
||
| 87 | |||
| 88 | $this->setMenu(MNU_MYPROFILE_FIELD_NOTES); |
||
| 89 | $this->setTitle($this->get('translator')->trans('field_notes.field_notes')); |
||
| 90 | |||
| 91 | return $this->render('field-notes/index.html.twig', [ |
||
| 92 | 'user' => $user, |
||
| 93 | 'form' => $form->createView(), |
||
| 94 | 'fieldNotes' => $fieldNotes, |
||
| 95 | ]); |
||
| 96 | } |
||
| 97 | |||
| 176 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.