Conditions | 10 |
Paths | 8 |
Total Lines | 55 |
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 partial(HTTPRequest $request) |
||
41 | { |
||
42 | // Ensure this URL doesn't get picked up by HTTP caches |
||
43 | HTTPCacheControlMiddleware::singleton()->disableCache(); |
||
44 | |||
45 | $key = $request->param('Key'); |
||
46 | $token = $request->param('Token'); |
||
47 | |||
48 | $partial = PartialFormSubmission::get()->find('Token', $token); |
||
49 | if (!$token || !$partial || !$partial->UserDefinedFormID) { |
||
50 | return $this->httpError(404); |
||
51 | } |
||
52 | |||
53 | // TODO: Recognize visitor with the password |
||
54 | if ($partial->generateKey($token) === $key) { |
||
55 | // Set the session if the last session has expired |
||
56 | if (!$request->getSession()->get(PartialSubmissionController::SESSION_KEY)) { |
||
57 | $request->getSession()->set(PartialSubmissionController::SESSION_KEY, $partial->ID); |
||
58 | } |
||
59 | |||
60 | // Set data record and load the form |
||
61 | $this->dataRecord = DataObject::get_by_id($partial->UserDefinedFormClass, $partial->UserDefinedFormID); |
||
62 | $this->setFailover($this->dataRecord); |
||
63 | |||
64 | $form = $this->Form(); |
||
65 | $form->loadDataFrom($partial->getFieldList()); |
||
66 | |||
67 | // Copied from {@link UserDefinedFormController} |
||
68 | if ($this->Content && $form && !$this->config()->disable_form_content_shortcode) { |
||
69 | $hasLocation = stristr($this->Content, '$UserDefinedForm'); |
||
70 | if ($hasLocation) { |
||
71 | /** @see Requirements_Backend::escapeReplacement */ |
||
72 | $formEscapedForRegex = addcslashes($form->forTemplate(), '\\$'); |
||
73 | $content = preg_replace( |
||
74 | '/(<p[^>]*>)?\\$UserDefinedForm(<\\/p>)?/i', |
||
75 | $formEscapedForRegex, |
||
76 | $this->Content |
||
77 | ); |
||
78 | return $this->customise([ |
||
79 | 'Content' => DBField::create_field('HTMLText', $content), |
||
80 | 'Form' => '', |
||
81 | 'PartialLink' => $partial->getPartialLink() |
||
82 | ])->renderWith(['Firesphere\PartialUserforms\PartialUserForm', 'Page']); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | return $this->customise([ |
||
87 | 'Content' => DBField::create_field('HTMLText', $this->Content), |
||
88 | 'Form' => $form, |
||
89 | 'PartialLink' => $partial->getPartialLink() |
||
90 | ])->renderWith(['Firesphere\PartialUserforms\PartialUserForm', 'Page']); |
||
91 | } else { |
||
92 | return $this->httpError(404); |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 |