Conditions | 2 |
Paths | 2 |
Total Lines | 60 |
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 |
||
39 | public function __construct($controller, $name = "Users_EditAccountForm") |
||
40 | { |
||
41 | $member = Member::singleton(); |
||
42 | $hidden_fields = array_merge( |
||
43 | $member->config()->hidden_fields, |
||
44 | static::config()->ignore_member_fields |
||
45 | ); |
||
46 | |||
47 | $fields = $member->getFrontEndFields(); |
||
48 | |||
49 | // Remove all "hidden fields" |
||
50 | foreach ($hidden_fields as $field_name) { |
||
51 | $fields->removeByName($field_name); |
||
52 | } |
||
53 | |||
54 | // Add the current member ID |
||
55 | $fields->add(HiddenField::create("ID")); |
||
56 | |||
57 | // Switch locale field |
||
58 | $fields->replaceField( |
||
59 | 'Locale', |
||
60 | DropdownField::create( |
||
61 | "Locale", |
||
62 | $member->fieldLabel("Locale"), |
||
63 | i18n::get_existing_translations() |
||
64 | ) |
||
65 | ); |
||
66 | |||
67 | $this->extend("updateFormFields", $fields); |
||
68 | |||
69 | $cancel_url = Controller::join_links($controller->Link()); |
||
70 | |||
71 | $actions = new FieldList( |
||
72 | LiteralField::create( |
||
73 | "cancelLink", |
||
74 | '<a class="btn btn-red" href="'.$cancel_url.'">'. _t("Users.CANCEL", "Cancel") .'</a>' |
||
75 | ), |
||
76 | FormAction::create("doUpdate", _t("CMSMain.SAVE", "Save")) |
||
77 | ->addExtraClass("btn") |
||
78 | ->addExtraClass("btn-green") |
||
79 | ); |
||
80 | |||
81 | $this->extend("updateFormActions", $actions); |
||
82 | |||
83 | $required = new RequiredFields( |
||
84 | $member->config()->required_fields |
||
85 | ); |
||
86 | |||
87 | $this->extend("updateRequiredFields", $required); |
||
88 | |||
89 | parent::__construct( |
||
90 | $controller, |
||
91 | $name, |
||
92 | $fields, |
||
93 | $actions, |
||
94 | $required |
||
95 | ); |
||
96 | |||
97 | $this->extend("updateForm", $this); |
||
98 | } |
||
99 | |||
143 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.