| Conditions | 7 |
| Paths | 17 |
| Total Lines | 63 |
| Code Lines | 34 |
| 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 |
||
| 40 | public function actionIndex() |
||
| 41 | { |
||
| 42 | $this->requirePostRequest(); |
||
| 43 | |||
| 44 | $request = Craft::$app->getRequest(); |
||
| 45 | |||
| 46 | if ($jobId = $request->getParam('jobId')) |
||
| 47 | { |
||
| 48 | $resumeIncluded = ! empty($_FILES['resume']['tmp_name']) |
||
| 49 | && ! empty($_FILES['resume']['name']); |
||
| 50 | |||
| 51 | $application = new LeverJobApplication([ |
||
| 52 | 'name' => $request->getParam('name'), |
||
| 53 | 'email' => $request->getParam('email'), |
||
| 54 | 'phone' => $request->getParam('phone'), |
||
| 55 | 'org' => $request->getParam('org'), |
||
| 56 | 'urls' => $request->getParam('urls'), |
||
| 57 | 'comments' => $request->getParam('comments'), |
||
| 58 | 'ip' => $request->getUserIP(), |
||
| 59 | 'silent' => Lever::$plugin->getSettings()->applySilently, |
||
| 60 | 'source' => Lever::$plugin->getSettings()->applicationSource, |
||
| 61 | ]); |
||
| 62 | |||
| 63 | if ($resumeIncluded) |
||
| 64 | { |
||
| 65 | $application->resume = UploadedFile::getInstanceByName('resume'); |
||
| 66 | } |
||
| 67 | |||
| 68 | if (Lever::$plugin->api->applyForJob($jobId, $application)) |
||
| 69 | { |
||
| 70 | if ($request->getAcceptsJson()) |
||
| 71 | { |
||
| 72 | return $this->asJson(['success' => true]); |
||
| 73 | } |
||
| 74 | |||
| 75 | Craft::$app->getSession()->setNotice('Application submitted.'); |
||
| 76 | |||
| 77 | return $this->redirectToPostedUrl(); |
||
| 78 | } |
||
| 79 | |||
| 80 | if ($request->getAcceptsJson()) |
||
| 81 | { |
||
| 82 | return $this->asJson(['errors' => $application->getErrors()]); |
||
| 83 | } |
||
| 84 | |||
| 85 | Craft::$app->getSession()->setError(Craft::t( |
||
| 86 | 'lever', |
||
| 87 | 'There was a problem with the application. Please check the form and try again!' |
||
| 88 | )); |
||
| 89 | |||
| 90 | Craft::$app->getUrlManager()->setRouteParams([ |
||
| 91 | 'variables' => ['application' => $application] |
||
| 92 | ]); |
||
| 93 | |||
| 94 | return null; |
||
| 95 | } |
||
| 96 | |||
| 97 | Craft::$app->getSession()->setError(Craft::t( |
||
| 98 | 'lever', |
||
| 99 | 'Job ID missing.' |
||
| 100 | )); |
||
| 101 | |||
| 102 | return null; |
||
| 103 | } |
||
| 125 |