| Conditions | 10 |
| Paths | 50 |
| Total Lines | 36 |
| Code Lines | 24 |
| Lines | 13 |
| Ratio | 36.11 % |
| 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 |
||
| 49 | public function doSave($data, $form) |
||
| 50 | { |
||
| 51 | View Code Duplication | if (isset($data['Password']) && is_array($data['Password'])) { |
|
| 52 | $data['Password'] = $data['Password']['_Password']; |
||
| 53 | } |
||
| 54 | |||
| 55 | // We need to ensure that the unique field is never overwritten |
||
| 56 | $uniqueField = Member::get_unique_identifier_field(); |
||
| 57 | View Code Duplication | if (isset($data[$uniqueField])) { |
|
| 58 | $SQL_unique = Convert::raw2sql($data[$uniqueField]); |
||
| 59 | $existingUniqueMember = Member::get()->filter(array($uniqueField => $SQL_unique))->first(); |
||
| 60 | if ($existingUniqueMember && $existingUniqueMember->exists()) { |
||
| 61 | if (Member::currentUserID() != $existingUniqueMember->ID) { |
||
| 62 | die("current member does not match enrolled member."); |
||
| 63 | return false; |
||
| 64 | } |
||
| 65 | } |
||
| 66 | } |
||
| 67 | $member = Member::currentUser(); |
||
| 68 | if (!$member) { |
||
| 69 | $member = new Member(); |
||
| 70 | } |
||
| 71 | |||
| 72 | $member->update($data); |
||
| 73 | $member->write(); |
||
| 74 | $arrayExtraFields = array(); |
||
| 75 | if (isset($data["SelectedOption"])) { |
||
| 76 | $arrayExtraFields["SelectedOption"] = $data["SelectedOption"]; |
||
| 77 | } |
||
| 78 | if (isset($data["BookingCode"])) { |
||
| 79 | $arrayExtraFields["BookingCode"] = $data["BookingCode"]; |
||
| 80 | } |
||
| 81 | $this->controller->addAttendee($member, $arrayExtraFields); |
||
| 82 | $this->redirect($this->getController()->Link("thankyou")); |
||
| 83 | return; |
||
| 84 | } |
||
| 85 | |||
| 117 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.