Conditions | 13 |
Paths | 21 |
Total Lines | 79 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
21 | public function createAction(Request $request): Response |
||
22 | { |
||
23 | $configuration = $this->requestConfigurationFactory->create($this->metadata, $request); |
||
24 | |||
25 | $this->isGrantedOr403($configuration, ResourceActions::CREATE); |
||
26 | |||
27 | $newResource = $this->newResourceFactory->create($configuration, $this->factory); |
||
28 | |||
29 | $form = $this->resourceFormFactory->create($configuration, $newResource); |
||
30 | |||
31 | $refManager = $this->get('app.referral.manager'); |
||
32 | |||
33 | $refManager->checkReferralValidity(); |
||
34 | |||
35 | if ($request->isMethod('POST') && $form->handleRequest($request)->isValid()) { |
||
36 | $newResource = $form->getData(); |
||
37 | |||
38 | $referrer = $refManager->getReferrerFromSession(); |
||
39 | if ($referrer) { |
||
40 | $newResource->setEnroller($referrer); |
||
41 | } |
||
42 | |||
43 | $refManager->removeReferral(); |
||
44 | |||
45 | $event = $this->eventDispatcher->dispatchPreEvent(ResourceActions::CREATE, $configuration, $newResource); |
||
46 | |||
47 | if ($event->isStopped() && !$configuration->isHtmlRequest()) { |
||
48 | throw new HttpException($event->getErrorCode(), $event->getMessage()); |
||
49 | } |
||
50 | if ($event->isStopped()) { |
||
51 | $this->flashHelper->addFlashFromEvent($configuration, $event); |
||
52 | |||
53 | if ($event->hasResponse()) { |
||
54 | return $event->getResponse(); |
||
55 | } |
||
56 | |||
57 | return $this->redirectHandler->redirectToIndex($configuration, $newResource); |
||
58 | } |
||
59 | |||
60 | if ($configuration->hasStateMachine()) { |
||
61 | $this->stateMachine->apply($configuration, $newResource); |
||
62 | } |
||
63 | |||
64 | $this->repository->add($newResource); |
||
65 | $postEvent = $this->eventDispatcher->dispatchPostEvent(ResourceActions::CREATE, $configuration, $newResource); |
||
66 | |||
67 | if (!$configuration->isHtmlRequest()) { |
||
68 | return $this->viewHandler->handle($configuration, View::create($newResource, Response::HTTP_CREATED)); |
||
69 | } |
||
70 | |||
71 | $this->flashHelper->addSuccessFlash($configuration, ResourceActions::CREATE, $newResource); |
||
72 | |||
73 | if ($postEvent->hasResponse()) { |
||
74 | return $postEvent->getResponse(); |
||
75 | } |
||
76 | |||
77 | return $this->redirectHandler->redirectToResource($configuration, $newResource); |
||
78 | } |
||
79 | |||
80 | if (!$configuration->isHtmlRequest()) { |
||
81 | return $this->viewHandler->handle($configuration, View::create($form, Response::HTTP_BAD_REQUEST)); |
||
82 | } |
||
83 | |||
84 | $initializeEvent = $this->eventDispatcher->dispatchInitializeEvent(ResourceActions::CREATE, $configuration, $newResource); |
||
85 | if ($initializeEvent->hasResponse()) { |
||
86 | return $initializeEvent->getResponse(); |
||
87 | } |
||
88 | |||
89 | $view = View::create() |
||
90 | ->setData([ |
||
91 | 'configuration' => $configuration, |
||
92 | 'metadata' => $this->metadata, |
||
93 | 'resource' => $newResource, |
||
94 | $this->metadata->getName() => $newResource, |
||
95 | 'form' => $form->createView(), |
||
96 | ]) |
||
97 | ->setTemplate($configuration->getTemplate(ResourceActions::CREATE . '.html')); |
||
98 | |||
99 | return $this->viewHandler->handle($configuration, $view); |
||
100 | } |
||
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.