Conditions | 7 |
Paths | 5 |
Total Lines | 62 |
Code Lines | 41 |
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 |
||
141 | public function adminEditEnrollerAction(Request $request, $id): Response |
||
142 | { |
||
143 | $configuration = $this->requestConfigurationFactory->create($this->metadata, $request); |
||
144 | $this->isGrantedOr403($configuration, ResourceActions::SHOW); |
||
145 | $resource = $this->findOr404($configuration); |
||
146 | |||
147 | $translator = $this->get('translator'); |
||
148 | $session = $this->get('session'); |
||
149 | $enabled = $this->getParameter('app_edit_enroller_enabled'); |
||
150 | if (!$enabled) { |
||
151 | $session->getFlashBag()->add( |
||
152 | 'error', |
||
153 | $translator->trans('app.messages.error.editEnrollerDisabled') |
||
154 | ); |
||
155 | return $this->redirectToRoute('sylius_admin_customer_show', ['id' => $id]); |
||
156 | } |
||
157 | |||
158 | if ($request->query->has('_enroller') && $request->query->has('_action')) { |
||
159 | $enrollerId = $request->query->get('_enroller'); |
||
160 | if ($enrollerId !== $id && $request->query->get('_action') === 'selectEnroller') { |
||
161 | /** @var CustomerManager $customerManager */ |
||
162 | $customerManager = $this->get('app.customer.manager'); |
||
163 | $customerManager->changeCustomerEnroller($id, $enrollerId); |
||
164 | /** @var CustomerRepository $customerRepository */ |
||
165 | $customerRepository = $this->get('sylius.repository.customer'); |
||
166 | $enroller = $customerRepository->getCustomerById($enrollerId); |
||
167 | $enrollerChangeEvent = new EnrollerChangeEvent($resource, $enroller); |
||
168 | /** @var EventDispatcher $eventDispatcher */ |
||
169 | $eventDispatcher = $this->get('event_dispatcher'); |
||
170 | $eventDispatcher->dispatch($enrollerChangeEvent, EnrollerChangeEvent::NAME); |
||
171 | $session->getFlashBag()->add( |
||
172 | 'success', |
||
173 | $translator->trans('app.messages.success.changedEnroller') |
||
174 | ); |
||
175 | return $this->redirectToRoute('sylius_admin_customer_show', ['id' => $id]); |
||
176 | } |
||
177 | else { |
||
178 | throw new InvalidArgumentException("Invalid request. Can't choose customer as his own enroller"); |
||
179 | } |
||
180 | } |
||
181 | |||
182 | $resources = $this->resourcesCollectionProvider->get($configuration, $this->repository); |
||
183 | |||
184 | $this->eventDispatcher->dispatch(ResourceActions::SHOW, $configuration, $resource); |
||
185 | |||
186 | $view = View::create($resource); |
||
187 | |||
188 | if ($configuration->isHtmlRequest()) { |
||
189 | $view |
||
190 | ->setTemplate($configuration->getTemplate(ResourceActions::SHOW . '.html')) |
||
191 | ->setTemplateVar($this->metadata->getName()) |
||
192 | ->setData([ |
||
193 | 'configuration' => $configuration, |
||
194 | 'metadata' => $this->metadata, |
||
195 | 'resource' => $resource, |
||
196 | 'resources' => $resources, |
||
197 | $this->metadata->getName() => $resource, |
||
198 | ]) |
||
199 | ; |
||
200 | } |
||
201 | |||
202 | return $this->viewHandler->handle($configuration, $view); |
||
203 | } |
||
205 | } |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.