Conditions | 11 |
Paths | 60 |
Total Lines | 65 |
Code Lines | 42 |
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 |
||
41 | public function edit(Request $request, string $guid = null): Response |
||
42 | { |
||
43 | $em = $this->getDoctrine()->getManager(); |
||
44 | $disabled_form = strpos($request->get("_route"), "_show") ? true : false; |
||
45 | |||
46 | if ($guid === null) { |
||
47 | $account = new Account(); |
||
48 | $old_password = null; |
||
49 | $user = null; |
||
50 | } else { |
||
51 | $user = $em->getRepository(User::class)->findOneBy(["guid" => $guid]); |
||
52 | $account = $em->getRepository(Account::class)->findOneBy(["user" => $user->getId()]); |
||
53 | $old_password = $account->getPassword(); |
||
54 | } |
||
55 | |||
56 | $form = $this->createForm("PiouPiou\RibsAdminBundle\Form\Account", $account, ["disabled" => $disabled_form]); |
||
57 | |||
58 | $form->handleRequest($request); |
||
59 | |||
60 | if ($form->isSubmitted() && $form->isValid()) { |
||
61 | /** |
||
62 | * @var Account |
||
63 | */ |
||
64 | $data = $form->getData(); |
||
65 | |||
66 | $account_exist = $em->getRepository(Account::class)->findOneBy(["username" => $data->getUsername()]); |
||
67 | |||
68 | if ($account_exist && $account_exist === $account) { |
||
69 | $account_exist = null; |
||
70 | } |
||
71 | |||
72 | if (!$account_exist) { |
||
73 | if ($guid === null) { |
||
74 | $temp_password = $this->get("security.password_encoder")->encodePassword($data, $form->get("password")->getData()); |
||
75 | $data->setPassword($temp_password); |
||
76 | } else if ($form->get("password")->getData()) { |
||
77 | $temp_password = $this->get("security.password_encoder")->encodePassword($data, $form->get("password")->getData()); |
||
78 | $data->setPassword($temp_password); |
||
79 | } else { |
||
80 | $data->setPassword($old_password); |
||
81 | } |
||
82 | |||
83 | $em->persist($data); |
||
84 | $em->flush(); |
||
85 | |||
86 | $username = $data->getUser()->getFirstName() . " " . $data->getUser()->getLastName(); |
||
87 | |||
88 | if ($guid === null) { |
||
89 | $this->addFlash("success-flash", "the account of " . $username . " was created"); |
||
90 | } else { |
||
91 | $this->addFlash("success-flash", "the account of " . $username . " was edited"); |
||
92 | } |
||
93 | |||
94 | return $this->redirectToRoute("ribsadmin_accounts"); |
||
95 | } else { |
||
96 | $this->addFlash("error-flash", "An account with username " . $data->getUsername() . " already exist"); |
||
97 | return $this->redirectToRoute($request->get("_route"), ["guid" => $guid]); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | return $this->render("@RibsAdmin/accounts/edit.html.twig", [ |
||
102 | "form" => $form->createView(), |
||
103 | "form_errors" => $form->getErrors(), |
||
104 | "user" => $user, |
||
105 | "disabled_form" => $disabled_form |
||
106 | ]); |
||
141 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.